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 ;
0 commit comments