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

Even Rouault even.rouault at spatialys.com
Tue Nov 13 07:02:57 PST 2018


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


More information about the gdal-dev mailing list