/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/wms/layer.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Extensions/wms/layer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/thuban/Extensions/wms/layer.py revision 2175 by joey, Thu Apr 15 07:13:31 2004 UTC branches/WIP-pyshapelib-bramz/Extensions/wms/layer.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 23  Graphic Layer via OGC WMS. Line 23  Graphic Layer via OGC WMS.
23  class WMSLayer:  class WMSLayer:
24      __init__()      __init__()
25    
26        LatLongBoundingBox()
27        BoundingBox()
28    
29        getFormat(format)
30        calcFormat(formats)
31    
32        getFormats()
33        getLayers()
34        getLayerTitle()
35    
36        getWMSFormat()
37        setWMSFormat(format)
38    
39        GetMapImg(width, height, bbox)
40    
41  Requirements:  Requirements:
42      - PyOGCLib <http://www.sourceforge.net/projects/pyogclib>      - PyOGCLib <http://www.sourceforge.net/projects/pyogclib>
# Line 66  def epsg_code_to_projection(epsg): Line 80  def epsg_code_to_projection(epsg):
80    
81    
82  class WMSLayer(BaseLayer):  class WMSLayer(BaseLayer):
83        """
84        WMS Layer
85    
86        This layer incorporates all methods from the Thuban BaseLayer and
87        adds specific methods for operating with a WMS server.
88        """
89    
90      def __init__(self, title, url):      def __init__(self, title, url):
91          """Initializes the WMSLayer.          """Initializes the WMSLayer.
# Line 81  class WMSLayer(BaseLayer): Line 101  class WMSLayer(BaseLayer):
101          self.bbox = None          self.bbox = None
102          self.latlonbbox = None          self.latlonbbox = None
103          self.error_msg = None          self.error_msg = None
104          self.layer_name = None          self.wms_layers = []
105          self.capabilities = None          self.capabilities = None
106    
107          # Change the cursor to demonstrate that we're busy but working          # Change the cursor to demonstrate that we're busy but working
# Line 96  class WMSLayer(BaseLayer): Line 116  class WMSLayer(BaseLayer):
116                                 '%s') % url                                 '%s') % url
117              return              return
118          top_layer = foo[0]          top_layer = foo[0]
119          self.layer_name = top_layer          self.wms_layers = [top_layer]
120    
121          # first projection of the top layer          # first projection of the top layer
122          foo = self.capabilities.getLayerSRS(top_layer)          foo = self.capabilities.getLayerSRS(top_layer)
# Line 147  class WMSLayer(BaseLayer): Line 167  class WMSLayer(BaseLayer):
167    
168    
169      def LatLongBoundingBox(self):      def LatLongBoundingBox(self):
170          """Return the layer's bounding box in lat-lon.          """
171            Return the layer's bounding box in lat-lon
172          """          """
173          return self.latlonbbox          return self.latlonbbox
174    
175    
176      def BoundingBox(self):      def BoundingBox(self):
177          """Return the layer's bounding box in the intrinsic coordinate system.          """
178            Return the layer's bounding box in the intrinsic coordinate system
179          """          """
180          return self.bbox          return self.bbox
181    
# Line 163  class WMSLayer(BaseLayer): Line 186  class WMSLayer(BaseLayer):
186    
187          format -- format as returned by the WMS server          format -- format as returned by the WMS server
188    
189          If no mapping was found, None is returned          If no mapping was found, None is returned.
190    
191            This routine uses a simple heuristic in order to find the
192            broken down image format to be used with the internal render
193            engine.
194    
195          An exception rule is implemented in order to not accept          An exception rule is implemented in order to not accept
196          image/wbmp or WBMP which refers to WAP bitmap format and is          image/wbmp or WBMP which refers to WAP bitmap format and is
# Line 202  class WMSLayer(BaseLayer): Line 229  class WMSLayer(BaseLayer):
229          image/wbmp or WBMP which refers to WAP bitmap format and is          image/wbmp or WBMP which refers to WAP bitmap format and is
230          not supported by the included render engine.          not supported by the included render engine.
231          """          """
232          prio = ['jpeg', 'bmp']          prio = ['png', 'gif', 'jpeg', 'bmp']
233          for p in prio:          for p in prio:
234              for f in formats:              for f in formats:
235                  if f.lower().find(p) > -1:                  if f.lower().find(p) > -1:
# Line 211  class WMSLayer(BaseLayer): Line 238  class WMSLayer(BaseLayer):
238          return None, None          return None, None
239                    
240    
241        def getFormats(self):
242            """
243            Return the list of supported image formats by the WMS server
244    
245            These formats may be used in the WMS GetMap request.  Data is
246            retrieved from the included WMSCapabilities object.
247    
248            The called method from WMSCapabilities will default to
249            'image/jpeg' if no format is recognised in XML Capabilities,
250            assuming that JPEG will always be supported on the server side
251            with this encoding.
252            """
253            return self.capabilities.getFormats()
254    
255    
256        def getLayers(self):
257            """
258            Return the list of layer names supported by the WMS server
259    
260            Data is retrieved from the included WMSCapabilities object.
261    
262            Only named layers will be returned, since a layer may have a
263            title but doesn't have to have a name associated to it as
264            well.  If no layers were found, an empty list is returned.
265            """
266            return self.capabilities.getLayers()
267    
268    
269        def getLayerTitle(self, layer):
270            """
271            Return the title of the named layer
272    
273            Data is retrieved from the included WMSCapabilities object.
274    
275            If no such title or no such layer exists, an empty string is
276            returned.
277            """
278            return self.capabilities.getLayerTitle(layer)
279    
280    
281        def getWMSFormat(self):
282            """
283            Return the image format that is used for WMS GetMap requests
284            """
285            return self.wmsformat
286    
287    
288        def setWMSFormat(self, format):
289            """
290            Set the image format that is used for WMS GetMap requests
291    
292            format -- format, one of getFormats()
293            """
294            self.wmsformat = format
295            self.format = self.getFormat(format)
296    
297    
298        def getVisibleLayers(self):
299            """
300            Return the list of names for all visible layers
301    
302            """
303            return self.wms_layers
304    
305    
306        def setVisibleLayers(self, layers):
307            """
308            Set the list of names for all visible layers
309    
310            """
311            self.wms_layers = layers
312    
313    
314      def GetMapImg(self, width, height, bbox):      def GetMapImg(self, width, height, bbox):
315            """
316            Retrieve a new map from the WMS server and return it
317    
318            width -- width in pixel of the desired image
319            height -- height in pixel of the desired image
320            bbox -- array of min(x,y) max(x,y) in the given SRS
321    
322            SRS and used image format will be retrieved from within the
323            layer itself.
324            """
325          bbox_dict = { 'minx': bbox[0], 'miny': bbox[1],          bbox_dict = { 'minx': bbox[0], 'miny': bbox[1],
326                        'maxx': bbox[2], 'maxy': bbox[3] }                        'maxx': bbox[2], 'maxy': bbox[3] }
327    
# Line 224  class WMSLayer(BaseLayer): Line 334  class WMSLayer(BaseLayer):
334    
335          wms_response = wmsclient.getMap(self.url, self.wmsformat, width, height,          wms_response = wmsclient.getMap(self.url, self.wmsformat, width, height,
336                                     epsg_id, bbox_dict,                                     epsg_id, bbox_dict,
337                                     [self.layer_name], version = self.capabilities.getVersion())                                     self.wms_layers, version = self.capabilities.getVersion())
338          ThubanEndBusyCursor()          ThubanEndBusyCursor()
339          return wms_response, self.format          return wms_response, self.format

Legend:
Removed from v.2175  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26