OGCServer: add support for load_map() within WMSFactory (thanks xcacou,theosys,and tmcw for early patches) (closes #129)
This commit is contained in:
parent
577ee5ee22
commit
be2c27ff86
2 changed files with 31 additions and 5 deletions
|
@ -13,6 +13,9 @@ For a complete change history, see the SVN log.
|
||||||
|
|
||||||
Current Version (0.6.0-dev, SVN trunk):
|
Current Version (0.6.0-dev, SVN trunk):
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
- OGCServer: Added support for load_map(), allowing reading of XML styles and layers (r901)
|
||||||
|
|
||||||
- OGCServer: Enabled friendly html output when in debug mode (debug=1 in ogcserver.conf) (r899)
|
- OGCServer: Enabled friendly html output when in debug mode (debug=1 in ogcserver.conf) (r899)
|
||||||
|
|
||||||
- Filter parsing: Allow numbers in the filter field name.
|
- Filter parsing: Allow numbers in the filter field name.
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
from common import Version
|
from common import Version, copy
|
||||||
from exceptions import OGCException, ServerConfigurationError
|
from exceptions import OGCException, ServerConfigurationError
|
||||||
from wms111 import ServiceHandler as ServiceHandler111
|
from wms111 import ServiceHandler as ServiceHandler111
|
||||||
from wms130 import ServiceHandler as ServiceHandler130
|
from wms130 import ServiceHandler as ServiceHandler130
|
||||||
from mapnik import Style, Layer
|
from mapnik import Style, Map, load_map
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def ServiceHandlerFactory(conf, mapfactory, onlineresource, version):
|
def ServiceHandlerFactory(conf, mapfactory, onlineresource, version):
|
||||||
|
@ -43,11 +43,34 @@ class BaseWMSFactory:
|
||||||
self.styles = {}
|
self.styles = {}
|
||||||
self.aggregatestyles = {}
|
self.aggregatestyles = {}
|
||||||
|
|
||||||
|
def loadXML(self, xmlfile, strict=False):
|
||||||
|
tmp_map = Map(0,0)
|
||||||
|
load_map (tmp_map, xmlfile, strict)
|
||||||
|
for lyr in tmp_map.layers:
|
||||||
|
style_count = len(lyr.styles)
|
||||||
|
if style_count == 0:
|
||||||
|
raise ServerConfigurationError("Cannot register Layer '%s' without a style" % lyr.name)
|
||||||
|
elif style_count == 1:
|
||||||
|
style_obj = tmp_map.find_style(lyr.styles[0])
|
||||||
|
style_name = lyr.styles[0]
|
||||||
|
if style_name not in self.aggregatestyles.keys() and style_name not in self.styles.keys():
|
||||||
|
self.register_style(style_name, copy(style_obj))
|
||||||
|
self.register_layer(copy(lyr), style_name, extrastyles=(style_name,))
|
||||||
|
elif style_count > 1:
|
||||||
|
for style_name in lyr.styles:
|
||||||
|
style_obj = tmp_map.find_style(style_name)
|
||||||
|
self.register_style(style_name, copy(style_obj))
|
||||||
|
del style_obj
|
||||||
|
aggregates = tuple([sty for sty in lyr.styles])
|
||||||
|
aggregates_name = '%s_aggregates' % lyr.name
|
||||||
|
self.register_aggregate_style(aggregates_name,aggregates)
|
||||||
|
self.register_layer(copy(lyr), aggregates_name, extrastyles=aggregates)
|
||||||
|
|
||||||
def register_layer(self, layer, defaultstyle, extrastyles=()):
|
def register_layer(self, layer, defaultstyle, extrastyles=()):
|
||||||
layername = layer.name
|
layername = layer.name
|
||||||
if not layername:
|
if not layername:
|
||||||
raise ServerConfigurationError('Attempted to register an unnamed layer.')
|
raise ServerConfigurationError('Attempted to register an unnamed layer.')
|
||||||
if not re.match('^\+init=epsg:\d+$', layer.srs):
|
if not re.match('^\+init=epsg:\d+$', layer.srs) and not re.match('^\+proj=.*$', layer.srs):
|
||||||
raise ServerConfigurationError('Attempted to register a layer without an epsg projection defined.')
|
raise ServerConfigurationError('Attempted to register a layer without an epsg projection defined.')
|
||||||
if defaultstyle not in self.styles.keys() + self.aggregatestyles.keys():
|
if defaultstyle not in self.styles.keys() + self.aggregatestyles.keys():
|
||||||
raise ServerConfigurationError('Attempted to register a layer with an non-existent default style.')
|
raise ServerConfigurationError('Attempted to register a layer with an non-existent default style.')
|
||||||
|
@ -68,7 +91,7 @@ class BaseWMSFactory:
|
||||||
if not name:
|
if not name:
|
||||||
raise ServerConfigurationError('Attempted to register a style without providing a name.')
|
raise ServerConfigurationError('Attempted to register a style without providing a name.')
|
||||||
if name in self.aggregatestyles.keys() or name in self.styles.keys():
|
if name in self.aggregatestyles.keys() or name in self.styles.keys():
|
||||||
raise ServerConfigurationError('Attempted to register an aggregate style with a name already in use.')
|
raise ServerConfigurationError("Attempted to register a style with a name already in use: '%s'" % name)
|
||||||
if not isinstance(style, Style):
|
if not isinstance(style, Style):
|
||||||
raise ServerConfigurationError('Bad style object passed to register_style() for style "%s".' % name)
|
raise ServerConfigurationError('Bad style object passed to register_style() for style "%s".' % name)
|
||||||
self.styles[name] = style
|
self.styles[name] = style
|
||||||
|
@ -92,4 +115,4 @@ class BaseWMSFactory:
|
||||||
for layer in self.layers.values():
|
for layer in self.layers.values():
|
||||||
for style in list(layer.styles) + list(layer.wmsextrastyles):
|
for style in list(layer.styles) + list(layer.wmsextrastyles):
|
||||||
if style not in self.styles.keys() + self.aggregatestyles.keys():
|
if style not in self.styles.keys() + self.aggregatestyles.keys():
|
||||||
raise ServerConfigurationError('Layer "%s" refers to undefined style "%s".' % (layer.name(), style))
|
raise ServerConfigurationError('Layer "%s" refers to undefined style "%s".' % (layer.name, style))
|
Loading…
Reference in a new issue