Skip to content

Commit 0b72fc8

Browse files
committedSep 14, 2014
GEOS context accessor for PAL
1 parent aafbc4e commit 0b72fc8

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed
 

‎src/core/pal/feature.cpp

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

4141
#include <qglobal.h>
42-
#include <qgsgeometry.h>
4342

4443
#include <cmath>
4544
#include <cstring>
@@ -110,7 +109,7 @@ namespace pal
110109

111110
if ( ownsGeom )
112111
{
113-
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), the_geom );
112+
GEOSGeom_destroy_r( geosContext(), the_geom );
114113
the_geom = NULL;
115114
}
116115
}
@@ -124,7 +123,7 @@ namespace pal
124123
int i, j;
125124

126125
const GEOSCoordSequence *coordSeq;
127-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
126+
GEOSContextHandle_t geosctxt = geosContext();
128127

129128
type = GEOSGeomTypeId_r( geosctxt, geom );
130129

@@ -1399,7 +1398,7 @@ namespace pal
13991398

14001399
void FeaturePart::addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] )
14011400
{
1402-
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
1401+
GEOSContextHandle_t ctxt = geosContext();
14031402
int geomType = GEOSGeomTypeId_r( ctxt, the_geom );
14041403

14051404
double sizeCost = 0;
@@ -1439,12 +1438,12 @@ namespace pal
14391438

14401439
bool FeaturePart::isConnected( FeaturePart* p2 )
14411440
{
1442-
return ( GEOSTouches_r( QgsGeometry::getGEOSHandler(), the_geom, p2->the_geom ) == 1 );
1441+
return ( GEOSTouches_r( geosContext(), the_geom, p2->the_geom ) == 1 );
14431442
}
14441443

14451444
bool FeaturePart::mergeWithFeaturePart( FeaturePart* other )
14461445
{
1447-
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
1446+
GEOSContextHandle_t ctxt = geosContext();
14481447
GEOSGeometry* g1 = GEOSGeom_clone_r( ctxt, the_geom );
14491448
GEOSGeometry* g2 = GEOSGeom_clone_r( ctxt, other->the_geom );
14501449
GEOSGeometry* geoms[2] = { g1, g2 };

‎src/core/pal/layer.cpp

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

44-
#include <qgsgeometry.h>
45-
4644
#include <pal/pal.h>
4745
#include <pal/layer.h>
4846
#include <pal/palexception.h>
@@ -287,7 +285,7 @@ namespace pal
287285
throw InternalException::UnknownGeometry();
288286
}
289287

290-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
288+
GEOSContextHandle_t geosctxt = geosContext();
291289

292290
while ( simpleGeometries->size() > 0 )
293291
{
@@ -496,7 +494,7 @@ namespace pal
496494

497495
void Layer::chopFeaturesAtRepeatDistance( )
498496
{
499-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
497+
GEOSContextHandle_t geosctxt = geosContext();
500498
LinkedList<FeaturePart*> * newFeatureParts = new LinkedList<FeaturePart*>( ptrFeaturePartCompare );
501499
while ( FeaturePart* fpart = featureParts->pop_front() )
502500
{

‎src/core/pal/pal.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#include "simplemutex.h"
6464
#include "util.h"
6565

66+
#include <qgsgeometry.h> // for GEOS context
67+
6668
namespace pal
6769
{
6870

@@ -80,6 +82,11 @@ namespace pal
8082
vfprintf( stdout, fmt, list );
8183
}
8284

85+
GEOSContextHandle_t geosContext()
86+
{
87+
return QgsGeometry::getGEOSHandler();
88+
}
89+
8390
Pal::Pal()
8491
{
8592
// do not init and exit GEOS - we do it inside QGIS

‎src/core/pal/pal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <QList>
3939
#include <iostream>
4040
#include <ctime>
41+
#include <geos_c.h>
4142

4243
// TODO ${MAJOR} ${MINOR} etc instead of 0.2
4344

@@ -51,6 +52,8 @@
5152

5253
namespace pal
5354
{
55+
/** Get GEOS context handle to be used in all GEOS library calls with reentrant API */
56+
GEOSContextHandle_t geosContext();
5457

5558
template <class Type> class LinkedList;
5659

‎src/core/pal/pointset.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#endif
4040

4141
#include <qglobal.h>
42-
#include <qgsgeometry.h>
4342

4443
#include "pointset.h"
4544
#include "util.h"
@@ -989,7 +988,7 @@ namespace pal
989988
// check if centroid inside in polygon
990989
if ( forceInside && !isPointInPolygon( nbPoints, x, y, px, py ) )
991990
{
992-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
991+
GEOSContextHandle_t geosctxt = geosContext();
993992
GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, nbPoints, 2 );
994993

995994
for ( int i = 0; i < nbPoints; ++i )

‎src/core/pal/util.cpp

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

45-
#include "qgsgeometry.h"
46-
4745
#include <pal/layer.h>
4846

4947
#include "internalexception.h"
@@ -213,7 +211,7 @@ namespace pal
213211
while ( queue->size() > 0 )
214212
{
215213
geom = queue->pop_front();
216-
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
214+
GEOSContextHandle_t geosctxt = geosContext();
217215
switch ( GEOSGeomTypeId_r( geosctxt, geom ) )
218216
{
219217
//case geos::geom::GEOS_MULTIPOINT:

‎src/core/qgsgeometry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ class CORE_EXPORT QgsGeometry
8383
//! Destructor
8484
~QgsGeometry();
8585

86-
/** return GEOS context handle */
86+
/** return GEOS context handle
87+
* @note added in 2.6
88+
* @note not available in Python
89+
*/
8790
static GEOSContextHandle_t getGEOSHandler();
8891

8992
/** static method that creates geometry from Wkt */

0 commit comments

Comments
 (0)
Please sign in to comment.