jschuengel: thuban/Extensions/umn_mapserver mapfile.py,1.10,1.11

cvs@intevation.de cvs at intevation.de
Mon Aug 9 13:38:50 CEST 2004


Author: jschuengel

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

Modified Files:
	mapfile.py 
Log Message:
Move the import AnnotationLayer to the function where it is needed, because it don't works if it stands at the beginning.
(MF_Layer.__init__): Removed the extra numclassed variable. Now numclasses from the mapscript will be used.
(MF_Layer.get_index): New. Return the index of the layer in mapfile.
(MF_Layer.set_classes): New. A Classlist will be set to the layer.
(MF_Layer.set_metadata): New. A Metadata mapscript object will set.
(MF_Layer.remove_allclasses): New. All class of the layer will remove.
(MF_Map.create_new_layer): New. A new Layer is created and associated with the mapscript object.
(MF_Map.set_layerorder): New. The Layer order like in thuban is set in the mapscript.
(MF_Map.add_thubanlayer): Now a new layerobj is created if no one is linked to the layer in thuban, else the layerobject linked to the thubanlayer will be used.
AnnotationLayer will now store the filename of the shapefile.
(MF_Map.remove_layer): If a layer is removed the associated object must be set new.


Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mapfile.py	3 Aug 2004 11:46:00 -0000	1.10
+++ mapfile.py	9 Aug 2004 11:38:47 -0000	1.11
@@ -42,11 +42,10 @@
 from Thuban.Model.classification import ClassGroupDefault, \
                                         ClassGroupSingleton, ClassGroupRange
 
-from Thuban.Model.layer import RasterLayer
-from Extensions.umn_mapserver.mf_import import AnnotationLayer
-
 from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, symbolObj, \
                       pointObj, lineObj
+                      
+from Thuban.Model.layer import RasterLayer
 
 # ###################################
 #
@@ -519,15 +518,13 @@
 	the class objects in the layer object will be stored in
 	an array. The metadata are created as a new object.
         """
-       
         self._mf_layer = mf_layer
 
         # Create Classes 
         # there could be more then 1 
-        self._numclasses = mf_layer.numclasses
         i = -1
         self._classes = []
-        while i < self._numclasses-1:
+        while i < self._mf_layer.numclasses-1:
             i += 1
             self._classes.append(MF_Class(self._mf_layer.getClass(i)))
             
@@ -536,17 +533,26 @@
         # Create Metadata
         self._metadata = MF_Metadata(self._mf_layer)
 
+    def get_index(self):
+        return self._mf_layer.index
+
     def get_name(self):
         return self._mf_layer.name
     
     def get_data(self):
         return self._mf_layer.data
-        
+
     def get_classes(self):
         return self._classes
     
+    def set_classes(self, new_classes):
+        self._classes = new_classes
+       
     def get_metadata(self):
         return self._metadata
+
+    def set_metadata(self, new_metadata):
+        self._metadata = new_metadata
     
     def get_type(self):
         return shp_type[self._mf_layer.type]
@@ -564,7 +570,6 @@
             return False
         else:
             return True
-        #return self._mf_layer.status
     
     def get_group(self):
         return self._mf_layer.group
@@ -572,7 +577,6 @@
     def set_group(self, new_group):
         self._mf_layer.group = new_group
     
-    
     def set_name(self, newname):
         self._mf_layer.name = newname 
     
@@ -581,7 +585,6 @@
             self._mf_layer.data = newdata
         else:
             self._mf_layer.data = newdata[:-4]
-        
     
     def set_status(self, newstatus):
         # status can set to true or false from thuban.
@@ -617,8 +620,9 @@
     def add_thubanclass(self, tb_class, type=""):
         """
         Add a thuban class object
-        """     
+        """ 
         new_class = MF_Class(classObj(self._mf_layer))
+        self._classes.append(new_class)
         # set the class name to the Label form thuban if given,
         # else set it to the value
         if tb_class.GetLabel() != "":
@@ -698,8 +702,11 @@
             else:
                 new_class.set_expressionstring(str(tb_class.GetValue()))
         new_class.set_status(tb_class.IsVisible())
-        self._classes.append(new_class)
 
+    def remove_allclasses(self):
+        for i in range(0,len(self.get_classes()), 1):
+            self._mf_layer.removeClass(i)
+        self.set_classes([])
 
 class MF_Scalebar:
     """
@@ -873,6 +880,18 @@
         # Create Metadata
         self._metadata = MF_Metadata(self._mf_map)
     
+    def create_new_layer(self):
+        """
+        the new layer must create inside the mapobj, because mapscript
+        need the mapscript object as parameter for layerObj
+        """
+        new_layer = MF_Layer(layerObj(self._mf_map))
+        self._layers.append(new_layer)
+        # the new created layer must remove from the mapobject
+        # because all layer will create new in export.
+        #self._mf_map.removeLayer(self._mf_map.numlayers-1)
+        return new_layer  
+    
     def get_mappath(self):
         return self._mf_map.mappath
     
@@ -945,6 +964,9 @@
         # shows the order of layer as list
         return self._mf_map.getLayerOrder()
     
+    def set_layerorder(self, new_order):
+        self._mf_map.setLayerOrder(new_order)
+    
     def get_size(self):
         #returns the size
         return (self._mf_map.width, self._mf_map.height)
@@ -977,7 +999,6 @@
                                     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
@@ -1006,9 +1027,24 @@
         """
         Add a thuban layer
         """
-        new_layer = MF_Layer(layerObj(self._mf_map))
+        # this import statement placed here, because if it is placed at the
+        # beginning of this file, it produced the following error:
+        # NameError: global name 'AnnotationLayer' is not defined
+        # don't know why this error is produced and why it works
+        # if it is placed here instead of the beginning.
+        from Extensions.umn_mapserver.mf_import import AnnotationLayer
+        if hasattr(tb_layer,"extension_umn_layerobj"):
+            #print tb_layer.extension_umn_layerobj
+            #new_layer = MF_Layer(layerObj(self._mf_map))
+            new_layer = tb_layer.extension_umn_layerobj
+        else:
+            new_layer = MF_Layer(layerObj(self._mf_map))
+            self._layers.append(new_layer)
+            tb_layer.extension_umn_layerobj = new_layer
+        new_layer.remove_allclasses()
+        # init a list to set the layerorder
+        new_layer.get_index()
         new_layer.set_name(tb_layer.Title()) 
-
         # TODO: implement relative pathnames
         # yet only absolute pathnames in the LayerObj are set 
         if isinstance(tb_layer, RasterLayer ):
@@ -1018,11 +1054,11 @@
         elif isinstance(tb_layer, AnnotationLayer):
             new_layer.set_type("annotation")
             new_layer.set_status(tb_layer.Visible())
+            new_layer.set_data(tb_layer.ShapeStore().FileName())
         else:
             new_layer.set_data(tb_layer.ShapeStore().FileName())
             new_layer.set_status(tb_layer.Visible())
             new_layer.set_type(tb_layer.ShapeType())
-        
             if tb_layer.GetClassificationColumn():
                 new_layer.set_classitem(tb_layer.GetClassificationColumn())
             if tb_layer.GetProjection():
@@ -1045,26 +1081,25 @@
                 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, 
+        # if the layer has its own definition use it, 
 	   # 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())
-        self._layers.append(new_layer)
-    
-    def remove_layer(self, nr):
-        #remove the last layer from the layer list and not the one which
-        # is removed in mapscript. This must be, becaus mapscript
-        # set the object links anew. Don't understand really :)
-        self._layers.pop()
-        self._mf_map.removeLayer(nr)
     
-    def remove_all_layers(self):
-        for i in range (self._mf_map.numlayers,0,-1):
-            self.remove_layer(i-1)
+    def remove_layer(self, delnr):
+        if delnr < len(self._layers):
+            # if a layer is removed, the links for the mapscript layer and 
+            # the metadata must set new
+            # TODO: All other object in a layer obj must set a new, e.g proj.
+            for ll in range(len(self._layers)-1, delnr, -1):
+                self._layers[ll]._mf_layer = self._layers[ll-1]._mf_layer
+                self._layers[ll].set_metadata(self._layers[ll-1].get_metadata())
+               
+            self._mf_map.removeLayer(delnr)
+            self._layers.pop(delnr)
     
     def save_map(self, filepath):
         # save the Map





More information about the Thuban-devel mailing list

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