Support xml lib fallback and GetFeatureInfo on all layers - closes #303 and #304

This commit is contained in:
Dane Springmeyer 2009-04-09 18:40:39 +00:00
parent c9a9fcf287
commit 82c6e87578
4 changed files with 49 additions and 16 deletions

View file

@ -14,11 +14,13 @@ For a complete change history, see the SVN log.
0.6.1 SVN
---------
- OGCServer: Made lxml dependency optional (r986) (#303)
- Rasters: Handle rounding to allow better alignment of raster layers (r1079) (#295)
- AGG Renderer: Added option to control output JPEG quality (r1078) (#198)
- Plugins: Fixed segfault in OGC Plugin with empty geometries (r1074) (#292)
- Plugins: Fixed segfault in OGR Plugin with empty geometries (r1074) (#292)

View file

@ -29,9 +29,16 @@ from StringIO import StringIO
from copy import deepcopy
from traceback import format_exception, format_exception_only
from sys import exc_info
from lxml import etree as ElementTree
import re
import sys
try:
from lxml import etree as ElementTree
except ImportError:
import xml.etree.ElementTree as ElementTree
except ImportError:
import elementtree.ElementTree as ElementTree
# from elementtree import ElementTree
# ElementTree._namespace_map.update({'http://www.opengis.net/wms': 'wms',
# 'http://www.opengis.net/ogc': 'ogc',
@ -316,22 +323,34 @@ class WMSBaseServiceHandler(BaseServiceHandler):
writer = TextFeatureInfo()
elif params['info_format'] == 'text/xml':
writer = XMLFeatureInfo()
for layerindex, layername in enumerate(params['query_layers']):
if layername in params['layers']:
if m.layers[layerindex].queryable:
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
if featureset:
writer.addlayer(m.layers[layerindex].name)
if params['query_layers'] and params['query_layers'][0] == '__all__':
for layerindex, layer in enumerate(m.layers):
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
if featureset:
writer.addlayer(layer.name)
feat = featureset.next()
while feat:
writer.addfeature()
for prop in feat.properties:
writer.addattribute(prop[0], prop[1])
feat = featureset.next()
else:
for layerindex, layername in enumerate(params['query_layers']):
if layername in params['layers']:
if m.layers[layerindex].queryable:
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
if featureset:
writer.addlayer(m.layers[layerindex].name)
feat = featureset.next()
while feat:
writer.addfeature()
for prop in feat.properties:
writer.addattribute(prop[0], prop[1])
feat = featureset.next()
else:
raise OGCException('Requested query layer "%s" is not marked queryable.' % layername, 'LayerNotQueryable')
else:
raise OGCException('Requested query layer "%s" is not marked queryable.' % layername, 'LayerNotQueryable')
else:
raise OGCException('Requested query layer "%s" not in the LAYERS parameter.' % layername)
raise OGCException('Requested query layer "%s" not in the LAYERS parameter.' % layername)
return Response(params['info_format'], str(writer))
def _buildMap(self, params):
@ -476,10 +495,10 @@ class TextFeatureInfo:
self.buffer = ''
def addlayer(self, name):
self.buffer += '[%s]\n' % name
self.buffer += '\n[%s]\n' % name
def addfeature(self):
self.buffer += '\n'
pass#self.buffer += '\n'
def addattribute(self, name, value):
self.buffer += '%s=%s\n' % (name, str(value))
@ -513,7 +532,7 @@ class XMLFeatureInfo:
attname = ElementTree.Element('name')
attname.text = name
attvalue = ElementTree.Element('value')
attvalue.text = value.unicode()
attvalue.text = unicode(value)
attribute.append(attname)
attribute.append(attvalue)
self.currentfeature.append(attribute)

View file

@ -25,9 +25,15 @@ from common import ParameterDefinition, Response, Version, ListFactory, \
ColorFactory, CRSFactory, WMSBaseServiceHandler, CRS, \
BaseExceptionHandler, Projection
from exceptions import OGCException, ServerConfigurationError
from lxml import etree as ElementTree
from mapnik import Coord
try:
from lxml import etree as ElementTree
except ImportError:
import xml.etree.ElementTree as ElementTree
except ImportError:
import elementtree.ElementTree as ElementTree
class ServiceHandler(WMSBaseServiceHandler):
SERVICE_PARAMS = {

View file

@ -25,9 +25,15 @@ from common import ParameterDefinition, Response, Version, ListFactory, \
ColorFactory, CRSFactory, CRS, WMSBaseServiceHandler, \
BaseExceptionHandler, Projection, Envelope
from exceptions import OGCException, ServerConfigurationError
from lxml import etree as ElementTree
from mapnik import Coord
try:
from lxml import etree as ElementTree
except ImportError:
import xml.etree.ElementTree as ElementTree
except ImportError:
import elementtree.ElementTree as ElementTree
class ServiceHandler(WMSBaseServiceHandler):
SERVICE_PARAMS = {