[gdal-dev] org2org select points within a polygon

Paul Higgins phigginsca at yahoo.com
Sat Sep 19 12:41:17 PDT 2020

I want have some points and I want to find out if they are in a polygon.
I have two shape files one defining a polygon and the other two points here are the csv files for  both and the vrt files:
My_Polygon.csv:ID,WKT1,"POLYGON ((1 1, 4 1, 4 3, 1 3, 1 1))"
My_points.csv:ID X Y1 2 22 0 1
My_Polygon.vrt:<OGRVRTDataSource>  <OGRVRTLayer name="My_Polygon"> <SrcDataSource relativeToVRT="1">My_polygon.csv</SrcDataSource> <GeometryType>wkbPolygon</GeometryType> <GeometryField encoding="WKT" field="WKT"/> </OGRVRTLayer></OGRVRTDataSource>
My_Points.vrt:<OGRVRTDataSource>    <OGRVRTLayer name="My_Points"> <SrcDataSource relativeToVRT="1">My_points.csv</SrcDataSource> <GeometryType>wkbPoint</GeometryType> <GeometryField encoding="PointFromColumns" x="X" y="Y"/> </OGRVRTLayer></OGRVRTDataSource>
I created the two shape files with:ogr2ogr -f "ESRI Shapefile" My_Polygon.shp My_Polygon.vrt  
ogr2ogr -f "ESRI Shapefile" My_Points.shp My_Points.vrt  

If I use the following org2org command I can select the polygon that has one of the points and it works fine:
ogr2ogr -f "ESRI Shapefile" selection.shp My_Polygon.shp -dialect sqlite -sql "SELECT polygon.Geometry, polygon.id FROM My_Polygon polygon, 'My_Points.shp'.My_Points point WHERE ST_Contains(polygon.geometry, point.geometry)"

But I want an org2org command that will select which points are in the polygon and can't seem to to do it. I tried:
ogr2ogr -f "ESRI Shapefile" selectpts.shp My_Points.shp -dialect sqlite -sql "SELECT point.Geometry, point.id FROM My_Points, 'My_Polygon.shp'.My_Polygon polygon WHERE ST_Contains(point.Geometry,polygon.geometry)"

But it gets an error:ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT point.Geometry, point.id FROM My_Points, "_OGR_1" polygon WHERE ST_Contains(point.Geometry,polygon.geometry)):  no such column: point.Geometry
Can anyone tell me the correct org2org command to select the points within the polygon?  Thanks,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200919/ba05cac0/attachment.html>

More information about the gdal-dev mailing list