Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

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

share|improve this answer
2  
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. –  geographika May 18 '11 at 7:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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