4

Which algorithm does QGIS use for clipping shapefiles?

When I use ogr2ogr to clip a large shapefile (approx. 3gb) it takes 77sec. When using QGIS it takes approx 5 sec, clipping the same dataset (and same mask-layer). New clipped layer is approx 30mb, and the 6sec. includes saving in QGIS

Any suggestions for a better algorithms or modifications of the code below?

Here is the code I use in Python:

import subprocess
clipping_shp = r"C:\Python\buffer.shp"
output_shp = r"C:\Python\result.shp"  
input_shp = r'C:\Python\data.shp'
subprocess.call(["ogr2ogr", "-f", "ESRI Shapefile", "-clipsrc", clipping_shp, output_shp, input_shp], shell=True)
4
  • 2
    Do you save clipped layer when you use qgis? I mean is it a memory layer or a saved layer on disk? Saving layer consumes a lot time and you are using 3 gb file.
    – Xi Jin
    Jan 13 at 10:48
  • 2
    Does 5 sec with QGIS include the time it took to open the layer into QGIS?
    – user30184
    Jan 13 at 11:10
  • You don't use a Python solution, you use ogr2ogr via Python
    – gene
    Jan 13 at 11:13
  • @Xi Jin, New clipped layer is approx 30mb, and the 6sec. includes saving in QGIS.@user30184 It includes the clip-prosess and saving new layer
    – heljor
    Jan 13 at 11:44
1

Which algorithm does QGIS use for clipping shapefiles?

QGIS is Open Source and you can have a look through the code for the clipping algorithm on their GitHub:

https://github.com/qgis/QGIS/blob/04b9c6ab00bb130e590863244b8de64c0f111ae1/src/analysis/processing/qgsalgorithmclip.cpp

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.