[gdal-dev] ogr2ogr clip operation very slow compared to QGIS

Nyall Dawson nyall.dawson at gmail.com
Tue Nov 13 15:17:17 PST 2018


On Wed, 14 Nov 2018 at 01:03, Even Rouault <even.rouault at spatialys.com> wrote:

> Looking at QGIS code, it uses GEOS prepared geometry mechanism with the clip
> geometry, so as to speed up intersection operations on it. Whereas ogr2ogr -
> clipsrc uses the 'naive' intersection function. I guess this is the reason for
> the speed difference.

This is the big difference -- using the prepared methods results in
orders of magnitude speed boosts.

> QGIS also checks for the result of contains() and
> intersects() predicates before calculating the intersection geometry. Not sure
> how much that speed-up things.

Significantly (sorry no actual figures available). What's happening
here is the GEOS intersection method doesn't utilise prepared
geometries, yet the tests like contains and intersects do. The raw
intersection method is slow, even if there's no actual intersection or
if the geometry will be returned unchanged (i.e. it's within the clip
mask). So by taking advantage of the fast within/intersects tests on
the prepared geometry we potentially skip a bunch of unnecessary slow
intersection calculations.

Nyall


More information about the gdal-dev mailing list