Is there a means in ogr2ogr to "clip out" one shapefile from another?

I know ogr2ogr -clipsrc B.shp out.shp A.shp will remove any part of A.shp that is NOT in B.shp.

Is there an ogr2ogr command to remove any part of A.shp that intersects with B.shp?

I have seen this called "reverse clip", "clip out", "erase" (ArcMap), or "difference".

Note: this question is about ogr2ogr, the command line tool, NOT the OGR library, which requires programming.

  • Is your copy of GDAL compiled with sqlite/spatialite support? – SaultDon Apr 1 '16 at 18:57
  • I don't believe so. – Tom West Apr 2 '16 at 20:28

Using GDAL >= 1.10.0 compiled with SQLite and SpatiaLite:

ogr2ogr difference.shp a.shp -dialect SQLite -sql "SELECT ST_Difference(a.geometry, b.geometry) AS geometry FROM a, 'b.shp'.b"
  • 2
    It doesn't work in my case ogr2ogr -f "ESRI Shapefile" out.shp road.shp -dialect sqlite -sql "select ST_Diffrence(road.geometry, seg_buff.geometry) from road, 'seg_buff.shp'.seg_buff and this gives me no such column: seg_buff.geometry' I do not understand why this gives me that error – Pil Kwon Oct 14 '18 at 13:30

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.