jschuengel: thuban/Extensions/umn_mapserver mapfile.py,1.5,1.6

cvs@intevation.de cvs at intevation.de
Thu Jul 8 16:26:58 CEST 2004


Author: jschuengel

Update of /thubanrepository/thuban/Extensions/umn_mapserver
In directory doto:/tmp/cvs-serv25025

Modified Files:
	mapfile.py 
Log Message:
Added code to generade and get a list of supported outputformats. This formats are not alle supported because there is no possibility to get the outputformat without the name known. Make some formal changes to the code.
(MF_Map.set_name()): Fixed a bug if the name is None.


Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mapfile.py	7 Jul 2004 12:51:42 -0000	1.5
+++ mapfile.py	8 Jul 2004 14:26:56 -0000	1.6
@@ -13,10 +13,15 @@
 mapscript are not implemented yet in this extension:
 
  DBFInfo, errorObj, fontSetObj, graticuleObj, imageObj, itemObj,
- labelCacheMemberObj, labelCacheObj, lineObj,
- markerCacheMembet, msTiledSHPLayerInfo, OutputFormat, pointObj, queryMapObj,
- referenzMapObj, resultCacheMemberObj, resultCacheObj, scalebarObj,
- shapefileObj, shapeObj, VectorObj, WebObj
+ labelCacheMemberObj, labelCacheObj,
+ markerCacheMembet, msTiledSHPLayerInfo, queryMapObj,
+ referenzMapObj, resultCacheMemberObj, resultCacheObj,
+ shapefileObj, shapeObj, VectorObj
+
+the following are only used to create a necessary object. They are not
+realy created as a MF_Object.
+
+ lineObj, pointObj
 """
 
 __version__ = "$Revision$"
@@ -36,12 +41,14 @@
 
 from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, symbolObj, \
                       pointObj, lineObj
-                      
 
 # ###################################
 #
 # Definition of dictionaries
 #
+# the dictonaries are like in mapscript and are used to make it
+# easear to unterstand the key from mapscript for the settings
+#
 # ###################################
 
 shp_type = { 0:'point',
@@ -53,41 +60,35 @@
              6:'query'}
 
 unit_type = { 0:"inches",
-             1:"feet",
-             2:"miles",
-             3:"meters",
-             4:"kilometers",
-             5:"dd"}
-
-# TODO: generate the list dynamical by alle supported formats.
-#       At the moment outputformat only get by name.
-image_type = ["png","jpeg","wbmp","GTiff"]
+              1:"feet",
+              2:"miles",
+              3:"meters",
+              4:"kilometers",
+              5:"dd"}
 
 legend_status_type = { 0:"OFF",
-                        1:"ON",
-                        3:"embed" } 
-                        # 2 = Default but will not be imported because 
-                        # mapscript dont support it and its not allowed
-
+                       1:"ON",
+                       3:"embed" } 
+                       # 2 = Default but is not allowed here
+		       
 scalebar_status_type = { 0:"OFF",
-                        1:"ON",
-                        3:"embed" } 
-                        # 2 = Default but will not be imported because 
-                        # mapscript dont support it and its not allowed
-
+                         1:"ON",
+                         3:"embed" } 
+                         # 2 = Default but is not allowed here
+			 
 scalebar_style_type = { 0:"0",
                         1:"1" }
 
 scalebar_position_type = { 0:"ul",
-                         1:"lr",
-                         2:"ur",
-                         3:"ll",
-                         6:"uc",
-                         7:"lc"}
+                           1:"lr",
+                           2:"ur",
+                           3:"ll",
+                           6:"uc",
+                           7:"lc"}
 
 layer_status_type = { 0:"OFF",
-                        1:"ON",
-                        2:"default"}
+                      1:"ON",
+                      2:"default"}
 
 legend_position_type = { 0:"ul",
                          1:"lr",
@@ -106,15 +107,15 @@
 label_font_type = { 1:"bitmap" }
 
 label_position_type = { 0:"ul",
-                         1:"lr",
-                         2:"ur",
-                         3:"ll",
-                         4:"cr",
-                         5:"cl",
-                         6:"uc",
-                         7:"lc",
-                         8:"cc",
-                         10:"auto"}
+                        1:"lr",
+                        2:"ur",
+                        3:"ll",
+                        4:"cr",
+                        5:"cl",
+                        6:"uc",
+                        7:"lc",
+                        8:"cc",
+                       10:"auto"}
 
 
 # ##################################################
@@ -174,11 +175,12 @@
     """    
     def __init__(self, mf_color):
         self._color = mf_color
-
         self._tbc_red = (float(self.get_red())/255)
         self._tbc_green = (float(self.get_green())/255)
         self._tbc_blue = (float(self.get_blue())/255)
-        self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
+        self._thubancolor = Color(self._tbc_red,
+				  self._tbc_green,
+				  self._tbc_blue)
 
     # TODO : Check if it is necessary to use rgb colors alone
     # or whether it is sufficient to only use the Thuban Color.
@@ -201,7 +203,9 @@
         self._tbc_red = (float(self.get_red())/255)
         self._tbc_green = (float(self.get_green())/255)
         self._tbc_blue = (float(self.get_blue())/255)
-        self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
+        self._thubancolor = Color(self._tbc_red,
+				  self._tbc_green, 
+				  self._tbc_blue)
         
     def get_mfcolor(self):
         return self._color
@@ -241,7 +245,6 @@
                 
     Metadata are not really needed at the moment.
     """
-
     def __init__(self):
         self.data = {}
        
@@ -254,11 +257,23 @@
     def add_metadata(self, key, data):
         self.data[key] = data
 
-# ##################################################
+# ################################################
 # Classes for MapServer Objects as they are
 # explicitly defined in a mapfile
-class MF_Outputformat:
 
+class MF_Outputformat:
+    """
+    The Outputformat defines which and how the image is
+    created by the mapserver.
+    
+    The following settings are used:
+    name
+    
+    The following settings are not used:
+    mimetye, driver, extension, renderer, imagemode, transparent,
+    bands, numfrotmatoptions, formatoptions, refcount, inmapfile
+    setExtension(), setMimetype(), setOption(), getOption()
+    """
     def __init__(self, mf_outputformat):
         self._outputformat = mf_outputformat
     
@@ -266,20 +281,25 @@
         return self._outputformat.name
     
 
-
 class MF_Symbol:
     """
     defines a single symbol which is used in the Symbolset
     
-    name, type, sizex, sizey, points, numpoints, filled, stylelength,
+    the following settings are used:
+    name, type,
+    
+    the following settings are not used:
+    sizex, sizey, points, numpoints, filled, stylelength,
     style, imagepath, transparent, transparentcolor, character, antialias,
     font, gap, position, linecap, linejoin, linejoinmaxsize, setPoints(),
     getPoints(), setStyle()
-    """
-    
+    """    
     def __init__(self, mf_symbol = "newone"):
         # create a circle Object like shown in Thuban
         # because Thuban don't support other symbols
+	
+	# TODO: include the options to create a symbol, but
+	#      first implement a methode to edit Symbols in Thuban
         if mf_symbol == "newone":
             mf_symbol = symbolObj("")            
             newpoint = pointObj()
@@ -300,30 +320,35 @@
     def set_name(self, new_name):
         self._symbol.name = new_name
     
+    def get_type(self):
+        return self._symbol.type
+    
     def set_type(self, new_type):
         # TODO include a function to set the type by a string
         self._symbol.type = new_type
     
+    def get_filled(self):
+        return self._symbol.filled
+    
     def set_filled(self, new_filled):
         if new_filled:
             self._symbol.filled = 1
         else:
             self._symbol.filled = 0
-    
-    
+
 
 class MF_SymbolSet:
     """
     defines a set of symbols, may be there can only be one
     
-    filename, imagecachesize, numsymbols, symbol, getSymbol(),
-    getSymbolByName(), index(), appendSymbol(), removeSymbol(),
+    the following settings are used:
+    numsymbols,
+    appendSymbol()
+    
+    filename, imagecachesize, symbol, getSymbol(),
+    getSymbolByName(), index(), removeSymbol(),
     save()    
     """
-    
-    # TODO: include the symbolset, but found only the possibility to
-    # create an extra symbol file and not to include it direct to the 
-    # mapfile itself
     def __init__(self, mf_symbolset):
         self._symbolset = mf_symbolset
         
@@ -335,15 +360,12 @@
             self._symbols.append(MF_Symbol(self._symbolset.getSymbol(self._i)))
             self._i += 1
 
-#    POINT
-#   1 1
-#   END
-
     def add_symbol(self, new_symbol):
         self._symbolset.appendSymbol(new_symbol.get_symbolObj())
         self._symbols.append(new_symbol)
         # the save function must be run to set the symbols to the
         # mapfile. I don't know why this ist so but it must be.
+	# the file is empty then an we can delete it
         self._symbolset.save("tempsymbol")
         os.remove("tempsymbol")
 
@@ -353,17 +375,17 @@
         else:
             return None
 
+
 class MF_Class:
     """
     The following parameters and functions, which the mapscript style obj
     contains, are used:
-    styles, numstyles, name,
+    styles, numstyles, name, status, keyimage, layer,
     getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(),
     getNextMetaDataKey(), getStyle()
 
     The following parameters and functions are not used:
-    status, label, title, template, type, minscale, maxscale, layer, 
-    debig, keyimage,
+    label, title, template, type, minscale, maxscale, debug,
     setExpression(), setText(), setMetaData(), drawLegendIcon(),
     createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),
     moveStyleDown()
@@ -609,11 +631,17 @@
         new_class.set_status(tb_class.IsVisible())
         self._classes.append(new_class)
 
+
 class MF_Scalebar:
     """
+    Represent the scalebar for a map
+
+    The following settings are used:
+    label, color, imagecolor, style, intervals, units,
+    status, position, height, width 
+    
     The following settings are (not) used:
-    imagecolor, height, width, style, intervals, label, color, backgroundcolor,
-    outlinecolor, units, status, position, postlabelcache
+    backgroundcolor,outlinecolor, postlabelcache
     """
     def __init__(self, mf_scalebar):
         self._scalebar = mf_scalebar
@@ -662,8 +690,8 @@
                if unit_type[unit_paar_nr] == units:
                    self._scalebar.units = unit_paar_nr
         
-    def get_status(self, art="integer"):
-        if art == "string":
+    def get_status(self, mode="integer"):
+        if mode == "string":
             return scalebar_status_type[self._scalebar.status]
         else:
             return self._scalebar.status
@@ -676,8 +704,8 @@
                 if scalebar_status_type[scalebar_status_type_nr] == new_status:
                     self._scalebar.status = scalebar_status_type_nr
     
-    def get_position(self, art="integer"):
-        if art == "string":
+    def get_position(self, mode="integer"):
+        if mode == "string":
             return scalebar_position_type[self._scalebar.position]
         else:
             return self._scalebar.position
@@ -687,9 +715,11 @@
             self._scalebar.position = new_position
         else:
             for scalebar_position_type_nr in legend_position_type:
-                if scalebar_position_type[scalebar_position_type_nr] == new_position:
+                if scalebar_position_type[scalebar_position_type_nr] \
+                == new_position:
                     self._scalebar.position = scalebar_position_type_nr
 
+
 class MF_Map:
     """
     The following parameters and functions, which the mapscript style obj
@@ -697,42 +727,56 @@
 
     name, numlayers, extent, shapepath, imagecolor, imagetype, units, getLayer,
     status, getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
-    save(), setExtent(), height, width, setProjection()
+    save(), setExtent(), height, width, setProjection(), setImageType(),
 
-    
     The following parameters and functions are not used:
     maxsize, layers, symbolset, fontset, labelcache,
     transparent, interlace, imagequality, cellsize, debug, datapattern,
     templatepattern, configoptions
     zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
     clone(), removeLayer(), getLayerByName(), getSymbolByName(),
-    prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),
+    prepareQuery(), prepareImage(), setOutputFormat(), draw(),
     drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),
-    nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),
-    setWKTProjection(), saveQuery(), saveQueryASGML(),
-    setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),
-    saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),
-    getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),
-    getConfigOption(), applyConfigOptions(), applySLD(), applySLDURL(), gernerateSLD(),
-    procecssTemplate(), processLegemdTemplate(), processQueryTemplate(),
+    nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(),
+    queryByShape(), setWKTProjection(), saveQuery(), saveQueryASGML(),
+    setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(),
+    setFontSet(), saveMapContext(), loadMapContext(), moveLayerUp(),
+    moveLayerDown(), getLayersDrawingOrder(), setLayersDrawingOrder(),
+    setConfigOption(), getConfigOption(), applyConfigOptions(), applySLD(),
+    applySLDURL(), gernerateSLD(), procecssTemplate(), processLegemdTemplate(), processQueryTemplate(),
     getOutputFormatByName(), appendOutputFormat(), removeOutputFormat(),
     """
-    
     def __init__(self, mf_map):
         """
 	Create the map object from the mapfile mapobject which is given.
 
 	All layers in the mapfile will be written to an array.
 	"""
-
         self._mf_map = mf_map
         self._extent = MF_Rectangle(self._mf_map.extent)
         self._imagecolor = MF_Color(self._mf_map.imagecolor)
         self._web = MF_Web(self._mf_map.web)
         self._legend = MF_Legend(self._mf_map.legend)
         self._scalebar = MF_Scalebar(self._mf_map.scalebar)
-        self._outputformat = MF_Outputformat(self._mf_map.outputformat)
         
+        # TODO: generate the list dynamical by alle supported formats.
+        # At the moment outputformat only get by name, but in a next
+        # version there may be a function to get the outputformat by id
+        # then there is no need to define the formattypes here
+        image_types = ['gif', 'png', 'png24', 'jpeg', 'wbmp', \
+	               'swf', 'pdf', 'imagemap'] 
+        self._alloutputformats = []
+        self._imagetype = self._mf_map.imagetype
+        # create a temp imagtype, because the function getOutputFormatByName()
+        # set the imagetype to the received OutputFormat        
+        for fmtname in image_types:
+            theformat = self._mf_map.getOutputFormatByName(fmtname)
+            if theformat:
+                self._alloutputformats.append(MF_Outputformat(theformat)) 
+        self._mf_map.setImageType(self._imagetype)
+
+        self._outputformat = MF_Outputformat(self._mf_map.outputformat)
+
         # symbols
         self._symbolset = MF_SymbolSet(self._mf_map.symbolset)
 
@@ -773,6 +817,9 @@
     def get_outputformat(self):
         return self._outputformat
     
+    def get_alloutputformats(self):
+        return self._alloutputformats
+
     def get_imagetype(self):
         return self._mf_map.imagetype
     
@@ -816,7 +863,8 @@
         return self._name
     
     def get_shapepath(self):
-        return self._shapepath # where are the shape files located..
+        # where are the shape files located..
+        return self._shapepath 
     
     def get_imagetype(self):
         return self._mf_map.imagetype
@@ -839,7 +887,8 @@
     def set_name(self, newname):
         # whitespace musst be replaced, either no
         # mapfile will be shown in the mapserver
-        newname = newname.replace(" ","_")
+        if newname:
+            newname = newname.replace(" ","_")
         self._name = newname
         self._mf_map.name = newname
     
@@ -847,8 +896,10 @@
         # TODO: add the shown extend here instead of the total
         self._newrect = MF_Rectangle(rectObj())
         try:
-            self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
-            self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
+            self._newrect.set_rect(newextent[0],newextent[1], \
+	                           newextent[2],newextent[3])
+            self._mf_map.setExtent(newextent[0],newextent[1], \
+	                           newextent[2],newextent[3])
         except:
             return
     
@@ -871,7 +922,10 @@
             for unit_paar_nr in unit_type:
                if unit_type[unit_paar_nr] == units:
                    self._mf_map.units = unit_paar_nr
-      
+    
+    def get_metadata(self):
+        return self._metadata
+    
     def add_thubanlayer(self, tb_layer):
         """
         Add a thuban layer
@@ -896,14 +950,20 @@
             if tb_layer.GetProjection():
                 new_layer.set_projection(tb_layer.GetProjection())
             if tb_layer.GetClassification().GetNumGroups() > 0:
-                for group in range(0, tb_layer.GetClassification().GetNumGroups(), 1):
-                    new_layer.add_thubanclass(tb_layer.GetClassification().GetGroup(group))
-                new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
+                for group in range(0, \
+		                tb_layer.GetClassification().GetNumGroups(), 1):
+                    new_layer.add_thubanclass( \
+		                   tb_layer.GetClassification().GetGroup(group))
+                new_layer.add_thubanclass( \
+		                 tb_layer.GetClassification().GetDefaultGroup())
             else:
-                new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup(), type="default")
+                new_layer.add_thubanclass( \
+		               tb_layer.GetClassification().GetDefaultGroup(), \
+		               type="default")
        
         # set the projection to the layer.
-        # if the layer has its own definition use is, else use the main projection
+        # if the layer has its own definition use is, 
+	# else use the main projection
         if tb_layer.GetProjection():
             new_layer.set_projection(tb_layer.GetProjection())
         else:
@@ -926,10 +986,10 @@
     Save the Web settings
     
     The following parametes are used:
-    imagepath, imageurl
+    imagepath, imageurl, queryformat,
     
     The following parameters are not used:
-    log, map, template, queryformat, header, footer, empty, error, extent,
+    log, map, template, header, footer, empty, error, extent,
     minscale, maxscale, mintemplate, maxtemplate
     """
     def __init__(self, mf_web):
@@ -945,7 +1005,7 @@
         return self._mf_web.imageurl
 
     def set_imageurl(self, new_imageurl):
-        self._mf_web.imagepath = new_imageurl
+        self._mf_web.imageurl = new_imageurl
     
     def get_queryformat(self):
         return self._mf_web.queryformat
@@ -957,14 +1017,14 @@
 class MF_Label:
     """
     The following parameters from mapscript are used:
-    type, color, size, offsetx, offsety,
+    type, color, size, offsetx, offsety, partials, force, buffer,
+    minfeaturesize, mindistance,
     
     The following parameters are not used:    
-    font,   outlinecolor, shadowcolor, shadowsizex, shadowsizey, 
+    font, outlinecolor, shadowcolor, shadowsizex, shadowsizey, 
     backgroundcolor, backgroundshadowcolor, backgroundshadowsizex,
     backgroundshadowsizey, sizescaled, minsize, maxsize, position, angle,
-    autoangle, buffer, antialias, wrap, minfeaturesize,
-    autominfeaturesize, mindistance, partials, force
+    autoangle, antialias, wrap, autominfeaturesize,
     """
     def __init__(self, mf_label):
         """
@@ -1001,7 +1061,7 @@
         elif new_partials == False:
             self._label.partials = 0
         else:
-            print "Boolean exspected"
+            print "must be boolean"
     
     def get_buffer(self):
         return self._label.buffer
@@ -1021,8 +1081,8 @@
     def set_minfeaturesize(self, new_minfeaturesize):
         self._label.minfeaturesize = new_minfeaturesize
     
-    def get_position(self, art="integer"):
-        if art == "string":
+    def get_position(self, mode="integer"):
+        if mode == "string":
             return label_position_type[self._label.position]
         else:
             return self._label.position
@@ -1103,8 +1163,8 @@
         self._mf_legend.keyspacingx = new_keyspacingx
         self._mf_legend.keyspacingy = new_keyspacingy
     
-    def get_status(self, art="integer"):
-        if art == "string":
+    def get_status(self, mode="integer"):
+        if mode == "string":
             return legend_status_type[self._mf_legend.status]
         else:
             return self._mf_legend.status
@@ -1117,8 +1177,8 @@
                 if legend_status_type[legend_status_type_nr] == new_status:
                     self._mf_legend.status = legend_status_type_nr
     
-    def get_position(self, art="integer"):
-        if art == "string":
+    def get_position(self, mode="integer"):
+        if mode == "string":
             return legend_position_type[self._mf_legend.position]
         else:
             return self._mf_legend.position
@@ -1128,7 +1188,7 @@
             self._mf_legend.position = new_position
         else:
             for legend_position_type_nr in legend_position_type:
-                if legend_position_type[legend_position_type_nr] == new_position:
+                if legend_position_type[legend_position_type_nr]== new_position:
                     self._mf_legend.position = legend_position_type_nr
 
 class MF_Projection:
@@ -1167,7 +1227,7 @@
         epsg -- EPSG code as string
         """
         #Needed only for this function
-        from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE, \
+        from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE,\
                                           EPSG_DEPRECATED_PROJ_FILE
 
         proj_file, warnings = get_system_proj_file(EPSG_PROJ_FILE)





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)