5

I'm trying to clip a large polygon shapefile (nearly 440,000 features, 0.5 GB) to a shapefile containing a single polygon. Both shapefiles use the same CRS (EPSG:27700).

With QGIS, using Vector > Geoprocessing Tools > Clip, I left it running for nearly 24 hours and it was still at only 7% complete.

I tried the same clip using ArcMap and it finished in 4 minutes.

I tried it again in QGIS, and also tried GDAL/OGR > Geoprocessing > Clip vectors to polygons, but it's been running for an hour and is clearly going to take an eternity.

I'm new to QGIS and am wondering if this typical of its performance when clipping large vector datasets? Or is there a trick to get it perform somewhere close to ArcMap's speed?

2

3 Answers 3

1

You could:

  • Simplify the geometries of your large polygon shapefile:

    Vector > Geometry Tools > Simplify Geometries...
    
  • Select only those features from the large polygon shapefile which intersects the single polygon:

    Processing Toolbox > QGIS geoalgorithms > Vector selection tools > Select by location
    

    Then use these selected features for clipping by enabling the Use only selected features in the Clip tool.

1

Came here with the same question. In my case, I'm comparing a vectorized CORINE raster (500,000 features) to the outline of Scotland (1 feature)

The reason for this is how spatial indexes work. Even if you have spatial indexes on everything, having one big polygon makes the spatial index effectively useless on that layer . The trick is to break up the large polygon into smaller features.

So to fix this, I

  • created a 1km polygon grid
  • "select by Location" on the grid, using the Scotland Layer, using 'within' or 'intersects' predicates
  • "save selected" to a new GPKG
  • do the clip on this new GPKG

It seems counter-intuitive that comparing against lots more features would be faster. The reason is that it makes much better use of spatial indexes.

This got it to do the clip in about 10 minutes.

EDIT: try using the Whitebox Tools version of Clip too... it is also slow in the original setup, but finished in about a minute

0

Create a spatial index using the "Create spatial index" tool for both the clipping features and the features to be clipped:

Vector > Data Management > Create Spatial Index...

This will then make your "Select by location" command run much faster!

Vector > Research Tools > Select by Location...

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.