jschuengel: thuban/Extensions/umn_mapserver mapfile.py,1.1,1.2

cvs@intevation.de cvs at intevation.de
Wed Jun 23 14:39:54 CEST 2004


Author: jschuengel

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

Modified Files:
	mapfile.py 
Log Message:
Expand the classes to use with the export module. Especially added the possibility to add thuban objects directly to the map objects.


Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mapfile.py	10 Jun 2004 12:27:48 -0000	1.1
+++ mapfile.py	23 Jun 2004 12:39:52 -0000	1.2
@@ -30,8 +30,12 @@
 #
 # ##################################################
 
+import os
 
-from Thuban.Model.color import Color
+from Thuban.Model.color import Color, Transparent 
+
+from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, \
+                      colorObj
 
 # ###################################
 #
@@ -56,7 +60,7 @@
 # ##################################################
 
 # ##################################################
-# General Classes that are not explicitly defined through
+# General Classes that are not all explicitly defined through
 # a mapfile, but rather some helper-classes.
 
 class MF_Rectangle:
@@ -78,7 +82,15 @@
 
     def get_maxy(self):
         return self._rect.maxy
+    
+    def get_rect(self):
+        return (self._rect.minx,self._rect.miny,self._rect.maxx,self._rect.maxy)
 
+    def set_rect(self, minx, miny, maxx, maxy):
+        self._rect.minx = minx
+        self._rect.miny = miny
+        self._rect.maxx = maxx
+        self._rect.maxy = maxy
 
 class MF_Color:
     """
@@ -95,7 +107,7 @@
     not add any capability.
     
     color is definied as RGB 0..255
-    """
+    """    
     def __init__(self, mf_color):
         self._color = mf_color
 
@@ -116,15 +128,19 @@
 
     def get_blue(self):
         return self._color.blue
+        
+    def get_mfcolor(self):
+        return self._color
 
     def get_thubancolor(self):
-        return self._thubancolor
+        return self._thubancolor     
 
     def set_thubancolor(self, thuban_color):
-        self._color.red = int(thuban_color.red * 255)
-        self._color.green = int(thuban_color.green * 255)
-        self._color.blue = int(thuban_color.blue * 255)
-        self._thubancolor = thuban_color
+        if thuban_color != Transparent:
+            self._color.red = int(thuban_color.red * 255)
+            self._color.green = int(thuban_color.green * 255)
+            self._color.blue = int(thuban_color.blue * 255)
+            self._thubancolor = thuban_color
 
 
 class MF_Size:
@@ -143,6 +159,10 @@
     
     def get_height(self):
         return self._height
+    
+    def set_size(self, newwidth, newheight):
+        self._width = newwidth
+        self._height = newheight
 
 
 class MF_Metadata:
@@ -182,17 +202,45 @@
     def add_metadata(self, key, data):
         self.data[key] = data
 
-
 # ##################################################
 # Classes for MapServer Objects as they are
-# explicitly defined in a mapfile.
+# explicitly defined in a mapfile
+
+class MF_Symbol:
+    """
+    defines a single symbol which is used in the Symbolset
+    
+    name, type, 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):
+        print "nothing"
+
+class MF_SymbolSet:
+    """
+    defines a set of symbols, may be there can only be one
+    
+    filename, imagecachesize, numsymbols, symbol, getSymbol(),
+    getSymbolByName(), index(), appendSymbol(), 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):
+        print "nothing"
+
 
 class MF_Class:
     """
     The following parameters and functions, which the mapscript style obj
     contains, are used:
     styles, numstyles, name,
-    getExpressionString(), getMetaData(), getFirstMetaDataKey(),
+    getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(),
     getNextMetaDataKey(), getStyle()
 
     The following parameters and functions are not used:
@@ -202,7 +250,6 @@
     createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),
     moveStyleDown()
     """
-    
     def __init__(self, mf_class):
         """
         Initialized a class from them given mapscript Class Object
@@ -216,7 +263,6 @@
         for i in range(0,self._numstyles,1):
             self._styles.append(MF_Style(mf_class.getStyle(i)))
         
-        
         if self._clazz.getExpressionString() == '"(null)"':
             self._expression = None
         else:
@@ -244,6 +290,27 @@
         
     def get_expressionstring(self):
         return self._expression
+    
+    def set_name(self, newname):
+        self._clazz.name = newname
+    
+    def set_expressionstring(self, newstring):
+        self._clazz.setExpression(newstring)
+        self._expression = self._clazz.getExpressionString()
+    
+    def add_thubanstyle(self, tb_style, type="default"):
+        new_styleobj = MF_Style(styleObj(self._clazz))
+        if type == "line":
+            new_styleobj.set_color(tb_style.GetLineColor())
+        elif type == "circle":
+            # set a default symbol to show circles not only a small dot
+            # symbol "circle" must create before
+            # TODO: create a Symbol (more see MF_SymbolSet)
+            new_styleobj.set_symbol('circle')
+        else:
+            new_styleobj.set_size(tb_style.GetLineWidth())
+            new_styleobj.set_linecolor(tb_style.GetLineColor())
+            new_styleobj.set_color(tb_style.GetFill())
 
 
 class MF_Layer:
@@ -253,11 +320,11 @@
 
     classitem, numclasses, name, data, type
     getClass(), getProjection(), getExtent(), getMetaData(),
-    getFirstMetaDataKey(), getNextMetaDataKey()
+    getFirstMetaDataKey(), getNextMetaDataKey(), status, 
 
 
     The following paramters and functions are not used:
-    index, map, header, footer, template, groupe, status, tolerance,
+    index, map, header, footer, template, groupe, tolerance,
     toleranceunits, symbolscale, minscale, maxscale, labelminscale
     labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache
     postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex
@@ -331,6 +398,66 @@
 
     def get_projection(self):
         return self._projection
+    
+    def get_status(self):
+        # returns a integer value
+        # 0 = off, 1 = on, 2 = default(always on)
+        if self._mf_layer.status == 0:
+            return False
+        else:
+            return True
+        #return self._mf_layer.status
+    
+    def set_name(self, newname):
+        self._mf_layer.name = newname 
+    
+    def set_data(self, newdata):
+        self._mf_layer.data = newdata[:-4]
+    
+    def set_status(self, newstatus):
+        # status can set to true or false from thuban.
+        # but mapserver supports the default value
+        self._mf_layer.status = newstatus
+    
+    def set_classitem(self, tb_field):
+        self._mf_layer.classitem = tb_field
+    
+    def set_type(self, tb_type):
+        # if type = arc its a in shapetype line
+        if tb_type == "arc":
+            self._mf_layer.type = 1
+        if shp_type.has_key(tb_type):
+            self._mf_layer.type = tb_type
+        else:
+            for shp_paar_nr in shp_type:
+               if shp_type[shp_paar_nr] == tb_type:
+                   self._mf_layer.type = shp_paar_nr
+                   return
+    
+    def set_projection(self, newprojection):
+        self._mfnewprojstring = ""
+        if newprojection:
+            self._newparams = newprojection.GetAllParameters()
+            for field in self._newparams:
+                self._mfnewprojstring = self._mfnewprojstring+ "," + field
+            self._mf_layer.setProjection(self._mfnewprojstring[1:])
+            self._projection.set_projection(newprojection)
+        else:        
+            print "no projection"
+    
+    def add_thubanclass(self, tb_class):
+        new_class = MF_Class(classObj(self._mf_layer))
+        new_class.set_name(tb_class.GetLabel())
+        if self.get_type() == "line":
+            new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
+        else:
+            new_class.add_thubanstyle(tb_class.GetProperties())
+        if tb_class.GetDisplayText() == "DEFAULT":
+            return
+            #new_class.set_expressionstring('/./')
+        else:
+            new_class.set_expressionstring(str(tb_class.GetDisplayText()))
+        self._classes.append(new_class)
 
 class MF_Map:
     """
@@ -338,19 +465,20 @@
     contains, are used:
 
     name, numlayers, extent, shapepath, imagecolor, imagetype, getLayer,
-    getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey
+    getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
+    save(), setExtent(), height, width, setProjection()
 
     
     The following parameters and functions are not used:
-    status, height, width, maxsize, layers, symbolset, fontset, labelcache,
+    status, maxsize, layers, symbolset, fontset, labelcache,
     transparent, interlace, imagequality, cellsize, units, debug, datapattern,
     templatepattern, configoptions
     zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
-    clone(), setExtent(), removeLayer(), getLayerByName(), getSymbolByName(),
+    clone(), removeLayer(), getLayerByName(), getSymbolByName(),
     prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),
     drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),
     nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),
-    setWKTProjection(), setProjection(), save(), saveQuery(), saveQueryASGML(),
+    setWKTProjection(), saveQuery(), saveQueryASGML(),
     setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),
     saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),
     getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),
@@ -361,7 +489,7 @@
     
     def __init__(self, mf_map):
         """
-	Create the map object from the mapfile mapobject witch is given.
+	Create the map object from the mapfile mapobject which is given.
 
 	All layers in the mapfile will be written to an array.
 	"""
@@ -403,8 +531,7 @@
                 self._metakeydata = self._mf_map.getMetaData(self._metafkey)
                 self._metadata.add_metadata(self._metafkey,self._metakeydata)
                 self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
-            
-
+    
     def get_extent(self):
         return self._extent
         
@@ -422,12 +549,71 @@
     
     def get_imagetype(self):
         return self._imagetype
-        
+    
     def get_layerorder(self):
         # shows the order of layer as list
         return self._mf_map.getLayerOrder()    
-
-
+    
+    def set_name(self, newname):
+        # whitespace musst be replaced, either no
+        # mapfile will be shown in the mapserver
+        newname = newname.replace(" ","_")
+        self._name = newname
+        self._mf_map.name = newname
+    
+    def set_extent(self, newextent):
+        # TODO: add the shown extend here instead of the total
+        self._newrect = MF_Rectangle(rectObj())
+        self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
+        self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
+    
+    def set_size(self, newwidth, newheight):
+        self._mf_map.width = newwidth
+        self._mf_map.height = newheight
+    
+    def set_projection(self, projection):
+        self._mfnewprojstring = ""
+        self._newparams = projection.GetAllParameters()
+        for field in self._newparams:
+            self._mfnewprojstring = self._mfnewprojstring+ "," + field
+        self._mf_map.setProjection(self._mfnewprojstring[1:])
+        self._projection.set_projection(projection)
+      
+    def add_thubanlayer(self, tb_layer):
+        new_layer = MF_Layer(layerObj(self._mf_map))
+        new_layer.set_name(tb_layer.Title())
+        
+        # TODO: implement relative pathnames
+        # yet only absolute pathnames in the LayerObj are set
+        new_layer.set_data(tb_layer.ShapeStore().FileName())
+        
+        new_layer.set_status(tb_layer.Visible())
+        new_layer.set_type(tb_layer.ShapeType())
+        
+        # set the projection to the layer.
+        # 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:
+            new_layer.set_projection(self._projection.get_projection())
+        
+        if tb_layer.GetClassificationColumn():
+            new_layer.set_classitem(tb_layer.GetClassificationColumn())
+        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())
+        else:
+            new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
+        self._layers.append(new_layer)
+    
+    def save_map(self, filepath):
+        # save the Map
+        # maybe an own saver can implement here
+        self._mf_map.save(filepath)
+        
 class MF_Projection:
     """
     The following parameter, which the mapscript style obj contains is used:
@@ -443,6 +629,7 @@
 	be splitted and an array with the parameters will be creaded.
 	"""
         self._mfprojstring = mf_projection
+        self._projstring = self._mfprojstring
         self._epsgcode = None
         self._params = None
         if self._mfprojstring:
@@ -489,17 +676,27 @@
     def get_epsgproj(self):
         # get an epsg projectionobject
         return self.epsg_code_to_projection(self._epsgcode)
-
+    
+    def get_projection(self):
+        return self._projstring
+    
+    def set_projection(self, newprojection):
+        self._projstring = newprojection
+        self._params = newprojection.GetAllParameters()
+        self._mfnewprojstring = ""
+        for field in self._params:
+            self._mfnewprojstring = self._mfnewprojstring+ "+" + field
+        self._mfprojstring = self._mfnewprojstring
 
 class MF_Style:
     """
     The following parameters, which the mapscript style obj
     contains, are used:
     
-    color, backgroundcolor, outlinecolor, size
+    color, backgroundcolor, outlinecolor, size, symbolname
 
     The following are not used:
-    symbol, symbolname, sizescaled, minsize, maxsize, offsetx, offsety,
+    symbol, sizescaled, minsize, maxsize, offsetx, offsety,
     antialias
     """
  
@@ -513,10 +710,10 @@
         """
         self._style = mf_style
         if self._style.color.red == -1:
-            self._color = None
+            self._maincolor = None
         else:
-            self._color = MF_Color(self._style.color)
-        self._backgroundcolor = MF_Color(self._style.backgroundcolor)
+            self._maincolor = MF_Color(self._style.color)
+        self._color = MF_Color(self._style.color)
         if self._style.outlinecolor.red == -1:
             self._outlinecolor = None
         else:
@@ -530,3 +727,25 @@
    
     def get_size(self):
         return self._style.size
+    
+    def set_linecolor(self, tb_color):
+        self._color = tb_color
+        new_linecolor = MF_Color(colorObj())
+        new_linecolor.set_thubancolor(tb_color)
+        self._outlinecolor = new_linecolor
+        self._style.outlinecolor = new_linecolor.get_mfcolor()
+    
+    def set_color(self, tb_color):
+        self._color = tb_color
+        new_color = MF_Color(colorObj())
+        new_color.set_thubancolor(tb_color)
+        self._color = new_color
+        self._style.color = new_color.get_mfcolor()
+    
+    def set_size(self, newsize):
+        self._style.size = newsize
+    
+    def set_symbolname(self, newsymbol):
+        # its possible to use stringnames instead of numbers
+        self._style.symbolname = 'circle'
+





More information about the Thuban-devel mailing list

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