I have a shapefile containing polygons and a shapefile containing points. Now I would like to select the polygons that contain points.
How can I do this from the command line using
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
At the following link all SQL functions that test spatial relationships are described: http://www.gaia-gis.it/spatialite-2.4.0/spatialite-sql-2.4.html#p12.
The following spatial relationships can be used within a query
For this type of request you can do this using the
ST_Containts query of
Which can be adopted in a
ogr2ogr command as follows:
ogr2ogr -f "ESRI Shapefile" selection_polygon.shp shapefile_polygon.shp -dialect sqlite -sql "SELECT polygon.Geometry, polygon.id FROM shapefile_polygon polygon, 'shapefile_point.shp'.shapefile_point point WHERE ST_Contains(polygon.geometry, point.geometry) GROUP BY polygon.id"
And picture of
Expanded options of the spatial relationships:
ST_EqualsReturns true if the interior and the boundary of the two geometries are spatially equal
ST_DisjointReturns true if the boundaries and interior do not intersect
ST_TouchesReturns true if the boundaries intersect but the interiors do not
ST_WithinReturns true if the interior of the given geometry does not intersect with the exterior of another geometry
ST_OverlapsReturns true if the interiors of two geometries have non-empty intersection
ST_CrossesReturns true if the interiors of the geometries intersect but the boundaries do not
ST_IntersectsReturns true if the interiors of the geometries intersect
ST_ContainsTests if the given geometry contains another geometry
ST_RelateReturns true if this geometry is spatially related to another geometry