1

I have shapefile with lines, and another with polygons. I want to generate an output of those lines that are not covered by any polygon.

I can perfectly do this in QGIS's Difference tool, but want to do it with og2ogr.

I tried to do it, using the following command:

ogr2ogr -overwrite out.shp line.shp -dialect SQLite -sql "select st_difference(a.geometry, b.geometry) as geometry from line as a, 'polygon.shp'.polygon as b"

But it just generated a .dbf file.

This behaviour has also been reported here: https://gis.stackexchange.com/a/324837/442

Vince
  • 20,017
  • 15
  • 45
  • 64
Devdatta Tengshe
  • 41,311
  • 35
  • 139
  • 263

1 Answers1

1

GDAL has a new script for Algebraic operations on Vectors called ogr_layer_algebra.py which can be used instead.

An equivalent command would be:

ogr_layer_algebra.py ERASE -input_ds line.shp -method_ds polygon.shp -output_ds output.shp

Do note that is available only in newer versions (3.6 +) of GDAL.

Devdatta Tengshe
  • 41,311
  • 35
  • 139
  • 263
  • It is exactly not so new script, it was already mentioned in one of the answers https://gis.stackexchange.com/questions/298855/ogr2ogr-differencing-vector-layer/324837 four years ago. But the script is easier to find nowadays, earlier users could get it only directly from GitHub. – user30184 May 10 '23 at 08:53