[Thuban-commits] r2844 - in trunk/thuban: . Extensions/wms

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 19 10:18:48 CEST 2008


Author: dpinte
Date: 2008-06-19 10:18:46 +0200 (Thu, 19 Jun 2008)
New Revision: 2844

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/Extensions/wms/__init__.py
   trunk/thuban/Extensions/wms/layer.py
   trunk/thuban/Extensions/wms/wms.py
Log:
2008-06-19  Didrik Pinte <dpinte at dipole-consulting.com>
    * Extension/wms/__init__.py, wms.py, layer.py : wms extension has been
    update to use owslib 0.3. Extension is not stable but usable.



Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2008-06-03 09:13:39 UTC (rev 2843)
+++ trunk/thuban/ChangeLog	2008-06-19 08:18:46 UTC (rev 2844)
@@ -1,3 +1,7 @@
+2008-06-19  Didrik Pinte <dpinte at dipole-consulting.com>
+	* Extension/wms/__init__.py, wms.py, layer.py : wms extension has been
+	update to use owslib 0.3. Extension is not stable but usable.
+
 2008-06-03  Bernhard Reiter <bernhard at intevation.de>
 
 	* test/test_baserenderer.py, testtest_layer.py: Give the

Modified: trunk/thuban/Extensions/wms/__init__.py
===================================================================
--- trunk/thuban/Extensions/wms/__init__.py	2008-06-03 09:13:39 UTC (rev 2843)
+++ trunk/thuban/Extensions/wms/__init__.py	2008-06-19 08:18:46 UTC (rev 2844)
@@ -9,9 +9,9 @@
 # of the PyOGCLib.
 ok = True
 try:
-    import ogclib.WMSClient
+    import owslib
 except:
-    print "Problems with PyOGCLib (not installed?)"
+    print "Problems with OWSLib (not installed?)"
     ok = False
 
 if ok:
@@ -22,7 +22,7 @@
 
     ext_registry.add(ExtensionDesc(
         name = 'WMS',
-        version = '0.2.0',
-        authors= [ 'Jan-Oliver Wagner', 'Martin Schulze' ],
-        copyright = '2003, 2004 Intevation GmbH',
+        version = '0.3.0',
+        authors= [ 'Didrik Pinte', 'Jan-Oliver Wagner', 'Martin Schulze' ],
+        copyright = '2008 Dipole Consulting SPRL - 2003, 2004 Intevation GmbH',
         desc = _("Provide layers via OGC WMS.")))

Modified: trunk/thuban/Extensions/wms/layer.py
===================================================================
--- trunk/thuban/Extensions/wms/layer.py	2008-06-03 09:13:39 UTC (rev 2843)
+++ trunk/thuban/Extensions/wms/layer.py	2008-06-19 08:18:46 UTC (rev 2844)
@@ -1,5 +1,7 @@
 # Copyright (c) 2003, 2004, 2007 by Intevation GmbH
+# Copyright (c) 2008 by Dipole Consulting SPRL
 # Authors:
+# Didrik Pinte <dpinte at dipole-consulting.com>
 # Jan-Oliver Wagner <jan at intevation.de>
 # Martin Schulze <joey at infodrom.org>
 #
@@ -39,10 +41,10 @@
     GetMapImg(width, height, bbox)
 
 Requirements:
-    - PyOGCLib <http://www.sourceforge.net/projects/pyogclib>
+    - OWSLib <http://trac.gispython.org/projects/PCL/wiki/OwsLib>
 
-Requires the ogclib installed regularily on the system or checked out
-next to the Thuban checkout.  Or set the PYTHONPATH to the PyOGCLib
+Requires the owslib installed regularily on the system or checked out
+next to the Thuban checkout.  Or set the PYTHONPATH to the OWSLib
 directory before starting Thuban.
 
 """
@@ -52,17 +54,14 @@
 # $Id$
 
 
-from Thuban import internal_from_unicode
+from Thuban import internal_from_unicode, _
 from Thuban.Model.layer import BaseLayer
 from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE, \
      EPSG_DEPRECATED_PROJ_FILE
 from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
 
-from capabilities import WMSCapabilities
+from owslib.wms import WebMapService
 
-from ogclib.WMSClient import WMSClient
-
-
 def epsg_code_to_projection(epsg):
     """Find the projection for the given epsg code.
 
@@ -107,11 +106,12 @@
 
         # Change the cursor to demonstrate that we're busy but working
         ThubanBeginBusyCursor()
-        self.capabilities = WMSCapabilities(url)
+        self.wmsserver = WebMapService(url, version="1.1.1")
+        self.capabilities = [op.name for op in self.wmsserver.operations]
         ThubanEndBusyCursor()
 
         # name of the top layer of the remote map
-        foo = self.capabilities.getLayers()
+        foo = list(self.wmsserver.contents)                   
         if len(foo) == 0:
             self.error_msg = _('No layers found in remote resource:\n'\
                                '%s') % url
@@ -120,30 +120,33 @@
         self.wms_layers = [top_layer]
 
         # first projection of the top layer
-        foo = self.capabilities.getLayerSRS(top_layer)
+        foo = self.wmsserver[top_layer].crsOptions
         if len(foo) == 0:
             self.error_msg = _('No LatLonBoundingBox found for top layer %s')\
                              % top_layer
             return
-        top_srs = foo[0]
+        top_srs = foo[0][foo[0].index(":")+1:]
 
         # BoundingBox of the top layer
-        bbox = self.capabilities.getLayerBBox(top_layer, top_srs)
-        if len(bbox) == 0:
-            self.error_msg = _('No BoundingBox found for layer %s and EPSG:')\
+        bbox = self.wmsserver[top_layer].boundingBox
+        if bbox is None or len(bbox) == 0:
+            self.error_msg = _('No BoundingBox found for layer %s and EPSG %s')\
                              % (top_layer, top_srs)
-            return
-        self.bbox = (float(bbox['minx']),
-                     float(bbox['miny']),
-                     float(bbox['maxx']),
-                     float(bbox['maxy']))
+            self.bbox = None
+        else :
+            self.bbox = (float(bbox[0]),
+                     float(bbox[1]),
+                     float(bbox[2]),
+                     float(bbox[3]))
 
         # LatLonBox of the top layer
-        bbox = self.capabilities.getLayerLatLonBBox(top_layer)
-        self.latlonbbox = (float(bbox['minx']),
-                           float(bbox['miny']),
-                           float(bbox['maxx']),
-                           float(bbox['maxy']))
+        bbox = self.wmsserver[top_layer].boundingBoxWGS84
+        self.latlonbbox = (float(bbox[0]),
+                     float(bbox[1]),
+                     float(bbox[2]),
+                     float(bbox[3]))
+        if self.bbox is None:
+            self.bbox =self.latlonbbox
 
         # get projection
         p = epsg_code_to_projection(top_srs)
@@ -157,14 +160,14 @@
 
         # pre-determine the used format
         self.wmsformat, self.format = \
-            self.calcFormat(self.capabilities.getFormats())
+        self.calcFormat(self.wmsserver.getOperationByName('GetMap').formatOptions)
         if self.wmsformat is None:
             self.error_msg = \
                 _('No supported image format found in remote resource')
             return
 
         # get and set the title
-        self.SetTitle(internal_from_unicode(self.capabilities.getTitle()))
+        self.SetTitle(internal_from_unicode(self.wmsserver.identification.title))
 
 
     def LatLongBoundingBox(self):
@@ -251,7 +254,7 @@
         assuming that JPEG will always be supported on the server side
         with this encoding.
         """
-        return self.capabilities.getFormats()
+        return self.wmsserver.getOperationByName('GetMap').formatOptions
 
 
     def getLayers(self):
@@ -264,7 +267,7 @@
         title but doesn't have to have a name associated to it as
         well.  If no layers were found, an empty list is returned.
         """
-        return self.capabilities.getLayers()
+        return list(self.wmsserver.contents)
 
 
     def getLayerTitle(self, layer):
@@ -276,7 +279,7 @@
         If no such title or no such layer exists, an empty string is
         returned.
         """
-        return self.capabilities.getLayerTitle(layer)
+        return self.wmsserver[layer].title
 
 
     def getWMSFormat(self):
@@ -329,12 +332,15 @@
         # Change the cursor to demonstrate that we're busy but working
         ThubanBeginBusyCursor()
 
-        wmsclient = WMSClient()
-
         epsg_id = int(self.GetProjection().EPSGCode())
 
-        wms_response = wmsclient.getMap(self.url, self.wmsformat, width, height,
-                                   epsg_id, bbox_dict,
-                                   self.wms_layers, version = self.capabilities.getVersion())
+        wms_response = self.wmsserver.getmap(layers=self.wms_layers, 
+                                             styles=None, 
+                                             srs="EPSG:%s" % epsg_id, 
+                                             bbox=bbox, 
+                                             size=(width, height), 
+                                             format=self.wmsformat, 
+                                             transparent=True)
         ThubanEndBusyCursor()
-        return wms_response, self.format
+        
+        return wms_response.read() , self.format

Modified: trunk/thuban/Extensions/wms/wms.py
===================================================================
--- trunk/thuban/Extensions/wms/wms.py	2008-06-03 09:13:39 UTC (rev 2843)
+++ trunk/thuban/Extensions/wms/wms.py	2008-06-19 08:18:46 UTC (rev 2844)
@@ -1,5 +1,7 @@
 # Copyright (C) 2003, 2004 by Intevation GmbH
+# Copyright (C) 2008 by Dipole Consulting SPRL
 # Authors:
+# Didrik Pinte <dpinte at dipole-consulting.com> (2008)
 # Jan-Oliver Wagner <jan at intevation.de> (2003, 2004)
 # Bernhard Herzog <bh at intevation.de> (2004)
 # Martin Schulze <joey at infodrom.org> (2004)
@@ -9,12 +11,6 @@
 
 """
 Provide layers via OGC WMS.
-
-This extension is in a very experimental stage!
-It just demonstrates how to add a special
-layer into Thuban via an extension.
-Some things are not wired, so be prepared for Exceptions
-everywhere.
 """
 
 __version__ = "$Revision$"
@@ -78,8 +74,8 @@
 
         self.combo_value = wx.ComboBox(self, self.ID_COMBOVALUE, size=(500,-1))
         self.combo_value.Append("")
-        self.combo_value.Append('http://demo.intevation.org/cgi-bin/frida-wms?')
-        self.combo_value.Append('http://wms.jpl.nasa.gov/wms.cgi?')
+        self.combo_value.Append('http://demo.intevation.org/cgi-bin/frida-wms')
+        self.combo_value.Append('http://wms.jpl.nasa.gov/wms.cgi')
         self.combo_value.SetSelection(0)
 
         button_ok = wx.Button(self, wx.ID_OK, _("OK"))



More information about the Thuban-commits mailing list