jschuengel: thuban/Extensions/umn_mapserver mf_import.py,1.5,1.6

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


Author: jschuengel

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

Modified Files:
	mf_import.py 
Log Message:
Replace	the exception handling on loading the layers by an if statement.It is not necessary to us the exception there.		
The Filepath creation now use os.path.join to build the path.


Index: mf_import.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_import.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mf_import.py	6 Jul 2004 14:31:28 -0000	1.5
+++ mf_import.py	14 Jul 2004 10:34:10 -0000	1.6
@@ -138,18 +138,19 @@
         #check if rasterlayer
         if maplayer.get_type() == 'raster':
             imgpath = maplayer.get_data()
-            try:
+            # if there is no imagepath defined, the Raster Layer could not load
+            if imgpath == None:
+                context.mainwindow.RunMessageBox(_('Error Loading Raster Layer'),
+                                                 _("Can't open the rasterlayer '%s'.") % layertitle)
+            else:
                 if os.path.isabs(imgpath):
-                    filename = imgpath 
+                    filename = imgpath
                 else:
-                    filename = filepath +"/" + mapobj.get_shapepath() +'/' + imgpath 
+                    filename = os.path.join(filepath,mapobj.get_shapepath(),imgpath) 
                 # Normalize the pathname by collapses 
                 # redundant separators and up-level references
                 filename = os.path.normpath(filename)
-            except:
-                context.mainwindow.RunMessageBox(_('Error Loading Raster Layer'),
-                                                 _("Can't open the rasterlayer '%s'.") % layertitle)
-            else:
+
                 rasterlayer = RasterLayer(maplayer.get_name(), filename)
                 # set the visible status
                 rasterlayer.SetVisible(maplayer.get_status())
@@ -163,19 +164,21 @@
              (maplayer.get_type() == 'line') or
              (maplayer.get_type() == 'circle') or
              (maplayer.get_type() == 'point')):
-            try:
+            
+            if mapobj.get_layers()[layernr].get_data():
                 if os.path.isabs(mapobj.get_layers()[layernr].get_data()):
                     filename = mapobj.get_layers()[layernr].get_data() +".shp"
                 else:
-                    filename = filepath + "/" + mapobj.get_shapepath() + "/" + \
-                           mapobj.get_layers()[layernr].get_data() +".shp"
+                    filename = os.path.join(filepath, mapobj.get_shapepath(), \
+                                                   mapobj.get_layers()[layernr].get_data())
+                    filename = filename + ".shp"
                 # Normalize the pathname by collapses 
                 # redundant separators and up-level references
                 filename = os.path.normpath(filename)
-            except:
+            else:
                 context.mainwindow.RunMessageBox(_('Error Loading Layer'),
                     _("no shp file definied, maybe used a feature obj '%s'.") % layertitle)
-                continue
+            # try to open the layer
             try:
                 store = context.application.Session().OpenShapefile(filename)
                 layer_count += 1
@@ -365,7 +368,6 @@
     return MF_Map(theMap)
 
 
-
 # ###################################
 #
 # Hook in MapServer Extension into Thuban
@@ -373,7 +375,7 @@
 # ###################################
 
 # register the new command
-registry.Add(Command("import_mapfile", _("Import Mapfile"), import_mapfile,
+registry.Add(Command("import_mapfile", _("Import mapfile"), import_mapfile,
                      helptext = _("Import a mapfile")))
 
 # find the extensions menu (create it anew if not found)





More information about the Thuban-devel mailing list

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