| 41 | |
| 42 | == Extend DAL to support Spatial Queries == |
| 43 | We need to support some extra SQL queries in DAL. |
| 44 | |
| 45 | I guess we have a PostGIS Adapter which inherits from the PostgreSQL one & a Spatialite adapter which inherits from the Sqlite one. |
| 46 | |
| 47 | Both should inherit the OpenGIS set of SQL syntax |
| 48 | |
| 49 | |
| 50 | We need to be able to do spatial queries like this: |
| 51 | * http://postgis.refractions.net/docs/ST_Overlaps.html |
| 52 | This one is our key performance bottleneck currently as we do BBOX filters on GeoJSON feature layers like this: |
| 53 | * http://bazaar.launchpad.net/~flavour/sahana-eden/trunk/view/head:/modules/s3/s3rest.py#L1773 |
| 54 | Instead of this query: |
| 55 | {{{ |
| 56 | bbox_filter = ((db.location.lon > minLon) & (db.location.lon < maxLon) & (db.location.lat > minLat) & (db.location.lat < maxLat)) |
| 57 | }}} |
| 58 | We want to: |
| 59 | {{{ |
| 60 | bbox_filter = (db.location.ST_Overlaps([minLon, minLat, maxLon, maxLat])) |
| 61 | }}} |
| 62 | |
| 63 | Full list of possible commands are here, but I don't expect all these to be implemented immediately (we can add additional ones as/when we need them if the hooks are right): |
| 64 | * http://postgis.refractions.net/documentation/manual-1.3/ch06.html#id2574404 |
| 65 | |
| 66 | |
| 67 | We could also want to be able to specify that a table is spatialised, so an option to db.define_table(spatial=True). |
| 68 | If this is on then we should send AddGeometryColumn() to the SQL Adapter |
| 69 | |
| 70 | NB A normal system would commonly only have a single spatial table, so this could be easily done out of band using a script, as I do now: |
| 71 | * wiki:InstallationGuidelinesPostgreSQL#AddGeometrycolumntogis_location |
| 72 | |
| 73 | |
| 74 | There are also some new field types, but I don't think we need to worry about those right now. |
| 75 | |
| 76 | Full specs are here: |
| 77 | * http://www.opengeospatial.org/standards/sfs |
| 78 | |