jschuengel: thuban/Extensions/umn_mapserver mf_export.py,1.4,1.5

cvs@intevation.de cvs at intevation.de
Thu Jul 22 14:37:30 CEST 2004


Author: jschuengel

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

Modified Files:
	mf_export.py 
Log Message:
Added "import os"
Removed the old "import Thuban.UI.mainwindow" code.
(tbextent_to_map): Removed the extra function and at the code direct to "thuban_to_map" function.
(write_creatorcomment): Added. Now a short comment is added to the beginning of an generated mapfile.
(export_mapfile): Now the Path and filename are saved in to variables and not together in one variable. This is needed for the new write_creatorcomment function.


Index: mf_export.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mf_export.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mf_export.py	14 Jul 2004 10:36:40 -0000	1.4
+++ mf_export.py	22 Jul 2004 12:37:28 -0000	1.5
@@ -22,7 +22,7 @@
 #
 # ###################################
 
-#import os, sys
+import os
 
 # mapscript
 from mapscript import mapObj
@@ -39,9 +39,6 @@
 # instance registry.
 from Thuban.UI.command import registry, Command
 
-# The instance of the main menu of the Thuban application
-#import Thuban.UI.mainwindow
-
 # needed to add the new menu
 from Thuban.UI.mainwindow import main_menu
 
@@ -66,12 +63,6 @@
     for layer in tb_layers:
         map.add_thubanlayer(layer)
 
-def tbextent_to_map(tb_map, map):
-    tb_bbox = tb_map.ProjectedBoundingBox()
-    # Size must be set before, because mapscript checks it
-    # when extent is set
-    map.set_extent(tb_bbox)
-
 def thuban_to_map(tb_context, map):
     # get the thuban map
     tb_map = tb_context.mainwindow.canvas.Map()
@@ -80,7 +71,11 @@
     # set the projection
     tbproj_to_map(tb_map, map)
     # set the extend
-    tbextent_to_map(tb_map, map)
+    tb_bbox = tb_map.ProjectedBoundingBox()
+    # tb_bbox = tb_context.mainwindow.canvas.get_view_transform()
+    # Size must be set before, because mapscript checks it
+    # when extent is set
+    map.set_extent(tb_bbox)
     tblayer_to_map(tb_map, map)
 
 def add_circle_symbol(map):
@@ -92,7 +87,21 @@
         new_symbol.set_type(2)
         new_symbol.set_filled(True)
         map.get_symbolset().add_symbol(new_symbol)
-        
+
+def write_creatorcomment(path,file):
+    thuban_umn_comment = "# \n" + \
+                                "# Map file generated by Thuban (umn_mapserver Extension) \n" + \
+                                "# \n \n"
+    datafile = os.path.join(path,file)
+    
+    in_file = open(datafile,"r")
+    text_in_file = in_file.read()
+    in_file.close()
+    
+    out_file = open(datafile,"w")
+    out_file.write(thuban_umn_comment)
+    out_file.write(text_in_file) # text in Datei schreiben
+    out_file.close()    # Datei schliessen
     
     
 def export_mapfile(context):
@@ -108,7 +117,8 @@
                        "All files (*.*)|*.*",
                        wxSAVE |wxOVERWRITE_PROMPT)
     if dlg.ShowModal() == wxID_OK:
-        path = dlg.GetPath()
+        path = dlg.GetDirectory()
+        file = dlg.GetFilename()
         dlg.Destroy()
     else:
         return
@@ -118,9 +128,13 @@
 
     #add symbol
     add_circle_symbol(theMap)
-    
+
     # save the map with the integrated mapscript saver
-    theMap.save_map(path)
+    theMap.save_map(os.path.join(path,file))
+    
+    # this funktion will write a commend to the generated mapfile
+    # that shows that the file is generated by thuban
+    write_creatorcomment(path,file)
     
     # remove alle added layers from the temporary mapobj
     # this is necessary because the layers will add new on each save





More information about the Thuban-devel mailing list

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