0

Can ogr2ogr be used to convert a polygon to a point but the point must remain inside the polygon? It does not matter where the point is as long as it is inside the object polygon.

1

This is covered in Convert Polygon Feature Centroid to Points using Python, but if you don't know the SpatialLite operators it might not be clear which of the answers to use. ST_Centroid returns the centroid, which may not be located in the shape. ST_PointOnSurface returns a point that will always be somewhere inside in the shape.

cd path/to/shapefiles
ogr2ogr -sql "SELECT ST_PointOnSurface(geometry), * FROM countries" -dialect sqlite countries_centroid.shp countries.shp

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.