Skip to content

Commit e4ab3f2

Browse files
committedSep 13, 2014
Merge remote-tracking branch 'rouault/use_geos_reentrant_api'
Conflicts: src/core/pal/layer.cpp src/core/qgsgeometry.cpp src/core/qgspallabeling.cpp
2 parents e46aa62 + 6354dd3 commit e4ab3f2

14 files changed

+468
-503
lines changed
 

‎cmake/FindGEOS.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ ELSE(WIN32)
8484
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GEOS_VERSION_MAJOR "${GEOS_VERSION}")
8585
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GEOS_VERSION_MINOR "${GEOS_VERSION}")
8686

87-
IF (GEOS_VERSION_MAJOR LESS 3)
88-
MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.0.0 or higher.")
89-
ENDIF (GEOS_VERSION_MAJOR LESS 3)
87+
IF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) )
88+
MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.1.0 or higher.")
89+
ENDIF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) )
9090

9191
# set INCLUDE_DIR to prefix+include
9292
EXEC_PROGRAM(${GEOS_CONFIG}

‎src/analysis/vector/qgsgeometryanalyzer.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,36 +1100,37 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
11001100

11011101
QList<GEOSGeometry*> outputGeomList;
11021102
QList<QgsGeometry*>::const_iterator inputGeomIt = inputGeomList.constBegin();
1103+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
11031104
for ( ; inputGeomIt != inputGeomList.constEnd(); ++inputGeomIt )
11041105
{
11051106
if ( geom->type() == QGis::Line )
11061107
{
11071108
//geos 3.3 needed for line offsets
11081109
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
11091110
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
1110-
GEOSGeometry* offsetGeom = GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
1111-
if ( !offsetGeom || !GEOSisValid( offsetGeom ) )
1111+
GEOSGeometry* offsetGeom = GEOSOffsetCurve_r(geosctxt, ( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
1112+
if ( !offsetGeom || !GEOSisValid_r(geosctxt, offsetGeom ) )
11121113
{
11131114
return false;
11141115
}
1115-
if ( !GEOSisValid( offsetGeom ) || GEOSGeomTypeId( offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints( offsetGeom ) < 1 )
1116+
if ( !GEOSisValid_r(geosctxt, offsetGeom ) || GEOSGeomTypeId_r(geosctxt, offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints_r(geosctxt, offsetGeom ) < 1 )
11161117
{
1117-
GEOSGeom_destroy( offsetGeom );
1118+
GEOSGeom_destroy_r(geosctxt, offsetGeom );
11181119
return false;
11191120
}
11201121
outputGeomList.push_back( offsetGeom );
11211122
#else
1122-
outputGeomList.push_back( GEOSGeom_clone(( *inputGeomIt )->asGeos() ) );
1123+
outputGeomList.push_back( GEOSGeom_clone_r(geosctxt, ( *inputGeomIt )->asGeos() ) );
11231124
#endif
11241125
}
11251126
else if ( geom->type() == QGis::Point )
11261127
{
11271128
QgsPoint p = ( *inputGeomIt )->asPoint();
11281129
p = createPointOffset( p.x(), p.y(), offset, lineGeom );
1129-
GEOSCoordSequence* ptSeq = GEOSCoordSeq_create( 1, 2 );
1130-
GEOSCoordSeq_setX( ptSeq, 0, p.x() );
1131-
GEOSCoordSeq_setY( ptSeq, 0, p.y() );
1132-
GEOSGeometry* geosPt = GEOSGeom_createPoint( ptSeq );
1130+
GEOSCoordSequence* ptSeq = GEOSCoordSeq_create_r(geosctxt, 1, 2 );
1131+
GEOSCoordSeq_setX_r(geosctxt, ptSeq, 0, p.x() );
1132+
GEOSCoordSeq_setY_r(geosctxt, ptSeq, 0, p.y() );
1133+
GEOSGeometry* geosPt = GEOSGeom_createPoint_r(geosctxt, ptSeq );
11331134
outputGeomList.push_back( geosPt );
11341135
}
11351136
}
@@ -1152,11 +1153,11 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry*
11521153
GEOSGeometry* collection = 0;
11531154
if ( geom->type() == QGis::Point )
11541155
{
1155-
collection = GEOSGeom_createCollection( GEOS_MULTIPOINT, geomArray, outputGeomList.size() );
1156+
collection = GEOSGeom_createCollection_r(geosctxt, GEOS_MULTIPOINT, geomArray, outputGeomList.size() );
11561157
}
11571158
else if ( geom->type() == QGis::Line )
11581159
{
1159-
collection = GEOSGeom_createCollection( GEOS_MULTILINESTRING, geomArray, outputGeomList.size() );
1160+
collection = GEOSGeom_createCollection_r(geosctxt, GEOS_MULTILINESTRING, geomArray, outputGeomList.size() );
11601161
}
11611162
geom->fromGeos( collection );
11621163
delete[] geomArray;

‎src/analysis/vector/qgszonalstatistics.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry*
281281
return;
282282
}
283283

284-
const GEOSPreparedGeometry* polyGeosPrepared = GEOSPrepare( poly->asGeos() );
284+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
285+
const GEOSPreparedGeometry* polyGeosPrepared = GEOSPrepare_r( geosctxt, poly->asGeos() );
285286
if ( !polyGeosPrepared )
286287
{
287288
return;
@@ -300,15 +301,15 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry*
300301
cellCenterX = rasterBBox.xMinimum() + pixelOffsetX * cellSizeX + cellSizeX / 2;
301302
for ( int j = 0; j < nCellsX; ++j )
302303
{
303-
GEOSGeom_destroy( currentCellCenter );
304-
cellCenterCoords = GEOSCoordSeq_create( 1, 2 );
305-
GEOSCoordSeq_setX( cellCenterCoords, 0, cellCenterX );
306-
GEOSCoordSeq_setY( cellCenterCoords, 0, cellCenterY );
307-
currentCellCenter = GEOSGeom_createPoint( cellCenterCoords );
304+
GEOSGeom_destroy_r( geosctxt, currentCellCenter );
305+
cellCenterCoords = GEOSCoordSeq_create_r( geosctxt, 1, 2 );
306+
GEOSCoordSeq_setX_r( geosctxt, cellCenterCoords, 0, cellCenterX );
307+
GEOSCoordSeq_setY_r( geosctxt, cellCenterCoords, 0, cellCenterY );
308+
currentCellCenter = GEOSGeom_createPoint_r( geosctxt, cellCenterCoords );
308309

309310
if ( scanLine[j] != mInputNodataValue ) //don't consider nodata values
310311
{
311-
if ( GEOSPreparedContains( polyGeosPrepared, currentCellCenter ) )
312+
if ( GEOSPreparedContains_r( geosctxt, polyGeosPrepared, currentCellCenter ) )
312313
{
313314
if ( !qIsNaN( scanLine[j] ) )
314315
{
@@ -322,7 +323,7 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry*
322323
cellCenterY -= cellSizeY;
323324
}
324325
CPLFree( scanLine );
325-
GEOSPreparedGeom_destroy( polyGeosPrepared );
326+
GEOSPreparedGeom_destroy_r( geosctxt, polyGeosPrepared );
326327
}
327328

328329
void QgsZonalStatistics::statisticsFromPreciseIntersection( void* band, QgsGeometry* poly, int pixelOffsetX,

‎src/app/qgsmaptooloffsetcurve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset, bool leftSide
367367
int quadSegments = s.value( "/qgis/digitizing/offset_quad_seg", 8 ).toInt();
368368
double mitreLimit = s.value( "/qgis/digitizing/offset_miter_limit", 5.0 ).toDouble();
369369

370-
GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, leftSide ? offset : -offset, quadSegments, joinStyle, mitreLimit );
370+
GEOSGeometry* offsetGeom = GEOSOffsetCurve_r( QgsGeometry::getGEOSHandler(), geosGeom, leftSide ? offset : -offset, quadSegments, joinStyle, mitreLimit );
371371
if ( !offsetGeom )
372372
{
373373
deleteRubberBandAndGeometry();

‎src/core/pal/feature.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#endif
4040

4141
#include <qglobal.h>
42+
#include <qgsgeometry.h>
4243

4344
#include <cmath>
4445
#include <cstring>
@@ -109,7 +110,7 @@ namespace pal
109110

110111
if ( ownsGeom )
111112
{
112-
GEOSGeom_destroy( the_geom );
113+
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), the_geom );
113114
the_geom = NULL;
114115
}
115116
}
@@ -123,36 +124,37 @@ namespace pal
123124
int i, j;
124125

125126
const GEOSCoordSequence *coordSeq;
127+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
126128

127-
type = GEOSGeomTypeId( geom );
129+
type = GEOSGeomTypeId_r( geosctxt, geom );
128130

129131
if ( type == GEOS_POLYGON )
130132
{
131-
if ( GEOSGetNumInteriorRings( geom ) > 0 )
133+
if ( GEOSGetNumInteriorRings_r( geosctxt, geom ) > 0 )
132134
{
133135
// set nbHoles, holes member variables
134-
nbHoles = GEOSGetNumInteriorRings( geom );
136+
nbHoles = GEOSGetNumInteriorRings_r( geosctxt, geom );
135137
holes = new PointSet*[nbHoles];
136138

137139
for ( i = 0; i < nbHoles; i++ )
138140
{
139141
holes[i] = new PointSet();
140142
holes[i]->holeOf = NULL;
141143

142-
const GEOSGeometry* interior = GEOSGetInteriorRingN( geom, i );
143-
holes[i]->nbPoints = GEOSGetNumCoordinates( interior );
144+
const GEOSGeometry* interior = GEOSGetInteriorRingN_r( geosctxt, geom, i );
145+
holes[i]->nbPoints = GEOSGetNumCoordinates_r( geosctxt, interior );
144146
holes[i]->x = new double[holes[i]->nbPoints];
145147
holes[i]->y = new double[holes[i]->nbPoints];
146148

147149
holes[i]->xmin = holes[i]->ymin = DBL_MAX;
148150
holes[i]->xmax = holes[i]->ymax = -DBL_MAX;
149151

150-
coordSeq = GEOSGeom_getCoordSeq( interior );
152+
coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, interior );
151153

152154
for ( j = 0; j < holes[i]->nbPoints; j++ )
153155
{
154-
GEOSCoordSeq_getX( coordSeq, j, &holes[i]->x[j] );
155-
GEOSCoordSeq_getY( coordSeq, j, &holes[i]->y[j] );
156+
GEOSCoordSeq_getX_r( geosctxt, coordSeq, j, &holes[i]->x[j] );
157+
GEOSCoordSeq_getY_r( geosctxt, coordSeq, j, &holes[i]->y[j] );
156158

157159
holes[i]->xmax = holes[i]->x[j] > holes[i]->xmax ? holes[i]->x[j] : holes[i]->xmax;
158160
holes[i]->xmin = holes[i]->x[j] < holes[i]->xmin ? holes[i]->x[j] : holes[i]->xmin;
@@ -166,7 +168,7 @@ namespace pal
166168
}
167169

168170
// use exterior ring for the extraction of coordinates that follows
169-
geom = GEOSGetExteriorRing( geom );
171+
geom = GEOSGetExteriorRing_r( geosctxt, geom );
170172
}
171173
else
172174
{
@@ -175,8 +177,8 @@ namespace pal
175177
}
176178

177179
// find out number of points
178-
nbPoints = GEOSGetNumCoordinates( geom );
179-
coordSeq = GEOSGeom_getCoordSeq( geom );
180+
nbPoints = GEOSGetNumCoordinates_r( geosctxt, geom );
181+
coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, geom );
180182

181183
// initialize bounding box
182184
xmin = ymin = DBL_MAX;
@@ -188,8 +190,8 @@ namespace pal
188190

189191
for ( i = 0; i < nbPoints; i++ )
190192
{
191-
GEOSCoordSeq_getX( coordSeq, i, &x[i] );
192-
GEOSCoordSeq_getY( coordSeq, i, &y[i] );
193+
GEOSCoordSeq_getX_r( geosctxt, coordSeq, i, &x[i] );
194+
GEOSCoordSeq_getY_r( geosctxt, coordSeq, i, &y[i] );
193195

194196
xmax = x[i] > xmax ? x[i] : xmax;
195197
xmin = x[i] < xmin ? x[i] : xmin;
@@ -1397,13 +1399,14 @@ namespace pal
13971399

13981400
void FeaturePart::addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] )
13991401
{
1400-
int geomType = GEOSGeomTypeId( the_geom );
1402+
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
1403+
int geomType = GEOSGeomTypeId_r( ctxt, the_geom );
14011404

14021405
double sizeCost = 0;
14031406
if ( geomType == GEOS_LINESTRING )
14041407
{
14051408
double length;
1406-
if ( GEOSLength( the_geom, &length ) != 1 )
1409+
if ( GEOSLength_r( ctxt, the_geom, &length ) != 1 )
14071410
return; // failed to calculate length
14081411
double bbox_length = max( bbx[2] - bbx[0], bby[2] - bby[0] );
14091412
if ( length >= bbox_length / 4 )
@@ -1414,7 +1417,7 @@ namespace pal
14141417
else if ( geomType == GEOS_POLYGON )
14151418
{
14161419
double area;
1417-
if ( GEOSArea( the_geom, &area ) != 1 )
1420+
if ( GEOSArea_r( ctxt, the_geom, &area ) != 1 )
14181421
return;
14191422
double bbox_area = ( bbx[2] - bbx[0] ) * ( bby[2] - bby[0] );
14201423
if ( area >= bbox_area / 16 )
@@ -1436,27 +1439,28 @@ namespace pal
14361439

14371440
bool FeaturePart::isConnected( FeaturePart* p2 )
14381441
{
1439-
return ( GEOSTouches( the_geom, p2->the_geom ) == 1 );
1442+
return ( GEOSTouches_r( QgsGeometry::getGEOSHandler(), the_geom, p2->the_geom ) == 1 );
14401443
}
14411444

14421445
bool FeaturePart::mergeWithFeaturePart( FeaturePart* other )
14431446
{
1444-
GEOSGeometry* g1 = GEOSGeom_clone( the_geom );
1445-
GEOSGeometry* g2 = GEOSGeom_clone( other->the_geom );
1447+
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
1448+
GEOSGeometry* g1 = GEOSGeom_clone_r( ctxt, the_geom );
1449+
GEOSGeometry* g2 = GEOSGeom_clone_r( ctxt, other->the_geom );
14461450
GEOSGeometry* geoms[2] = { g1, g2 };
1447-
GEOSGeometry* g = GEOSGeom_createCollection( GEOS_MULTILINESTRING, geoms, 2 );
1448-
GEOSGeometry* gTmp = GEOSLineMerge( g );
1449-
GEOSGeom_destroy( g );
1451+
GEOSGeometry* g = GEOSGeom_createCollection_r( ctxt, GEOS_MULTILINESTRING, geoms, 2 );
1452+
GEOSGeometry* gTmp = GEOSLineMerge_r( ctxt, g );
1453+
GEOSGeom_destroy_r( ctxt, g );
14501454

1451-
if ( GEOSGeomTypeId( gTmp ) != GEOS_LINESTRING )
1455+
if ( GEOSGeomTypeId_r( ctxt, gTmp ) != GEOS_LINESTRING )
14521456
{
14531457
// sometimes it's not possible to merge lines (e.g. they don't touch at endpoints)
1454-
GEOSGeom_destroy( gTmp );
1458+
GEOSGeom_destroy_r( ctxt, gTmp );
14551459
return false;
14561460
}
14571461

14581462
if ( ownsGeom ) // delete old geometry if we own it
1459-
GEOSGeom_destroy( the_geom );
1463+
GEOSGeom_destroy_r( ctxt, the_geom );
14601464
// set up new geometry
14611465
the_geom = gTmp;
14621466
ownsGeom = true;

‎src/core/pal/layer.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <cmath>
4242
#include <vector>
4343

44+
#include <qgsgeometry.h>
4445

4546
#include <pal/pal.h>
4647
#include <pal/layer.h>
@@ -286,18 +287,20 @@ namespace pal
286287
throw InternalException::UnknownGeometry();
287288
}
288289

290+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
291+
289292
while ( simpleGeometries->size() > 0 )
290293
{
291294
const GEOSGeometry* geom = simpleGeometries->pop_front();
292295

293296
// ignore invalid geometries (e.g. polygons with self-intersecting rings)
294-
if ( GEOSisValid( geom ) != 1 ) // 0=invalid, 1=valid, 2=exception
297+
if ( GEOSisValid_r( geosctxt, geom ) != 1 ) // 0=invalid, 1=valid, 2=exception
295298
{
296299
std::cerr << "ignoring invalid feature " << geom_id << std::endl;
297300
continue;
298301
}
299302

300-
int type = GEOSGeomTypeId( geom );
303+
int type = GEOSGeomTypeId_r( geosctxt, geom );
301304

302305
if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
303306
{
@@ -325,9 +328,9 @@ namespace pal
325328
if ( mode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
326329
{
327330
if ( type == GEOS_LINESTRING )
328-
GEOSLength( geom, &geom_size );
331+
GEOSLength_r( geosctxt, geom, &geom_size );
329332
else if ( type == GEOS_POLYGON )
330-
GEOSArea( geom, &geom_size );
333+
GEOSArea_r( geosctxt, geom, &geom_size );
331334

332335
if ( geom_size > biggest_size )
333336
{
@@ -493,30 +496,31 @@ namespace pal
493496

494497
void Layer::chopFeaturesAtRepeatDistance( )
495498
{
499+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
496500
LinkedList<FeaturePart*> * newFeatureParts = new LinkedList<FeaturePart*>( ptrFeaturePartCompare );
497501
while ( FeaturePart* fpart = featureParts->pop_front() )
498502
{
499503
const GEOSGeometry* geom = fpart->getGeometry();
500504
double chopInterval = fpart->getFeature()->repeatDistance();
501-
if ( chopInterval != 0. && GEOSGeomTypeId( geom ) == GEOS_LINESTRING )
505+
if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
502506
{
503507

504508
double bmin[2], bmax[2];
505509
fpart->getBoundingBox( bmin, bmax );
506510
rtree->Remove( bmin, bmax, fpart );
507511

508-
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom );
512+
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
509513

510514
// get number of points
511515
unsigned int n;
512-
GEOSCoordSeq_getSize( cs, &n );
516+
GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
513517

514518
// Read points
515519
std::vector<Point> points( n );
516520
for ( unsigned int i = 0; i < n; ++i )
517521
{
518-
GEOSCoordSeq_getX( cs, i, &points[i].x );
519-
GEOSCoordSeq_getY( cs, i, &points[i].y );
522+
GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
523+
GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
520524
}
521525

522526
// Cumulative length vector
@@ -548,14 +552,14 @@ namespace pal
548552
p.x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
549553
p.y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
550554
part.push_back( p );
551-
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create( part.size(), 2 );
555+
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
552556
for ( std::size_t i = 0; i < part.size(); ++i )
553557
{
554-
GEOSCoordSeq_setX( cooSeq, i, part[i].x );
555-
GEOSCoordSeq_setY( cooSeq, i, part[i].y );
558+
GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
559+
GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
556560
}
557561

558-
GEOSGeometry* newgeom = GEOSGeom_createLineString( cooSeq );
562+
GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
559563
FeaturePart* newfpart = new FeaturePart( fpart->getFeature(), newgeom );
560564
newFeatureParts->push_back( newfpart );
561565
newfpart->getBoundingBox( bmin, bmax );
@@ -565,14 +569,14 @@ namespace pal
565569
}
566570
// Create final part
567571
part.push_back( points[n - 1] );
568-
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create( part.size(), 2 );
572+
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
569573
for ( std::size_t i = 0; i < part.size(); ++i )
570574
{
571-
GEOSCoordSeq_setX( cooSeq, i, part[i].x );
572-
GEOSCoordSeq_setY( cooSeq, i, part[i].y );
575+
GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
576+
GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
573577
}
574578

575-
GEOSGeometry* newgeom = GEOSGeom_createLineString( cooSeq );
579+
GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
576580
FeaturePart* newfpart = new FeaturePart( fpart->getFeature(), newgeom );
577581
newFeatureParts->push_back( newfpart );
578582
newfpart->getBoundingBox( bmin, bmax );

‎src/core/pal/pointset.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#endif
4040

4141
#include <qglobal.h>
42+
#include <qgsgeometry.h>
4243

4344
#include "pointset.h"
4445
#include "util.h"
@@ -988,29 +989,30 @@ namespace pal
988989
// check if centroid inside in polygon
989990
if ( forceInside && !isPointInPolygon( nbPoints, x, y, px, py ) )
990991
{
991-
GEOSCoordSequence *coord = GEOSCoordSeq_create( nbPoints, 2 );
992+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
993+
GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, nbPoints, 2 );
992994

993995
for ( int i = 0; i < nbPoints; ++i )
994996
{
995-
GEOSCoordSeq_setX( coord, i, x[i] );
996-
GEOSCoordSeq_setY( coord, i, y[i] );
997+
GEOSCoordSeq_setX_r( geosctxt, coord, i, x[i] );
998+
GEOSCoordSeq_setY_r( geosctxt, coord, i, y[i] );
997999
}
9981000

999-
GEOSGeometry *geom = GEOSGeom_createPolygon( GEOSGeom_createLinearRing( coord ), 0, 0 );
1001+
GEOSGeometry *geom = GEOSGeom_createPolygon_r( geosctxt, GEOSGeom_createLinearRing_r( geosctxt, coord ), 0, 0 );
10001002

10011003
if ( geom )
10021004
{
1003-
GEOSGeometry *pointGeom = GEOSPointOnSurface( geom );
1005+
GEOSGeometry *pointGeom = GEOSPointOnSurface_r( geosctxt, geom );
10041006

10051007
if ( pointGeom )
10061008
{
1007-
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq( pointGeom );
1008-
GEOSCoordSeq_getX( coordSeq, 0, &px );
1009-
GEOSCoordSeq_getY( coordSeq, 0, &py );
1009+
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, pointGeom );
1010+
GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, &px );
1011+
GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, &py );
10101012

1011-
GEOSGeom_destroy( pointGeom );
1013+
GEOSGeom_destroy_r( geosctxt, pointGeom );
10121014
}
1013-
GEOSGeom_destroy( geom );
1015+
GEOSGeom_destroy_r( geosctxt, geom );
10141016
}
10151017
}
10161018
}

‎src/core/pal/util.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <cstdarg>
4343
#include <ctime>
4444

45+
#include "qgsgeometry.h"
46+
4547
#include <pal/layer.h>
4648

4749
#include "internalexception.h"
@@ -211,18 +213,19 @@ namespace pal
211213
while ( queue->size() > 0 )
212214
{
213215
geom = queue->pop_front();
214-
switch ( GEOSGeomTypeId( geom ) )
216+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
217+
switch ( GEOSGeomTypeId_r( geosctxt, geom ) )
215218
{
216219
//case geos::geom::GEOS_MULTIPOINT:
217220
//case geos::geom::GEOS_MULTILINESTRING:
218221
//case geos::geom::GEOS_MULTIPOLYGON:
219222
case GEOS_MULTIPOINT:
220223
case GEOS_MULTILINESTRING:
221224
case GEOS_MULTIPOLYGON:
222-
nGeom = GEOSGetNumGeometries( geom );
225+
nGeom = GEOSGetNumGeometries_r( geosctxt, geom );
223226
for ( i = 0; i < nGeom; i++ )
224227
{
225-
queue->push_back( GEOSGetGeometryN( geom, i ) );
228+
queue->push_back( GEOSGetGeometryN_r( geosctxt, geom, i ) );
226229
}
227230
break;
228231
case GEOS_POINT:

‎src/core/qgsgeometry.cpp

Lines changed: 350 additions & 401 deletions
Large diffs are not rendered by default.

‎src/core/qgsgeometry.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ email : morb at ozemail dot com dot au
2424

2525
#include <geos_c.h>
2626

27-
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
28-
#define GEOSGeometry struct GEOSGeom_t
29-
#define GEOSCoordSequence struct GEOSCoordSeq_t
30-
#endif
31-
3227
#include "qgspoint.h"
3328
#include "qgscoordinatetransform.h"
3429
#include "qgsfeature.h"
@@ -88,6 +83,9 @@ class CORE_EXPORT QgsGeometry
8883
//! Destructor
8984
~QgsGeometry();
9085

86+
/** return GEOS context handle */
87+
static GEOSContextHandle_t getGEOSHandler();
88+
9189
/** static method that creates geometry from Wkt */
9290
static QgsGeometry* fromWkt( QString wkt );
9391

@@ -643,7 +641,7 @@ class CORE_EXPORT QgsGeometry
643641
/** return polygon from wkb */
644642
QgsPolygon asPolygon( QgsConstWkbPtr &wkbPtr, bool hasZValue ) const;
645643

646-
static bool geosRelOp( char( *op )( const GEOSGeometry*, const GEOSGeometry * ),
644+
static bool geosRelOp( char( *op )( GEOSContextHandle_t handle, const GEOSGeometry*, const GEOSGeometry * ),
647645
const QgsGeometry* a, const QgsGeometry* b );
648646

649647
/**Returns < 0 if point(x/y) is left of the line x1,y1 -> x1,y2*/

‎src/core/qgsgeometryvalidator.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,38 +201,39 @@ void QgsGeometryValidator::run()
201201
{
202202
char *r = 0;
203203
const GEOSGeometry *g0 = mG.asGeos();
204+
GEOSContextHandle_t handle = QgsGeometry::getGEOSHandler();
204205
if ( !g0 )
205206
{
206207
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:could not produce geometry for GEOS (check log window)" ) ) );
207208
}
208209
else
209210
{
210211
GEOSGeometry *g1 = 0;
211-
if ( GEOSisValidDetail( g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 )
212+
if ( GEOSisValidDetail_r( handle, g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 )
212213
{
213214
if ( g1 )
214215
{
215-
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g1 );
216+
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( handle, g1 );
216217

217218
unsigned int n;
218-
if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 )
219+
if ( GEOSCoordSeq_getSize_r( handle, cs, &n ) && n == 1 )
219220
{
220221
double x, y;
221-
GEOSCoordSeq_getX( cs, 0, &x );
222-
GEOSCoordSeq_getY( cs, 0, &y );
222+
GEOSCoordSeq_getX_r( handle, cs, 0, &x );
223+
GEOSCoordSeq_getY_r( handle, cs, 0, &y );
223224
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
224225
mErrorCount++;
225226
}
226227

227-
GEOSGeom_destroy( g1 );
228+
GEOSGeom_destroy_r( handle, g1 );
228229
}
229230
else
230231
{
231232
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
232233
mErrorCount++;
233234
}
234235

235-
GEOSFree( r );
236+
GEOSFree_r( handle, r );
236237
}
237238
}
238239

‎src/core/qgspalgeometry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef QGSPALGEOMETRY_H
22
#define QGSPALGEOMETRY_H
33

4+
#include "qgsgeometry.h"
45
#include <pal/feature.h>
56
#include <pal/palgeometry.h>
67

@@ -29,7 +30,7 @@ class QgsPalGeometry : public PalGeometry
2930
~QgsPalGeometry()
3031
{
3132
if ( mG )
32-
GEOSGeom_destroy( mG );
33+
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mG );
3334
delete mInfo;
3435
delete mFontMetrics;
3536
}

‎src/core/qgspallabeling.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,13 +1971,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
19711971
}
19721972

19731973
GEOSGeometry* geos_geom_clone;
1974-
if ( GEOSGeomTypeId( geos_geom ) == GEOS_POLYGON && repeatDistance > 0 && placement == Line )
1974+
if ( GEOSGeomTypeId_r( QgsGeometry::getGEOSHandler(), geos_geom ) == GEOS_POLYGON && repeatDistance > 0 && placement == Line )
19751975
{
1976-
geos_geom_clone = GEOSBoundary( geos_geom );
1976+
geos_geom_clone = GEOSBoundary_r( QgsGeometry::getGEOSHandler(), geos_geom );
19771977
}
19781978
else
19791979
{
1980-
geos_geom_clone = GEOSGeom_clone( geos_geom );
1980+
geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
19811981
}
19821982

19831983
//data defined position / alignment / rotation?
@@ -3532,7 +3532,7 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature&
35323532
}
35333533

35343534
//create PALGeometry with diagram = true
3535-
QgsPalGeometry* lbl = new QgsPalGeometry( feat.id(), "", GEOSGeom_clone( geos_geom ) );
3535+
QgsPalGeometry* lbl = new QgsPalGeometry( feat.id(), "", GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom ) );
35363536
lbl->setIsDiagram( true );
35373537

35383538
// record the created geometry - it will be deleted at the end.

‎src/plugins/topology/topolTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
589589

590590
int i = 0;
591591
ErrorList errorList;
592+
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
592593

593594
// could be enabled for lines and points too
594595
// so duplicate rule may be removed?
@@ -646,13 +647,13 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
646647

647648
QgsGeometry* polyGeom = QgsGeometry::fromPolygon( polygon );
648649

649-
geomList.push_back( GEOSGeom_clone( polyGeom->asGeos() ) );
650+
geomList.push_back( GEOSGeom_clone_r( geosctxt, polyGeom->asGeos() ) );
650651
}
651652

652653
}
653654
else
654655
{
655-
geomList.push_back( GEOSGeom_clone( g1->asGeos() ) );
656+
geomList.push_back( GEOSGeom_clone_r( geosctxt, g1->asGeos() ) );
656657
}
657658
}
658659

@@ -672,11 +673,11 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
672673
}
673674

674675
GEOSGeometry* collection = 0;
675-
collection = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, geomArray, geomList.size() );
676+
collection = GEOSGeom_createCollection_r( geosctxt, GEOS_MULTIPOLYGON, geomArray, geomList.size() );
676677

677678

678679
qDebug() << "performing cascaded union..might take time..-";
679-
GEOSGeometry* unionGeom = GEOSUnionCascaded( collection );
680+
GEOSGeometry* unionGeom = GEOSUnionCascaded_r( geosctxt, collection );
680681
//delete[] geomArray;
681682

682683
QgsGeometry test;
@@ -875,7 +876,7 @@ ErrorList topolTest::checkValid( double tolerance, QgsVectorLayer* layer1, QgsVe
875876
if ( !g->asGeos() )
876877
continue;
877878

878-
if ( !GEOSisValid( g->asGeos() ) )
879+
if ( !GEOSisValid_r( QgsGeometry::getGEOSHandler(), g->asGeos() ) )
879880
{
880881
QgsRectangle r = g->boundingBox();
881882
QList<FeatureLayer> fls;

0 commit comments

Comments
 (0)
Please sign in to comment.