joey: thuban/Extensions/wms wms.py,1.7,1.8
cvs@intevation.de
cvs at intevation.de
Thu Apr 15 09:14:28 CEST 2004
Author: joey
Update of /thubanrepository/thuban/Extensions/wms
In directory doto:/tmp/cvs-serv27359
Modified Files:
wms.py
Log Message:
Moved the WMS layer into layer.py in order to establish a clean
structure.
Index: wms.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/wms/wms.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- wms.py 13 Apr 2004 17:38:26 -0000 1.7
+++ wms.py 15 Apr 2004 07:14:25 -0000 1.8
@@ -13,11 +13,6 @@
layer into Thuban via an extension.
Some things are not wired, so be prepared for Exceptions
everywhere.
-
-You will need PyOGCLib 0.1.0, see
- http://pyogclib.sourceforge.net/
-Set the PYTHONPATH to the PyOGCLib directory before
-starting Thuban.
"""
__version__ = "$Revision$"
@@ -28,204 +23,20 @@
from wxPython.wx import *
-from ogclib.WMSClient import WMSClient
-
-from Thuban.Model.layer import BaseLayer
from Thuban.Model.proj import Projection
from Thuban.Model.extension import Extension
-from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE, \
- EPSG_DEPRECATED_PROJ_FILE
from Thuban.UI.command import registry, Command
import Thuban.UI.mainwindow
-from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
from Thuban import _
import Thuban.UI.baserenderer
-from capabilities import WMSCapabilities
-
-def epsg_code_to_projection(epsg):
- """Find the projection for the given epsg code.
-
- epsg -- EPSG code as string
- """
- proj_file, warnings = get_system_proj_file(EPSG_PROJ_FILE)
+from layer import WMSLayer
- for proj in proj_file.GetProjections():
- if proj.EPSGCode() == epsg:
- return proj
- proj_file, warnings = get_system_proj_file(EPSG_DEPRECATED_PROJ_FILE)
- for proj in proj_file.GetProjections():
- if proj.EPSGCode() == epsg:
- return proj
- return None
class WMSExtension(Extension):
def TreeInfo(self):
return (_("Extension: %s") % self.title,
[ object.TreeInfo() for object in self.objects ])
-
-class WMSLayer(BaseLayer):
-
- def __init__(self, title, url):
- """Initializes the WMSLayer.
-
- title -- Title of this layer.
- url -- URL of the WMS-Server wich must contain '?'
-
- If an error occured, self.error_msg is a string describing
- the problem(s). Else, self.error_msg is None.
- """
- BaseLayer.__init__(self, title, visible = True, projection = None)
- self.url = url
- self.bbox = None
- self.latlonbbox = None
- self.error_msg = None
- self.layer_name = None
- self.capabilities = None
-
- # Change the cursor to demonstrate that we're busy but working
- ThubanBeginBusyCursor()
- self.capabilities = WMSCapabilities(url)
- ThubanEndBusyCursor()
-
- # name of the top layer of the remote map
- foo = self.capabilities.getLayers()
- if len(foo) == 0:
- self.error_msg = _('No layers found in remote resource:\n'\
- '%s') % url
- return
- top_layer = foo[0]
- self.layer_name = top_layer
-
- # first projection of the top layer
- foo = self.capabilities.getLayerSRS(top_layer)
- if len(foo) == 0:
- self.error_msg = _('No LatLonBoundingBox found for top layer %s')\
- % top_layer
- return
- top_srs = foo[0]
-
- # 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:')\
- % (top_layer, top_srs)
- return
- self.bbox = (float(bbox['minx']),
- float(bbox['miny']),
- float(bbox['maxx']),
- float(bbox['maxy']))
-
- # 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']))
-
- # get projection
- p = epsg_code_to_projection(top_srs)
- self.SetProjection(p)
-
- if p is None:
- self.error_msg = _('EPSG projection code %s not found!\n'\
- 'Setting projection to "None".\n'\
- 'Please set an appropriate projection yourself.'\
- % top_srs)
-
- # pre-determine the used format
- self.wmsformat, self.format = \
- self.calcFormat(self.capabilities.getFormats())
- if self.wmsformat is None:
- self.error_msg = \
- _('No supported image format found in remote resource')
- return
-
- # get and set the title
- self.SetTitle(self.capabilities.getTitle().encode('latin1', 'replace'))
-
-
- def LatLongBoundingBox(self):
- """Return the layer's bounding box in lat-lon.
- """
- return self.latlonbbox
-
- def BoundingBox(self):
- """Return the layer's bounding box in the intrinsic coordinate system.
- """
- return self.bbox
-
-
- def getFormat(self, format):
- """
- Return the image format for the render engine
-
- format -- format as returned by the WMS server
-
- If no mapping was found, None is returned
-
- An exception rule is implemented in order to not accept
- image/wbmp or WBMP which refers to WAP bitmap format and is
- not supported by the included render engine.
- """
- fmap = {'png' : "PNG",
- 'jpeg': "JPEG",
- 'jpg' : "JPEG",
- 'tif' : "TIFF",
- 'gif' : "GIF",
- 'wbmp': None,
- 'bmp' : "BMP"}
-
- for f in fmap.keys():
- if format.lower().find(f) > -1:
- return fmap[f]
- return None
-
-
- def calcFormat(self, formats):
- """
- Calculate the preferred image format
-
- formats -- list of formates as returned by the WMS server
-
- The following priority is used:
- - PNG
- - JPEG
- - TIFF
- - GIF
- - BMP
-
- If no matching format was found, None, None will be returned.
-
- An exception rule is implemented in order to not accept
- image/wbmp or WBMP which refers to WAP bitmap format and is
- not supported by the included render engine.
- """
- prio = ['jpeg', 'bmp']
- for p in prio:
- for f in formats:
- if f.lower().find(p) > -1:
- if f.lower().find('wbmp') == -1:
- return f, self.getFormat(f)
- return None, None
-
-
- def GetMapImg(self, width, height, bbox):
- bbox_dict = { 'minx': bbox[0], 'miny': bbox[1],
- 'maxx': bbox[2], 'maxy': bbox[3] }
-
- # 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.layer_name], version = self.capabilities.getVersion())
- ThubanEndBusyCursor()
- return wms_response, self.format
def render_wms_layer(renderer, layer):
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)