jschuengel: thuban/Extensions/umn_mapserver mf_import.py,1.3,1.4

cvs@intevation.de cvs at intevation.de
Thu Jul 1 16:36:39 CEST 2004


Author: jschuengel

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

Modified Files:
	mf_import.py 
Log Message:
Added the possibility to import mapfiles without any layer selected. So it is possible to edit the other settings in a mapfile.
(import_mapfile): Added code to use the editing functions.
Added the possibility to import the projection to a layer if one is defined.
Status settings (On,Off) will now set in thuban (visible, invisible). 
fixed a bug with with classnames. If no classname is set in mapfile the value in Thuban will set to the expression.


Index: mf_import.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_import.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mf_import.py	23 Jun 2004 12:40:45 -0000	1.3
+++ mf_import.py	1 Jul 2004 14:36:37 -0000	1.4
@@ -99,49 +99,48 @@
     if numlayers == 0:
         context.mainwindow.RunMessageBox(_('Loading Layer'),
                                      _("No Layer found."))
-        return
     else:
         context.mainwindow.RunMessageBox(_('Loading Layer'),
                                          _("%s Layer loaded from file.") % numlayers)
 
+    selectedlayer = []
     # Show a dialog to select layers to load into thuban
-    lst = []
-    for layernr in range(0, numlayers,1):
-        lst.append(mapobj.get_layers()[layernr].get_name() +
-                  " (" + mapobj.get_layers()[layernr].get_type() +")" )
-            
-    dlgsize = (300,130+len(lst)*20)
-    if dlgsize[1] >= 300:
-        dlgsize = (300,300)
-    dlg = wxMultipleChoiceDialog(context.mainwindow,
-                                 "Select the layers from the\n" +
-                                 "list to load into thuban.\n" +
-                                 "annotation not supported !",
-                                 "Select Layer.", lst, size = dlgsize)
-    if (dlg.ShowModal() == wxID_OK):
-        selectedlayer = dlg.GetValue()
-    else:
-        selectedlayer = []
+    if numlayers != 0:
+        lst = []
+        for layernr in range(0, numlayers,1):
+            lst.append(mapobj.get_layers()[layernr].get_name() +
+                      " (" + mapobj.get_layers()[layernr].get_type() +")" )
+                
+        dlgsize = (300,130+len(lst)*20)
+        if dlgsize[1] >= 300:
+            dlgsize = (300,300)
+        dlg = wxMultipleChoiceDialog(context.mainwindow,
+                                     "Select the layers from the\n" +
+                                     "list to load into thuban.\n" +
+                                     "annotation not supported !",
+                                     "Select Layer.", lst, size = dlgsize)
+        if (dlg.ShowModal() == wxID_OK):
+            selectedlayer = dlg.GetValue()
 
     # counter to show the numer of layer loaded into Tuban
     layer_count = 0
     # thuban map context
     tb_map = context.mainwindow.canvas.Map()
-    # set the name of the map in thuban
+    # set the titel an projection
     tb_map.SetTitle(mapobj.get_name())
-    # set the projection in thuban only if one layer selected
-    if len(selectedlayer) != 0:
-        set_projection_to_tb(tb_map,mapobj)
+    set_projection_to_tb(tb_map,mapobj)
+        
     # Check for each Layer if it is possible to show in Thuban
     for layernr in selectedlayer:
         maplayer = mapobj.get_layers()[layernr]
         layertitle = maplayer.get_name()
+        
         #check if rasterlayer
         if maplayer.get_type() == 'raster':
             imgpath = maplayer.get_data()
             try:
-                if os.path.isabs(mapobj.get_shapepath()):
-                    filename = mapobj.get_shapepath() +'/' + imgpath 
+                if os.path.isabs(imgpath):
+                    filename = imgpath 
                 else:
                     filename = filepath +"/" + mapobj.get_shapepath() +'/' + imgpath 
                 # Normalize the pathname by collapses 
@@ -152,11 +151,12 @@
                                                  _("Can't open the rasterlayer '%s'.") % layertitle)
             else:
                 rasterlayer = RasterLayer(maplayer.get_name(), filename)
+                # set the visible status
+                rasterlayer.SetVisible(maplayer.get_status())
+                #add the projection if exists
+                set_projection_to_tb(rasterlayer, maplayer)
                 tb_map.AddLayer(rasterlayer)
                 layer_count += 1
-                # TODO check this, because if the projection is not set
-                # correctly, adding the raster layer will show an error
-                # set_projection_to_tb(rasterlayer, maplayer)
 
         #check if polygonlayer
         if ((maplayer.get_type() == 'polygon') or   
@@ -240,10 +240,11 @@
                     #    Regular expressions
                     #    Logical expressions
                     expressionstring = map_clazz.get_expressionstring()
-                    
                     if (((map_numclazzes == 1) & (not expressionstring)) or
                        ((map_numclazzes > 1) & (expressionstring == None)) or
                        (expressionstring == '/./')):
+                        if clazz_name == None:
+                            clazz_name = ""
                         new_group = ClassGroupDefault(props = prop, label = clazz_name)
                         clazz.SetDefaultGroup(new_group)
                         defaultclazzset = True
@@ -264,7 +265,7 @@
                             theexpression = int(expressionstring[1:-1])
                         except:
                             theexpression = expressionstring[1:-1]
-                        if clazz_name == 'none':
+                        if clazz_name == None:
                             clazz_name = str(theexpression)
                         new_group = ClassGroupSingleton(value = theexpression,
                                                         props = prop,
@@ -283,15 +284,40 @@
                     clazz.SetDefaultGroup(new_group)
                     defaultclazzset = None
                 
+                # set the visible status
+                layer.SetVisible(maplayer.get_status())
+                # associate the maplayer object to the layer in thuban.
+                layer.extension_umn_layerobj = maplayer
+                
+                #add the projection if exists
+                set_projection_to_tb(layer, maplayer)
+
                 #add the layer into thuban
                 tb_map.AddLayer(layer)
+               
+    # maybe remove all used layers
+    # for nr in range(len(selectedlayer)-1, -1, -1):
+    #    print selectedlayer[nr]
+    #    mapobj.remove_layer(selectedlayer[nr])
+    
+    # remove alle layer from the mapobj, because the layer will be
+    # created new in export, and the unused layers are not needed
+    # TODO: Save the layers which are not used somewhere, to edit
+    # them later and export it.
+    for nr in range(len(mapobj.get_layers())-1, -1, -1):
+        mapobj.remove_layer(nr)
+        
+    # add the map object to thuban, to use it later
+    tb_map.extension_umn_mapobj = mapobj
     
     # fit the new map to the window
     context.mainwindow.canvas.FitMapToWindow()
 
     # show a message how many layer were loaded into thuban
-    context.mainwindow.RunMessageBox(_('Layer loaded'),
-                                     _("%s Layer loaded into Thuban") % layer_count)
+    # if the number of layers is not null
+    if numlayers != 0:
+        context.mainwindow.RunMessageBox(_('Layer loaded'),
+                                         _("%s Layer loaded into Thuban") % layer_count)
 
 def set_projection_to_tb(tb_con, mapobj):
     """
@@ -302,8 +328,15 @@
         mapobj -- The mapobject (from mapscript)
     """
     if (mapobj.get_projection().get_params() != None):
-        projparam = mapobj.get_projection().get_params()
-        tb_con.SetProjection(Projection(projparam))
+        projparams = mapobj.get_projection().get_params()
+        # check if it is an latlong projection, becaues one
+        # more parameter is needed in that case
+        for param in projparams:
+            projkey = param.split("=")
+            if projkey[0] == "proj":
+                if projkey[1] == "latlong":
+                    projparams.append("to_meter=0.017453")
+        tb_con.SetProjection(Projection(projparams))
     if mapobj.get_projection().get_epsgcode() != None:
         projepsg = mapobj.get_projection().get_epsgproj()
         tb_con.SetProjection(projepsg)  





More information about the Thuban-devel mailing list

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