[gdal-dev] Split polygon by a linestring to get two polygons

Jukka Rahkonen jukka.rahkonen at mmmtike.fi
Wed Sep 17 13:27:09 PDT 2014


Max Demars <burton449geo <at> gmail.com> writes:


> Hi,
> I am scratching my head to find a way to split a polygon geometry by a
linestring without success. Anybody has found a workaround as function such
postgis ST_Split is not implemented in ogr geometry yet?
> Thank you for your help,
> -Max Demars

Hi,

It should be possible do with SQLite SQL dialect if GDAL is built with fresh
enough Spatialite and Spatialite is built with LWGEOM. Spatialite has
functions Split, SplitLeft and SplitRight
http://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html. 

For testing the syntax create a dummy shapefile "test.shp" and try the
following which should work with quite old Spatialite version.

ogrinfo test.shp -sql "select buffer(geomfromtext('POINT (100 100)'),10)"
-dialect sqlite

Similarly this should do split if the Spatialite version supports it:
ogrinfo test.shp -sql "select split(geomfromtext('POLYGON (( 126 178, 187
254, 289 185, 126 178 ))'),geomfromtext('LINESTRING ( 189 13
5, 244 272 )'))" -dialect sqlite

The gisinternals.com Windows builds do not support the latter.
Spatialite-gui 1.7.0 with Spatialite v. 4.1 does support it so build GDAL
with the current Spatialite v. 4.2 and I believe that you will have your
splitter.

-Jukka Rahkonen-



More information about the gdal-dev mailing list