[Featureserver] Filter query on PostGIS layer crashes FS
Etienne Dube
etienne.dube at boreal-is.com
Thu Nov 11 17:11:48 EST 2010
Hi,
I've got a problem when querying a PostGIS datasource using a queryable
parameter to filter features by attributes. FeatureServer (got the
latest rev from svn) crashes with the following stack trace:
An error occurred: 'NoneType' object has no attribute 'has_key'
File
"C:\OSGeo4W\apache\htdocs\featureserver\web_request\handlers.py", line
219, in cgi
accepts = accepts )
File
"C:\OSGeo4W\apache\htdocs\featureserver\FeatureServer\Server.py", line
167, in dispatchRequest
result = method(action)
File
"C:\OSGeo4W\apache\htdocs\featureserver\FeatureServer\DataSource\PostGIS.py",
line 157, in select
filters = self.feature_predicates(match)
File
"C:\OSGeo4W\apache\htdocs\featureserver\FeatureServer\DataSource\PostGIS.py",
line 92, in feature_predicates
if feature.geometry.has_key("coordinates"):
It happens systematically; I think the problem could have been
introduced by a change to Feature.py in revision 618.
I've attached a patch for PostGIS.py that fixes the issue. It also adds
the "eq" operator to query_action_types and query_action_sql, to make it
work correctly with OpenLayers.Protocol.HTTP.
Regards,
--
Etienne Dubé
Developer
Boréal Informations Stratégiques
101, Du Moulin, bureau 202-A
Magog (Québec)
J1X 4A1
Tel. : 514.313.5951 #1131
Email: etienne.dube at boreal-is.com
-------------- next part --------------
Index: FeatureServer/DataSource/PostGIS.py
===================================================================
--- FeatureServer/DataSource/PostGIS.py (revision 629)
+++ FeatureServer/DataSource/PostGIS.py (working copy)
@@ -26,11 +26,12 @@
"""PostGIS datasource. Setting up the table is beyond the scope of
FeatureServer."""
- query_action_types = ['lt', 'gt', 'ilike', 'like', 'gte', 'lte']
+ query_action_types = ['lt', 'gt', 'ilike', 'like', 'gte', 'lte', 'eq']
query_action_sql = {'lt': '<', 'gt': '>',
'ilike': 'ilike', 'like':'like',
- 'gte': '>=', 'lte': '<='}
+ 'gte': '>=', 'lte': '<=',
+ 'eq': '='}
def __init__(self, name, srid = 4326, fid = "gid", geometry = "the_geom", order = "", attribute_cols = '*', writable = True, encoding = "utf-8", **args):
DataSource.__init__(self, name, **args)
@@ -89,7 +90,7 @@
pair[1]['pred']))
else:
predicates.append("%s = %s" % pair)
- if feature.geometry.has_key("coordinates"):
+ if feature.geometry and feature.geometry.has_key("coordinates"):
predicates.append(" %s = SetSRID('%s'::geometry, %s) " % (self.geom_col, WKT.to_wkt(feature.geometry), self.srid))
return predicates
More information about the Featureserver
mailing list