I have used QGIS Geoprocessing tool Difference to cut polylines (SHP) into to smaller pieces using a polygon (SHP). This works very good in QGIS.

Now, to speed up the process, I'd like to be able to do the exact same thing but from the Terminal (so I can later make a shell script).

Maybe GDAL has these functions? In that case, how?

I'm using a Mac.

1 Answer 1


Maybe can you try ogr2ogr -clipdst DATASOURCE destinationFile sourceFile. For example : ogr2ogr-clipdst yourPolygon.shp destinationFile yourPolylines.shp.

But, in this case, you will cut one shapefile with another. If you want to cut your polylines shapefile with each features of a polygon shapefile, you must split the polygon shapefile and iterate over each polygon feature. For example: ogr2ogr -clipdst myFirstPolygonFeature destinationFile yourPolylines.shp.

Here is the man page: http://www.gdal.org/ogr2ogr.html.

  • This command returns a simple Clip layer and not the Difference layer.
    – JAT86
    Jun 23, 2019 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.