jschuengel: thuban/Extensions/umn_mapserver mf_import.py,1.1,1.2
cvs@intevation.de
cvs at intevation.de
Wed Jun 16 12:44:36 CEST 2004
Author: jschuengel
Update of /thubanrepository/thuban/Extensions/umn_mapserver
In directory doto:/tmp/cvs-serv6564
Modified Files:
mf_import.py
Log Message:
Changed the wxPython.wx import from * to explicit used statements.
Changed the Thuban.UI.mainwindow import phrase, too.
(import_mapfile):Corrected a clerical mistake.
Added wxCHANGE_DIR in OpenFile Dialog
Added a MultipleChoiceDialog, to select the layers to load from mapfile into thuban. Thereby the projection is only set if one layer is selected.
Added the possibility to handle relative pathnames which uses up-level references.Removed some doubled code.
Corrected an error with integer values used as label in thuban ClassGroup.
Index: mf_import.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_import.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mf_import.py 10 Jun 2004 12:49:58 -0000 1.1
+++ mf_import.py 16 Jun 2004 10:44:34 -0000 1.2
@@ -22,12 +22,14 @@
#
# ###################################
-import os, sys
+import os#, sys
from mapscript import mapObj
-# TODO: explicitly use from .. import
-from wxPython.wx import *
+from wxPython.wx import wxFileDialog, wxCHANGE_DIR,\
+ wxOPEN, wxOVERWRITE_PROMPT, wxID_OK
+
+from wxPython.lib.dialogs import wxMultipleChoiceDialog
# use _() already now for all strings that may later be translated
from Thuban import _
@@ -37,7 +39,7 @@
from Thuban.UI.command import registry, Command
# The instance of the main menu of the Thuban application
-import Thuban.UI.mainwindow
+from Thuban.UI import mainwindow
# The layer an projection from Thuban
from Thuban.Model.layer import Layer, RasterLayer
@@ -76,23 +78,50 @@
_("Select MapFile file"), ".", "",
_("UMN MapServer Mapfiles (*.map)|*.map|") +
_("All Files (*.*)|*.*"),
- wxOPEN|wxOVERWRITE_PROMPT)
+ wxOPEN|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
if dlg.ShowModal() == wxID_OK:
filename = dlg.GetPath()
dlg.Destroy()
else:
return
-
+
# get the path to the file
- filepath = os.path.dirname(filename)
-
+ mapfilepath = os.path.dirname(filename)
# Parse mapfile
mapobj = parse_mapfile(filename)
-
- # Show numer of Layer fond in file
+ # set the filepath empty if shapepath is absolute
+ if os.path.isabs(mapobj.get_shapepath()):
+ filepath = ""
+ else:
+ filepath = mapfilepath
+ # Show number of Layer found in file
numlayers = len(mapobj.get_layers())
- context.mainwindow.RunMessageBox(_('Loading Layer'),
- _("%s Layer loaded from File.") % numlayers)
+ if numlayers == 0:
+ context.mainwindow.RunMessageBox(_('Loading Layer'),
+ _("No Layer found."))
+ return
+ else:
+ context.mainwindow.RunMessageBox(_('Loading Layer'),
+ _("%s Layer loaded from file.") % numlayers)
+
+ # 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 = []
# counter to show the numer of layer loaded into Tuban
layer_count = 0
@@ -100,20 +129,21 @@
tb_map = context.mainwindow.canvas.Map()
# set the name of the map in thuban
tb_map.SetTitle(mapobj.get_name())
-
- # set the projection in thuban
- set_projection_to_tb(tb_map,mapobj)
-
+ # set the projection in thuban only if one layer selected
+ if len(selectedlayer) != 0:
+ set_projection_to_tb(tb_map,mapobj)
# Check for each Layer if it is possible to show in Thuban
- for layernr in range(0, numlayers,1):
+ 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:
filename = 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)
@@ -125,7 +155,6 @@
# correctly, adding the raster layer will show an error
# set_projection_to_tb(rasterlayer, maplayer)
-
#check if polygonlayer
if ((maplayer.get_type() == 'polygon') or
(maplayer.get_type() == 'line') or
@@ -134,6 +163,9 @@
try:
filename = filepath + "/" + mapobj.get_shapepath() + "/" + \
mapobj.get_layers()[layernr].get_data() +".shp"
+ # Normalize the pathname by collapses
+ # redundant separators and up-level references
+ filename = os.path.normpath(filename)
except:
context.mainwindow.RunMessageBox(_('Error Loading Layer'),
_("no shp file definied, maybe used a feature obj '%s'.") % layertitle)
@@ -224,13 +256,12 @@
(expressionstring[0] == '"')):
expressionclassitem = maplayer.get_classitem().upper()
layer.SetClassificationColumn(expressionclassitem)
- theexpression = expressionstring[1:-1]
try:
theexpression = int(expressionstring[1:-1])
except:
theexpression = expressionstring[1:-1]
if clazz_name == 'none':
- clazz_name = theexpression
+ clazz_name = str(theexpression)
new_group = ClassGroupSingleton(value = theexpression,
props = prop,
label = clazz_name)
@@ -286,7 +317,7 @@
"""
theMap = mapObj(filename)
- return MF_Map(theMap)
+ return MF_Map(theMap)
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)