From e8c94112b37579fbd70897363aaea065d5317a7c Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 16 Nov 2020 11:59:46 +0100 Subject: [PATCH] Use GEOSPreparedDistance when available Allow speeding up GEOSDistance computation. See https://github.com/qgis/QGIS/pull/39970#pullrequestreview-528643769 Requires GEOS-3.9+ Also fixes a conditional about GEOS for nearestPoints --- src/core/geometry/qgsgeos.cpp | 11 +++++++++++ src/core/pal/pointset.cpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index fd1bb3a6c4d2..47025feb290a 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -430,7 +430,18 @@ double QgsGeos::distance( const QgsAbstractGeometry *geom, QString *errorMsg ) c try { +#if GEOS_VERSION_MAJOR>3 || ( GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR>=9 ) + if ( mGeosPrepared ) + { + GEOSPreparedDistance_r( geosinit()->ctxt, mGeosPrepared.get(), otherGeosGeom.get(), &distance ); + } + else + { + GEOSDistance_r( geosinit()->ctxt, mGeos.get(), otherGeosGeom.get(), &distance ); + } +#else GEOSDistance_r( geosinit()->ctxt, mGeos.get(), otherGeosGeom.get(), &distance ); +#endif } CATCH_GEOS_WITH_ERRMSG( -1.0 ) diff --git a/src/core/pal/pointset.cpp b/src/core/pal/pointset.cpp index a67125486ce1..376ae29089e2 100644 --- a/src/core/pal/pointset.cpp +++ b/src/core/pal/pointset.cpp @@ -842,7 +842,7 @@ double PointSet::minDistanceToPoint( double px, double py, double *rx, double *r #endif } -#if GEOS_VERSION_MAJOR>3 || GEOS_VERSION_MINOR>=9 +#if GEOS_VERSION_MAJOR>3 || ( GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR>=9 ) geos::coord_sequence_unique_ptr nearestCoord( GEOSPreparedNearestPoints_r( geosctxt, preparedExtRing, geosPt.get() ) ); #else geos::coord_sequence_unique_ptr nearestCoord( GEOSNearestPoints_r( geosctxt, extRing, geosPt.get() ) );