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

cvs@intevation.de cvs at intevation.de
Wed Jul 14 12:38:10 CEST 2004


Author: jschuengel

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

Modified Files:
	mapfile.py 
Log Message:
Added ClassGroupDefault to import.
(MF_Symbolset): Removed the extra variable for numsymbols.
(MF_Class.__init__): Added a comment to the exception clause.
Removed the extent init, because it was not needed anymore.
(MF_Layer.add_thubanclass): Added the code to set the class name to the expression value from thuban if no label is defined. 
Added the code to export Range expressions from thuban to the mapfile.
(MF_Map.set_extent): Removed the exception and replace it by some if code. If the size of a map is not defined the size will be set to 1,1. This is necessary because if the extent is set, mapscript checks if the size is greater than zero.
(MF_Web): Added the get and set function for the template.


Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mapfile.py	8 Jul 2004 14:26:56 -0000	1.6
+++ mapfile.py	14 Jul 2004 10:38:08 -0000	1.7
@@ -39,6 +39,9 @@
 
 from Thuban.Model.color import Color, Transparent 
 
+from Thuban.Model.classification import ClassGroupDefault, \
+                                        ClassGroupSingleton, ClassGroupRange
+
 from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, symbolObj, \
                       pointObj, lineObj
 
@@ -354,9 +357,8 @@
         
         # Initial Symbol List
         self._symbols = []
-        self._numsymbols = self._symbolset.numsymbols
         self._i = 1
-        while self._i < self._numsymbols:
+        while self._i < self._symbolset.numsymbols:
             self._symbols.append(MF_Symbol(self._symbolset.getSymbol(self._i)))
             self._i += 1
 
@@ -370,7 +372,7 @@
         os.remove("tempsymbol")
 
     def get_symbol(self, symbolnr):
-        if symbolnr < self._numsymbols:
+        if symbolnr < self._symbolset.numsymbols:
             return self._symbols[symbolnr-1]
         else:
             return None
@@ -409,6 +411,9 @@
             self._expression = self._clazz.getExpressionString()
         
         self.metadata = MF_Metadata()
+        # try to get the first metaDatakey. If it does not exists, the following
+        # error will occur:
+        # MapServerError: getFirstMetaDataKey: Hash table error. Key  does not exist
         try:
             self.metafkey = mf_class.getFirstMetaDataKey()
         except:
@@ -522,14 +527,6 @@
             
         self._projection = MF_Projection(self._mf_layer.getProjection())
         
-        # Variable extent will not used for RasterLayer
-        # this variable is not necessary, because it comes directly
-	# from the shp file
-        try:
-            self._extent = MF_Rectangle(self._mf_layer.getExtent())
-        except:
-            self._extent = None
-
         # Create Metadata
         self._metadata = MF_Metadata()
         try:
@@ -613,9 +610,20 @@
     def add_thubanclass(self, tb_class, type=""):
         """
         Add a thuban class object
-        """
+        """      
         new_class = MF_Class(classObj(self._mf_layer))
-        new_class.set_name(tb_class.GetLabel())
+        # set the class name to the Label form thuban if given,
+        # else set it to the value
+        if tb_class.GetLabel() != "":
+            new_class.set_name(tb_class.GetLabel())
+        else:
+            if isinstance(tb_class, ClassGroupDefault):
+                new_class.set_name("default")
+            elif isinstance(tb_class, ClassGroupSingleton):
+                new_class.set_name(str(tb_class.GetValue()))
+            else:
+                # TODO: set a name if the expression is a ogical                
+                new_class.set_name("no name")
         if self.get_type() == "line":
             new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
         elif self.get_type() == "point":
@@ -624,10 +632,64 @@
             new_class.add_thubanstyle(tb_class.GetProperties())
         if (type == "default"):
             return
+        # removed the following two lines to check if the expressionstring
+        # is needed for points, because if expressionstring is a range type,
+        # no expressionstring in the default group is allowed
         elif (tb_class.Matches("DEFAULT")):
-            new_class.set_expressionstring('/./')
+            return
+           # new_class.set_expressionstring('/./')
         else:
-            new_class.set_expressionstring(str(tb_class.GetValue()))
+            #check which type of expression 
+            if isinstance(tb_class, ClassGroupRange):
+                # get the needed infos from the Range-String
+                self._range_begin = tb_class.GetRange()[0]
+                self._range_min = str(tb_class.GetMin())
+                self._range_max = str(tb_class.GetMax())
+                self._range_end = tb_class.GetRange()[len(tb_class.GetRange())-1]
+                self._range_umn = ""
+                self._range_classitem = self.get_classitem()
+                # generate the operator
+                if self._range_begin == "[":
+                    self._range_op1 = ">="
+                elif self._range_begin == "]":
+                    self._range_op1 = ">"
+                else:
+                    print "error in Thuban class properties"
+                #build op1 string for the lower limit
+                self._range_op1 = "[" + self._range_classitem + "] " + \
+                                 self._range_op1 + " " +\
+                                 self._range_min
+                # build op2 string for the upper limit
+                if self._range_end == "[":
+                    self._range_op2 = "<"
+                elif self._range_end == "]":
+                    self._range_op2 = "<="
+                else:
+                    print "error in Thuban class properties"
+
+                self._range_op2 = "[" + self._range_classitem + "] " + \
+                                 self._range_op2 + " " +\
+                                 self._range_max
+                # we only need AND here at the moment, becaus of the limits 
+                # in thuban
+                self._range_combine = "AND"
+                # check if the one limit is set to inf and then
+                # remove the second expression becaus is not needed.
+                if self._range_min == "-inf":
+                    self._range_combine = ""
+                    self._range_op1 = ""
+                elif self._range_max == "inf":
+                    self._range_combine = ""
+                    self._range_op2 = ""
+                # build the expression together
+                self._range_umn = "(" + self._range_umn + \
+                                 self._range_op1 + " " +\
+                                 self._range_combine + \
+                                 self._range_op2 + " )"
+                #set the expression to the mapscript
+                new_class.set_expressionstring(self._range_umn)
+            else:
+                new_class.set_expressionstring(str(tb_class.GetValue()))
         new_class.set_status(tb_class.IsVisible())
         self._classes.append(new_class)
 
@@ -894,14 +956,16 @@
     
     def set_extent(self, newextent):
         # 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], \
+        # if no size is set or if it is zero, the size will set to 1.
+        if self.get_size()[0] == - 1:
+            print "define the size first to set extent"
+            print "size is now set to (1,1)"
+            self.set_size(1,1)
+        self._newrect = MF_Rectangle(rectObj(newextent[0],newextent[1], \
+	                           newextent[2],newextent[3]))
+        self._mf_map.setExtent(newextent[0],newextent[1], \
 	                           newextent[2],newextent[3])
-        except:
-            return
+
     
     def set_size(self, newwidth, newheight):
         self._mf_map.width = newwidth
@@ -950,12 +1014,19 @@
             if tb_layer.GetProjection():
                 new_layer.set_projection(tb_layer.GetProjection())
             if tb_layer.GetClassification().GetNumGroups() > 0:
+                singletonexists = False
                 for group in range(0, \
 		                tb_layer.GetClassification().GetNumGroups(), 1):
+                    if isinstance(tb_layer.GetClassification().GetGroup(group), \
+                                    ClassGroupSingleton):
+                        singletonexists = True
                     new_layer.add_thubanclass( \
 		                   tb_layer.GetClassification().GetGroup(group))
                 new_layer.add_thubanclass( \
 		                 tb_layer.GetClassification().GetDefaultGroup())
+                # remove the classitem if one singleton exists
+                if singletonexists == False:
+                    new_layer.set_classitem(None)
             else:
                 new_layer.add_thubanclass( \
 		               tb_layer.GetClassification().GetDefaultGroup(), \
@@ -1003,6 +1074,12 @@
     
     def get_imageurl(self):
         return self._mf_web.imageurl
+    
+    def get_template(self):
+        return self._mf_web.template
+    
+    def set_template(self, new_template):
+        self._mf_web.template = new_template
 
     def set_imageurl(self, new_imageurl):
         self._mf_web.imageurl = new_imageurl





More information about the Thuban-devel mailing list

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