Saturday, 5 May 2018

open source gis - Spatial joins in OGR SQL



I have seen that OGR supports it's own form of SQL, I was wondering if it's possible to do spatial joins.


Something like select all objects where one intersects the other. I did have a look around but couldn't really see anything.



Answer



The OGR SQL is only for standard attribute queries, and not for spatial queries.


http://www.gdal.org/ogr/ogr_sql.html


The only geometry related queries that can be run are to query by area using the keyword OGR_GEOM_AREA


SELECT * FROM nation WHERE OGR_GEOM_AREA > 10000000'

If you run the OGR SQL against a datasource that is a database then the SQL query is executed using the database's own SQL implementation.


You can also pass in spatial queries directly to a geodatabase using the ExecuteSQL command on a OGRDataSource. This method also allows a bonding box to be passed in as a filter.



To do queries such as intersections with OGR you'd need to use the OGRGeometryClass. Personally I find it easier to use the opensource Shapely library for these types of query, or use the spatial queries in the underlying geodatabase (SQL Server, Oracle, PostGIS etc.)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...