Skip to content

Commit 8d64e2e

Browse files
committed
Also add unique_ptrs for other geos classes
1 parent b2add8c commit 8d64e2e

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

src/core/geometry/qgsgeos.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ void geos::GeosDeleter::operator()( const GEOSPreparedGeometry *geom )
111111
GEOSPreparedGeom_destroy_r( geosinit.ctxt, geom );
112112
}
113113

114+
void geos::GeosDeleter::operator()( GEOSBufferParams *params )
115+
{
116+
GEOSBufferParams_destroy_r( geosinit.ctxt, params );
117+
}
118+
119+
void geos::GeosDeleter::operator()( GEOSCoordSequence *sequence )
120+
{
121+
GEOSCoordSeq_destroy_r( geosinit.ctxt, sequence );
122+
}
123+
114124

115125
///@endcond
116126

@@ -1851,18 +1861,17 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::singleSidedBuffer( double distance
18511861
geos::unique_ptr geos;
18521862
try
18531863
{
1854-
GEOSBufferParams *bp = GEOSBufferParams_create_r( geosinit.ctxt );
1855-
GEOSBufferParams_setSingleSided_r( geosinit.ctxt, bp, 1 );
1856-
GEOSBufferParams_setQuadrantSegments_r( geosinit.ctxt, bp, segments );
1857-
GEOSBufferParams_setJoinStyle_r( geosinit.ctxt, bp, joinStyle );
1858-
GEOSBufferParams_setMitreLimit_r( geosinit.ctxt, bp, miterLimit ); //#spellok
1864+
geos::buffer_params_unique_ptr bp( GEOSBufferParams_create_r( geosinit.ctxt ) );
1865+
GEOSBufferParams_setSingleSided_r( geosinit.ctxt, bp.get(), 1 );
1866+
GEOSBufferParams_setQuadrantSegments_r( geosinit.ctxt, bp.get(), segments );
1867+
GEOSBufferParams_setJoinStyle_r( geosinit.ctxt, bp.get(), joinStyle );
1868+
GEOSBufferParams_setMitreLimit_r( geosinit.ctxt, bp.get(), miterLimit ); //#spellok
18591869

18601870
if ( side == 1 )
18611871
{
18621872
distance = -distance;
18631873
}
1864-
geos.reset( GEOSBufferWithParams_r( geosinit.ctxt, mGeos.get(), bp, distance ) );
1865-
GEOSBufferParams_destroy_r( geosinit.ctxt, bp );
1874+
geos.reset( GEOSBufferWithParams_r( geosinit.ctxt, mGeos.get(), bp.get(), distance ) );
18661875
}
18671876
CATCH_GEOS_WITH_ERRMSG( nullptr );
18681877
return fromGeos( geos.get() );
@@ -2020,11 +2029,10 @@ QgsGeometry QgsGeos::closestPoint( const QgsGeometry &other, QString *errorMsg )
20202029
double ny = 0.0;
20212030
try
20222031
{
2023-
GEOSCoordSequence *nearestCoord = GEOSNearestPoints_r( geosinit.ctxt, mGeos.get(), otherGeom.get() );
2032+
geos::coord_sequence_unique_ptr nearestCoord( GEOSNearestPoints_r( geosinit.ctxt, mGeos.get(), otherGeom.get() ) );
20242033

2025-
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord, 0, &nx );
2026-
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord, 0, &ny );
2027-
GEOSCoordSeq_destroy_r( geosinit.ctxt, nearestCoord );
2034+
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord.get(), 0, &nx );
2035+
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord.get(), 0, &ny );
20282036
}
20292037
catch ( GEOSException &e )
20302038
{
@@ -2057,14 +2065,12 @@ QgsGeometry QgsGeos::shortestLine( const QgsGeometry &other, QString *errorMsg )
20572065
double ny2 = 0.0;
20582066
try
20592067
{
2060-
GEOSCoordSequence *nearestCoord = GEOSNearestPoints_r( geosinit.ctxt, mGeos.get(), otherGeom.get() );
2061-
2062-
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord, 0, &nx1 );
2063-
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord, 0, &ny1 );
2064-
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord, 1, &nx2 );
2065-
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord, 1, &ny2 );
2068+
geos::coord_sequence_unique_ptr nearestCoord( GEOSNearestPoints_r( geosinit.ctxt, mGeos.get(), otherGeom.get() ) );
20662069

2067-
GEOSCoordSeq_destroy_r( geosinit.ctxt, nearestCoord );
2070+
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord.get(), 0, &nx1 );
2071+
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord.get(), 0, &ny1 );
2072+
( void )GEOSCoordSeq_getX_r( geosinit.ctxt, nearestCoord.get(), 1, &nx2 );
2073+
( void )GEOSCoordSeq_getY_r( geosinit.ctxt, nearestCoord.get(), 1, &ny2 );
20682074
}
20692075
catch ( GEOSException &e )
20702076
{

src/core/geometry/qgsgeos.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ namespace geos
5454
* geos context.
5555
*/
5656
void CORE_EXPORT operator()( const GEOSPreparedGeometry *geom );
57+
58+
/**
59+
* Destroys the GEOS buffer params \a params, using the static QGIS
60+
* geos context.
61+
*/
62+
void CORE_EXPORT operator()( GEOSBufferParams *params );
63+
64+
/**
65+
* Destroys the GEOS coordinate sequence \a sequence, using the static QGIS
66+
* geos context.
67+
*/
68+
void CORE_EXPORT operator()( GEOSCoordSequence *sequence );
5769
};
5870

5971
/**
@@ -65,6 +77,17 @@ namespace geos
6577
* Scoped GEOS prepared geometry pointer.
6678
*/
6779
using prepared_unique_ptr = std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter>;
80+
81+
/**
82+
* Scoped GEOS buffer params pointer.
83+
*/
84+
using buffer_params_unique_ptr = std::unique_ptr< GEOSBufferParams, GeosDeleter>;
85+
86+
/**
87+
* Scoped GEOS coordinate sequence pointer.
88+
*/
89+
using coord_sequence_unique_ptr = std::unique_ptr< GEOSCoordSequence, GeosDeleter>;
90+
6891
}
6992

7093
/**

src/core/pal/pointset.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,11 @@ double PointSet::minDistanceToPoint( double px, double py, double *rx, double *r
718718
//for polygons, we want distance to exterior ring (not an interior point)
719719
extRing = GEOSGetExteriorRing_r( geosctxt, mGeos );
720720
}
721-
GEOSCoordSequence *nearestCoord = GEOSNearestPoints_r( geosctxt, extRing, geosPt.get() );
721+
geos::coord_sequence_unique_ptr nearestCoord( GEOSNearestPoints_r( geosctxt, extRing, geosPt.get() ) );
722722
double nx;
723723
double ny;
724-
( void )GEOSCoordSeq_getX_r( geosctxt, nearestCoord, 0, &nx );
725-
( void )GEOSCoordSeq_getY_r( geosctxt, nearestCoord, 0, &ny );
726-
GEOSCoordSeq_destroy_r( geosctxt, nearestCoord );
724+
( void )GEOSCoordSeq_getX_r( geosctxt, nearestCoord.get(), 0, &nx );
725+
( void )GEOSCoordSeq_getY_r( geosctxt, nearestCoord.get(), 0, &ny );
727726

728727
if ( rx )
729728
*rx = nx;

0 commit comments

Comments
 (0)