I have two shapefiles, a polygon shapefile (lake) and a line shapefile (boudary) I want to create a new shapefile containing the polygon splitted by the polyline using ogr2ogr.
2 Answers
If we have GDAL OGR with Spatialite support and liblwgeom (e.g. OSGeo4W):
ogr2ogr splitted_lake.shp lake.shp -dialect sqlite -sql "SELECT ST_Split(g1.geometry,g2.geometry) AS geometry FROM lake AS g1, 'boundary.shp'.'boundary' AS g2" -explodecollections - Hmm, two input files. Seems one must use a VRT file: gis.stackexchange.com/questions/72294/…Dan Jacobson– Dan Jacobson2024-10-07 03:05:49 +00:00Commented Oct 7, 2024 at 3:05
After an hour of trying to understand the ST_Split approach, I instead simply by hand extended the boundary to wrap around the back side of the half (of "F") I wanted, making a closed clipping polygon "A", and then used the documented ogr2ogr -clip* options. In fact I was so happy I did it again ("B").
(I added arrows else as the labels are on the centers, and the centers are beyond the edges, it looks odd.)


