Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
GEOS context accessor for PAL
  • Loading branch information
wonder-sk committed Sep 14, 2014
1 parent aafbc4e commit 0b72fc8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
11 changes: 5 additions & 6 deletions src/core/pal/feature.cpp
Expand Up @@ -39,7 +39,6 @@
#endif

#include <qglobal.h>
#include <qgsgeometry.h>

#include <cmath>
#include <cstring>
Expand Down Expand Up @@ -110,7 +109,7 @@ namespace pal

if ( ownsGeom )
{
GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), the_geom );
GEOSGeom_destroy_r( geosContext(), the_geom );
the_geom = NULL;
}
}
Expand All @@ -124,7 +123,7 @@ namespace pal
int i, j;

const GEOSCoordSequence *coordSeq;
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t geosctxt = geosContext();

type = GEOSGeomTypeId_r( geosctxt, geom );

Expand Down Expand Up @@ -1399,7 +1398,7 @@ namespace pal

void FeaturePart::addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] )
{
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t ctxt = geosContext();
int geomType = GEOSGeomTypeId_r( ctxt, the_geom );

double sizeCost = 0;
Expand Down Expand Up @@ -1439,12 +1438,12 @@ namespace pal

bool FeaturePart::isConnected( FeaturePart* p2 )
{
return ( GEOSTouches_r( QgsGeometry::getGEOSHandler(), the_geom, p2->the_geom ) == 1 );
return ( GEOSTouches_r( geosContext(), the_geom, p2->the_geom ) == 1 );
}

bool FeaturePart::mergeWithFeaturePart( FeaturePart* other )
{
GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t ctxt = geosContext();
GEOSGeometry* g1 = GEOSGeom_clone_r( ctxt, the_geom );
GEOSGeometry* g2 = GEOSGeom_clone_r( ctxt, other->the_geom );
GEOSGeometry* geoms[2] = { g1, g2 };
Expand Down
6 changes: 2 additions & 4 deletions src/core/pal/layer.cpp
Expand Up @@ -41,8 +41,6 @@
#include <cmath>
#include <vector>

#include <qgsgeometry.h>

#include <pal/pal.h>
#include <pal/layer.h>
#include <pal/palexception.h>
Expand Down Expand Up @@ -287,7 +285,7 @@ namespace pal
throw InternalException::UnknownGeometry();
}

GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t geosctxt = geosContext();

while ( simpleGeometries->size() > 0 )
{
Expand Down Expand Up @@ -496,7 +494,7 @@ namespace pal

void Layer::chopFeaturesAtRepeatDistance( )
{
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t geosctxt = geosContext();
LinkedList<FeaturePart*> * newFeatureParts = new LinkedList<FeaturePart*>( ptrFeaturePartCompare );
while ( FeaturePart* fpart = featureParts->pop_front() )
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/pal/pal.cpp
Expand Up @@ -63,6 +63,8 @@
#include "simplemutex.h"
#include "util.h"

#include <qgsgeometry.h> // for GEOS context

namespace pal
{

Expand All @@ -80,6 +82,11 @@ namespace pal
vfprintf( stdout, fmt, list );
}

GEOSContextHandle_t geosContext()
{
return QgsGeometry::getGEOSHandler();
}

Pal::Pal()
{
// do not init and exit GEOS - we do it inside QGIS
Expand Down
3 changes: 3 additions & 0 deletions src/core/pal/pal.h
Expand Up @@ -38,6 +38,7 @@
#include <QList>
#include <iostream>
#include <ctime>
#include <geos_c.h>

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

Expand All @@ -51,6 +52,8 @@

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

template <class Type> class LinkedList;

Expand Down
3 changes: 1 addition & 2 deletions src/core/pal/pointset.cpp
Expand Up @@ -39,7 +39,6 @@
#endif

#include <qglobal.h>
#include <qgsgeometry.h>

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

for ( int i = 0; i < nbPoints; ++i )
Expand Down
4 changes: 1 addition & 3 deletions src/core/pal/util.cpp
Expand Up @@ -42,8 +42,6 @@
#include <cstdarg>
#include <ctime>

#include "qgsgeometry.h"

#include <pal/layer.h>

#include "internalexception.h"
Expand Down Expand Up @@ -213,7 +211,7 @@ namespace pal
while ( queue->size() > 0 )
{
geom = queue->pop_front();
GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler();
GEOSContextHandle_t geosctxt = geosContext();
switch ( GEOSGeomTypeId_r( geosctxt, geom ) )
{
//case geos::geom::GEOS_MULTIPOINT:
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsgeometry.h
Expand Up @@ -83,7 +83,10 @@ class CORE_EXPORT QgsGeometry
//! Destructor
~QgsGeometry();

/** return GEOS context handle */
/** return GEOS context handle
* @note added in 2.6
* @note not available in Python
*/
static GEOSContextHandle_t getGEOSHandler();

/** static method that creates geometry from Wkt */
Expand Down

0 comments on commit 0b72fc8

Please sign in to comment.