[Thuban-commits] r2857 - in trunk/thuban: Extensions/umn_mapserver test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Jul 27 07:30:28 CEST 2008


Author: elachuni
Date: 2008-07-27 07:30:28 +0200 (Sun, 27 Jul 2008)
New Revision: 2857

Added:
   trunk/thuban/test/test_mapservpostgis.py
Modified:
   trunk/thuban/Extensions/umn_mapserver/mapfile.py
   trunk/thuban/Extensions/umn_mapserver/mf_import.py
   trunk/thuban/test/postgissupport.py
Log:
Applying patch #689 (Support for PostGIS layers in umn_mapserver extension).



Modified: trunk/thuban/Extensions/umn_mapserver/mapfile.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/mapfile.py	2008-07-27 04:51:22 UTC (rev 2856)
+++ trunk/thuban/Extensions/umn_mapserver/mapfile.py	2008-07-27 05:30:28 UTC (rev 2857)
@@ -96,6 +96,19 @@
                       1:"ON",
                       2:"default"}
 
+layer_connection_type = { mapscript.MS_INLINE:"inline",
+                          mapscript.MS_SHAPEFILE:"shapefile",
+                          mapscript.MS_TILED_SHAPEFILE:"tiled shapefile",
+                          mapscript.MS_SDE:"sde",
+                          mapscript.MS_OGR:"ogr",
+                          mapscript.MS_POSTGIS:"postgis",
+                          mapscript.MS_WMS:"wms",
+                          mapscript.MS_ORACLESPATIAL:"oracle spatial",
+                          mapscript.MS_WFS:"wfs",
+                          mapscript.MS_GRATICULE:"graticule",
+                          mapscript.MS_MYGIS:"mygis",
+                          mapscript.MS_RASTER:"raster"}
+
 legend_position_type = { 0:"ul",
                          1:"lr",
                          2:"ur",
@@ -502,7 +515,7 @@
     labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache
     postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex
     labelsizeitemindex, labelangleitemindex, tileitem, tileindex, units
-    connection, connectiontype, numitems, filteritem, styleitem, requires
+    numitems, filteritem, styleitem, requires
     labelrequires, transparency, dump, debug, numprocessing, numjoins,
     removeClass(), open(), close(), getShape(), getNumResults(), getResult()
     getItem(), promote(), demote(), draw(), drawQuery(), queryByAttributes()
@@ -524,10 +537,8 @@
 
         # Create Classes 
         # there could be more then 1 
-        i = -1
         self._classes = []
-        while i < self._mf_layer.numclasses-1:
-            i += 1
+        for i in range (self._mf_layer.numclasses):
             self._classes.append(MF_Class(self._mf_layer.getClass(i)))
             
         self._projection = MF_Projection(self._mf_layer.getProjection())
@@ -544,6 +555,12 @@
     def get_data(self):
         return self._mf_layer.data
 
+    def get_connection(self):
+        return self._mf_layer.connnection
+
+    def get_connectiontype(self):
+        return self._mf_layer.connectiontype
+
     def get_classes(self):
         return self._classes
     
@@ -583,11 +600,17 @@
         self._mf_layer.name = newname 
     
     def set_data(self, newdata, type="shape"):
-        if type == "raster":
+        if type == "shape":
+            self._mf_layer.data = newdata[:-4]
+        else:
             self._mf_layer.data = newdata
-        else:
-            self._mf_layer.data = newdata[:-4]
-    
+
+    def set_connection (self, newconnection):
+        self._mf_layer.connection = newconnection
+
+    def set_connectiontype (self, newtype):
+        self._mf_layer.connectiontype = newtype
+
     def set_status(self, newstatus):
         # status can set to true or false from thuban.
         # but mapserver supports the default value
@@ -1035,6 +1058,7 @@
         # don't know why this error is produced and why it works
         # if it is placed here instead of the beginning.
         from Extensions.umn_mapserver.mf_import import AnnotationLayer
+        from Thuban.Model.postgisdb import PostGISShapeStore
         if hasattr(tb_layer,"extension_umn_layerobj"):
             #print tb_layer.extension_umn_layerobj
             #new_layer = MF_Layer(layerObj(self._mf_map))
@@ -1058,7 +1082,19 @@
             new_layer.set_status(tb_layer.Visible())
             new_layer.set_data(tb_layer.ShapeStore().FileName())
         else:
-            new_layer.set_data(tb_layer.ShapeStore().FileName())
+            if isinstance (tb_layer.ShapeStore(), PostGISShapeStore):
+                data = "%s from %s" % (tb_layer.ShapeStore().geometry_column,
+                                       tb_layer.ShapeStore().tablename)
+                new_layer.set_data (data, type="postgis")
+                params = []
+                for name in ("host", "port", "dbname", "user", "password"):
+                    val = getattr(tb_layer.ShapeStore().db, name)
+                    if val:
+                        params.append("%s=%s" % (name, val))
+                new_layer.set_connection (" ".join(params))
+                new_layer.set_connectiontype (mapscript.MS_POSTGIS)
+            else:
+                new_layer.set_data(tb_layer.ShapeStore().FileName())
             new_layer.set_status(tb_layer.Visible())
             new_layer.set_type(tb_layer.ShapeType())
             if tb_layer.GetClassificationColumn():

Modified: trunk/thuban/Extensions/umn_mapserver/mf_import.py
===================================================================
--- trunk/thuban/Extensions/umn_mapserver/mf_import.py	2008-07-27 04:51:22 UTC (rev 2856)
+++ trunk/thuban/Extensions/umn_mapserver/mf_import.py	2008-07-27 05:30:28 UTC (rev 2857)
@@ -652,7 +652,7 @@
         if len(selectedlayer) != 0:
             # thuban map context
             tb_map = context.mainwindow.canvas.Map()
-            # set the titel and projection
+            # set the title and projection
             tb_map.SetTitle(mapobj.get_name())
             set_projection_to_tb(tb_map,mapobj)
 

Modified: trunk/thuban/test/postgissupport.py
===================================================================
--- trunk/thuban/test/postgissupport.py	2008-07-27 04:51:22 UTC (rev 2856)
+++ trunk/thuban/test/postgissupport.py	2008-07-27 05:30:28 UTC (rev 2857)
@@ -527,20 +527,22 @@
     first one found (looking under contrib first).  
 
     Debian (umcoming Etch) can do several version of postgresql
-    and thus has changed the paths. We try one location
-    in datadir2 only for Debian Etch postgresql-8.1.
+    and thus has changed the paths. We try locations for
+    postgresql-8.1 and 8.3.
 
     If the file is not found the return value is None.
     """
     bindir = run_config_script("pg_config --bindir").strip()
     datadir = os.path.join(bindir, "..", "share", "postgresql")
     datadir2 = os.path.join("/", "usr", "share", "postgresql-8.1-postgis")
+    datadir3 = os.path.join("/", "usr", "share", "postgresql-8.3-postgis")
 
     for filename in [os.path.join(datadir, "contrib", "postgis.sql"),
                      os.path.join(datadir, "postgis.sql"),
                      os.path.join(datadir, "lwpostgis.sql"),
                      os.path.join(datadir, "contrib", "lwpostgis.sql"),
-                     os.path.join(datadir2, "lwpostgis.sql") \
+                     os.path.join(datadir2, "lwpostgis.sql"),
+                     os.path.join(datadir3, "lwpostgis.sql"),
                     ]:
         if os.path.exists(filename):
             return filename

Added: trunk/thuban/test/test_mapservpostgis.py
===================================================================
--- trunk/thuban/test/test_mapservpostgis.py	2008-07-27 04:51:22 UTC (rev 2856)
+++ trunk/thuban/test/test_mapservpostgis.py	2008-07-27 05:30:28 UTC (rev 2857)
@@ -0,0 +1,60 @@
+import unittest
+import os, sys
+import support
+from Thuban.Model.layer import Layer
+from Thuban.Model.map import Map
+from Thuban.Model.session import Session
+from Thuban.UI.context import Context
+from Thuban.Lib.connector import ConnectorError
+
+from test_postgis_db import PostGISStaticTests
+from Thuban.Model.postgisdb import PostGISShapeStore
+
+mapscriptAvailable=True
+try:
+    import mapscript
+    from Extensions.umn_mapserver.mf_export import thuban_to_map
+    from Extensions.umn_mapserver.mapfile import MF_Map
+except ImportError:
+    mapscriptAvailable=False
+    
+
+class DummyMainWindow(object):
+    def __init__(self, canvas):
+        self.canvas = canvas
+
+class DummyCanvas(object):
+    def __init__(self, map):
+        self.map = map
+    def Map(self):
+        return self.map
+    def VisibleExtent (self):
+        return self.map.BoundingBox()
+
+class TestPostGISMFExport(PostGISStaticTests):
+    def setUp(self):
+        PostGISStaticTests.setUp(self)
+        self.store = PostGISShapeStore(self.db, "political_multi")
+
+    def testExport(self):
+        if not mapscriptAvailable:
+            raise support.SkipTest("Couldn't import mapscript module")
+        session = Session("A Session")
+        map = Map("A Map")
+        session.AddMap(map)
+        layer = Layer("PostGIS Layer", self.store)
+        map.AddLayer(layer)
+        mainwindow = DummyMainWindow(DummyCanvas(map))
+        context = Context(None, session, mainwindow)
+        mf = MF_Map(mapscript.mapObj(""))
+        mf.set_size (600, 500)
+        thuban_to_map (context, mf)
+        try:
+            map.Destroy()
+        except ConnectorError:
+            pass
+        session.Destroy()
+
+if __name__ == "__main__":
+    support.run_tests()
+



More information about the Thuban-commits mailing list