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

Peter Marlow Peter.Marlow at scisys.co.uk
Wed Nov 14 01:10:37 PST 2018


Hi Even,

Thanks for the reply. That makes sense then, I didn't realise QGIS was doing lots of additional optimisation. It looks like there are Python bindings for GEOS so I will try to use the clip mechanism that resides there instead of ogr2ogr.

Making ogr2ogr use the same performance enhancements as GEOS would be a great improvement :) (suspect it's not that straight-forward though)

Thanks,
Pete

-----Original Message-----
From: Even Rouault <even.rouault at spatialys.com> 
Sent: 13 November 2018 15:03
To: gdal-dev at lists.osgeo.org
Cc: Peter Marlow <Peter.Marlow at scisys.co.uk>
Subject: Re: [gdal-dev] ogr2ogr clip operation very slow compared to QGIS

Peter,

> 
> I'm trying to clip some GML data via a fairly complex ShapeFile 
> boundary using standard ogr2ogr and it is taking roughly 5 minutes 
> before completing successfully.

Does your input dataset (input_file.gz) has many features ? (let's say ~1000)

> This same operation takes less than a second using the Clip operation 
> in QGIS with exactly the same data. I was lead to believe that QGIS is 
> using OGR under the hood to perform the clip operation,

I don't think so. From what I can see, qgsalgorithmclip.cpp in QGIS uses the same geometry library as OGR, namely GEOS, but doesn't use OGR itself.

> so my
> question is: why is my ogr2ogr clip command taking so much longer?

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. QGIS also checks for the result of contains() and
intersects() predicates before calculating the intersection geometry. Not sure how much that speed-up things. So I bet ogr2ogr could be improved to have similar performance as QGIS clipping.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com



SCISYS UK Limited. Registered in England and Wales No. 4373530.
Registered Office: Methuen Park, Chippenham, Wiltshire SN14 0GB, UK.
 
Before printing, please think about the environment.



More information about the gdal-dev mailing list