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.


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


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.)

  • 3
    ogr2ogr has a spatial query option, -spat xmin ymin xmax ymax. The input extent can only be a rectangle.
    – klewis
    May 17 '11 at 20:24
  • @klewis - I've updated the answer to mention the use of ExecuteSQL which could be used to run spatial queries directly on a DBMS or further filter records by bounding box. May 18 '11 at 7:13
  • What about spatialthoughts.com/blog/gis/ogr-spatial-join
    – Benjamin
    Feb 9 '17 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.