jschuengel: thuban/Extensions/umn_mapserver mapfile.py,1.8,1.9

cvs@intevation.de cvs at intevation.de
Wed Jul 28 14:35:34 CEST 2004


Author: jschuengel

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

Modified Files:
	mapfile.py 
Log Message:
Changed all class functions. Now all metadata will handle by the function and its not needed to initialize it from outside. Therefor the associated mapobj will be stored in the Metadata Object. So we can use thespecial functions from the associated mapobj to get the Metadata. Therefor all initialization code for the metadata is removed from the other classes.
(MF_Layer): Added a function to get the metadata object. 
(MF_Map): Added a function to set the mappath, the path where the mapfile ist stored.


Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mapfile.py	15 Jul 2004 14:31:37 -0000	1.8
+++ mapfile.py	28 Jul 2004 12:35:32 -0000	1.9
@@ -229,36 +229,45 @@
     Metadata is not a Object in mapscript witch can be used
     by ease. Only the infos can get with the functions
     "getFirstMetaDataKey", "getNextMetaDataKey" and "getMetaData".
-    To get some special Metadata you need a key. So the metadata will
-    saved as an dictionary to geht the information with the key here.
-    
-    The metadata obj will be created and filled with infos like
-    the following code sample:
-    
-    self.metadata = MF_Metadata()
+    To get some special Metadata you need a key. So there is a special 
+    function which create a list of the metadatakeys.
+    """
+    def __init__(self, mapobj):
+        self.mapobj = mapobj
+
+    def get_metadatakeys(self):
+        keylist = []
         try:
-            self.metafkey = varia.getFirstMetaDataKey()
+            metafkey =self.mapobj.getFirstMetaDataKey()
+            keylist.append(metafkey)
         except:
-            self.metadata = None
+            return None
         else:
-            while self.metafkey:
-                self.metakeydata = varia.getMetaData(self.metafkey)
-                self.metadata.add_metadata(self.metafkey,self.metakeydata)
-                self.metafkey = varia.getNextMetaDataKey(self.metafkey)
-                
-    Metadata are not really needed at the moment.
-    """
-    def __init__(self):
-        self.data = {}
-       
+            if metafkey:
+                while metafkey:
+                    metafkey = self.mapobj.getNextMetaDataKey(metafkey)
+                    if metafkey:
+                        keylist.append(metafkey)
+                return keylist
+
     def get_metadata(self):
-        return self.data
+        keylist = self.get_metadatakeys()
+        metadatalist = []
+        if keylist:
+            for key in keylist:
+                metadatalist.append([key,self.mapobj.getMetaData(key)])
+            return metadatalist
+        else:
+            return None
     
     def get_metadatabykey(self, key):
-        return self.data[key]
+        return self.mapobj.getMetaData(key)
+
+    def remove_metadatabykey(self, key):
+        self.mapobj.removeMetaData(key)
     
     def add_metadata(self, key, data):
-        self.data[key] = data
+        self.mapobj.setMetaData(key,data)
 
 # ################################################
 # Classes for MapServer Objects as they are
@@ -410,19 +419,7 @@
         else:
             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:
-            self.metadata = None
-        else:
-            while self.metafkey:
-                self.metakeydata = mf_class.getMetaData(self.metafkey)
-                self.metadata.add_metadata(self.metafkey,self.metakeydata)
-                self.metafkey = mf_class.getNextMetaDataKey(self.metafkey)
+        self.metadata = MF_Metadata(self._clazz)
 
     def get_styles(self):
         return self._styles
@@ -528,16 +525,7 @@
         self._projection = MF_Projection(self._mf_layer.getProjection())
         
         # Create Metadata
-        self._metadata = MF_Metadata()
-        try:
-            self._metafkey = self._mf_layer.getFirstMetaDataKey()
-        except:
-            self._metadata = None
-        else:
-            while self._metafkey:
-                self._metakeydata = self._mf_layer.getMetaData(self._metafkey)
-                self._metadata.add_metadata(self._metafkey,self._metakeydata)
-                self._metafkey = self._mf_layer.getNextMetaDataKey(self._metafkey)
+        self._metadata = MF_Metadata(self._mf_layer)
 
     def get_name(self):
         return self._mf_layer.name
@@ -547,7 +535,10 @@
         
     def get_classes(self):
         return self._classes
-        
+    
+    def get_metadata(self):
+        return self._metadata
+    
     def get_type(self):
         return shp_type[self._mf_layer.type]
 
@@ -622,10 +613,7 @@
             elif isinstance(tb_class, ClassGroupSingleton):
                 new_class.set_name(str(tb_class.GetValue()))
             else:
-                # TODO: set a name if the expression is a logical           
-                # if it is an logical expression and no name is set,
-                # the final name will be set after expression is created
-                new_class.set_name("no name")
+                new_class.set_name(None)
         if self.get_type() == "line":
             new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
         elif self.get_type() == "point":
@@ -868,21 +856,14 @@
             self._shapepath = ""
 
         # Create Metadata
-        self._metadata = MF_Metadata()
-        try:
-            self._metafkey = self._mf_map.getFirstMetaDataKey()
-        except:
-            self._metadata = None
-        else:
-            while self._metafkey:
-                self._metakeydata = self._mf_map.getMetaData(self._metafkey)
-                self._metadata.add_metadata(self._metafkey,self._metakeydata)
-                self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
-    
+        self._metadata = MF_Metadata(self._mf_map)
+       
     
     def get_mappath(self):
         return self._mf_map.mappath
     
+    def set_mappath(self, new_mappath):
+        self._mf_map.mappath = new_mappath
     
     
     def get_outputformat(self):
@@ -934,9 +915,13 @@
         return self._name
     
     def get_shapepath(self):
-        # where are the shape files located..
+        # where are the shape files located.
         return self._shapepath 
     
+    def set_shapepath(self, new_shapepath):
+        # where are the shape files located..
+        self._shapepath = new_shapepath
+    
     def get_imagetype(self):
         return self._mf_map.imagetype
     
@@ -1006,10 +991,10 @@
         Add a thuban layer
         """
         new_layer = MF_Layer(layerObj(self._mf_map))
-        new_layer.set_name(tb_layer.Title())        
-        
+        new_layer.set_name(tb_layer.Title()) 
+
         # TODO: implement relative pathnames
-        # yet only absolute pathnames in the LayerObj are set
+        # yet only absolute pathnames in the LayerObj are set 
         try:
             new_layer.set_data(tb_layer.ShapeStore().FileName())
         except:
@@ -1045,7 +1030,7 @@
        
         # set the projection to the layer.
         # if the layer has its own definition use is, 
-	# else use the main projection
+	   # else use the main projection
         if tb_layer.GetProjection():
             new_layer.set_projection(tb_layer.GetProjection())
         else:





More information about the Thuban-devel mailing list

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