[Featureserver] [PATCH] Support for range selects
Stefan de Konink
stefan at konink.de
Tue Mar 22 18:37:32 EDT 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi,
I guess a month ago I annouced I made some patch. I hope someone can
review it, and maybe include it into the subversion repository. It tries
to implement range selects, but generally allows mulitple operations on
the same column. This allows someone to implement x > y and x < z.
It has been tested with PostGIS. But I approached the other backends in
the same way.
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEAREKAAYFAk2JJKsACgkQYH1+F2Rqwn0d0ACfcWOhwI7oP/uOWU0/glrB2FSM
pWcAoIzAMCHhcdn6HTVawsUsCE0K6Nq0
=uq9X
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: featureserver/FeatureServer/Service/__init__.py
===================================================================
--- featureserver/FeatureServer/Service/__init__.py (revision 629)
+++ featureserver/FeatureServer/Service/__init__.py (working copy)
@@ -134,7 +134,7 @@
elif key in queryable or key.upper() in queryable:
if type:
if type in ds.query_action_types:
- action.attributes[key] = {'type': type, 'value':value}
+ action.attributes[key+'__'+type] = {'column': key, 'type': type, 'value':value}
else:
raise ApplicationException("%s, %s, %s\nYou can't use %s on this layer. Available query action types are: \n%s" % (self, self.query_action_types, type,
type, ",".join(ds.query_action_types) or "None"))
Index: featureserver/FeatureServer/DataSource/PostGIS.py
===================================================================
--- featureserver/FeatureServer/DataSource/PostGIS.py (revision 629)
+++ featureserver/FeatureServer/DataSource/PostGIS.py (working copy)
@@ -84,13 +84,13 @@
# Special Query: pair[0] is 'a', pair[1] is {'type', 'pred', 'value'}
# We build a Predicate here, then we replace pair[1] with pair[1] value below
if pair[1].has_key('value'):
- predicates.append("%s %s %s" % (pair[0],
+ predicates.append("%s %s %s" % (pair[1]['column'],
self.query_action_sql[pair[1]['type']],
pair[1]['pred']))
else:
predicates.append("%s = %s" % pair)
- if feature.geometry.has_key("coordinates"):
- predicates.append(" %s = SetSRID('%s'::geometry, %s) " % (self.geom_col, WKT.to_wkt(feature.geometry), self.srid))
+ 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
def feature_values (self, feature):
Index: featureserver/FeatureServer/DataSource/GeoAlchemy.py
===================================================================
--- featureserver/FeatureServer/DataSource/GeoAlchemy.py (revision 629)
+++ featureserver/FeatureServer/DataSource/GeoAlchemy.py (working copy)
@@ -154,7 +154,7 @@
if action.attributes:
query = query.filter(
and_(
- *[self.feature_predicate(getattr(cls, k),
+ *[self.feature_predicate(v['column'],
v['type'], v['value'])
for k, v in action.attributes.iteritems()]
)
Index: featureserver/FeatureServer/DataSource/SQLite.py
===================================================================
--- featureserver/FeatureServer/DataSource/SQLite.py (revision 629)
+++ featureserver/FeatureServer/DataSource/SQLite.py (working copy)
@@ -210,14 +210,14 @@
if filters:
sql += "WHERE 1 "
for ii, (key, value) in enumerate(filters):
- select_dict['key%i' % ii] = key
if isinstance(value, dict):
-
+ select_dict['key%i' % ii] = value['column']
select_dict['value%i' % ii] = value['value']
sql += (" AND a.key = :key%i AND a.value " + self.query_action_sql[value['type']] + " :value%i") % (ii, ii)
else:
+ select_dict['key%i' % ii] = key
select_dict['value%i' % ii] = value
sql += " AND a.key = :key%i AND a.value = :value%i" % (ii, ii)
Index: featureserver/FeatureServer/DataSource/AppEngineGeoModel.py
===================================================================
--- featureserver/FeatureServer/DataSource/AppEngineGeoModel.py (revision 629)
+++ featureserver/FeatureServer/DataSource/AppEngineGeoModel.py (working copy)
@@ -99,7 +99,7 @@
current_key = None
for key, value in action.attributes.items():
if isinstance(value, dict):
- obj_list = obj_list.filter("%s %s" % (key, self.query_action_string[value['type']]), value['value'])
+ obj_list = obj_list.filter("%s %s" % (value['column'], self.query_action_string[value['type']]), value['value'])
else:
try: value = int(value)
except: pass
Index: featureserver/FeatureServer/DataSource/AppEngine.py
===================================================================
--- featureserver/FeatureServer/DataSource/AppEngine.py (revision 629)
+++ featureserver/FeatureServer/DataSource/AppEngine.py (working copy)
@@ -85,7 +85,7 @@
current_key = None
for key, value in action.attributes.items():
if isinstance(value, dict):
- obj_list.filter("%s %s" % (key, self.query_action_string[value['type']]), value['value'])
+ obj_list.filter("%s %s" % (value['column'], self.query_action_string[value['type']]), value['value'])
else:
obj_list.filter("%s =" % key, value)
return_list = []
More information about the Featureserver
mailing list