Skip to content
Permalink
Browse files

Speedup label placement when building against GEOS-3.9.0

Uses GEOSPreparedNearestPoints signature
See https://trac.osgeo.org/geos/ticket/1007
  • Loading branch information
strk authored and nyalldawson committed Nov 4, 2020
1 parent 9a7efe0 commit 8723be6970c5cc26fd7f57f3d74a3f7dca130a8b
Showing with 31 additions and 0 deletions.
  1. +30 −0 src/core/pal/pointset.cpp
  2. +1 −0 src/core/pal/pointset.h
@@ -184,6 +184,11 @@ void PointSet::invalidateGeos()
GEOSPreparedGeom_destroy_r( geosctxt, mPreparedGeom );
mOwnsGeom = false;
mGeos = nullptr;
if ( mGeosPreparedBoundary )
{
GEOSPreparedGeom_destroy_r( geosctxt, mGeosPreparedBoundary );
mGeosPreparedBoundary = nullptr;
}
mPreparedGeom = nullptr;
mLength = -1;
mArea = -1;
@@ -200,6 +205,12 @@ PointSet::~PointSet()
}
GEOSPreparedGeom_destroy_r( geosctxt, mPreparedGeom );

if ( mGeosPreparedBoundary )
{
GEOSPreparedGeom_destroy_r( geosctxt, mGeosPreparedBoundary );
mGeosPreparedBoundary = nullptr;
}

deleteCoords();

delete[] cHull;
@@ -807,16 +818,35 @@ double PointSet::minDistanceToPoint( double px, double py, double *rx, double *r
#endif
int type = GEOSGeomTypeId_r( geosctxt, mGeos );
const GEOSGeometry *extRing = nullptr;
#if GEOS_VERSION_MAJOR>3 || GEOS_VERSION_MINOR>=9
const GEOSPreparedGeometry *preparedExtRing = nullptr;
#endif

if ( type != GEOS_POLYGON )
{
extRing = mGeos;
#if GEOS_VERSION_MAJOR>3 || GEOS_VERSION_MINOR>=9
preparedExtRing = preparedGeom();
#endif
}
else
{
//for polygons, we want distance to exterior ring (not an interior point)
extRing = GEOSGetExteriorRing_r( geosctxt, mGeos );
#if GEOS_VERSION_MAJOR>3 || GEOS_VERSION_MINOR>=9
if ( ! mGeosPreparedBoundary )
{
mGeosPreparedBoundary = GEOSPrepare_r( geosctxt, extRing );
}
preparedExtRing = mGeosPreparedBoundary;
#endif
}

#if 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() ) );
#endif
double nx;
double ny;
#if GEOS_VERSION_MAJOR>3 || GEOS_VERSION_MINOR>=8
@@ -233,6 +233,7 @@ namespace pal

private:

mutable const GEOSPreparedGeometry *mGeosPreparedBoundary = nullptr;
mutable const GEOSPreparedGeometry *mPreparedGeom = nullptr;

PointSet &operator= ( const PointSet & ) = delete;

0 comments on commit 8723be6

Please sign in to comment.
You can’t perform that action at this time.