From 6354dd3a31aeeb951e60adb7b98c744f32386396 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 17 Jun 2014 22:18:15 +0200 Subject: [PATCH] Use GEOS reentrant API (_r functions) and update requirement to GEOS >= 3.1.0 Currently QGIS uses the 'classic' GEOS API that uses a global context. This can conflict with libraries that would also use the global context and potentially finalize it whereas QGIS will still use it later. See https://groups.google.com/forum/#!topic/spatialite-users/9YSU6c5AVQ4 for such an example of such a recent issue with Spatialite. The _r API is available since GEOS 3.1.0, which is already an ancient GEOS version. For example, old-old-stable Ubuntu (Lucid 10.04) and Debian (squeeze) ship with GEOS 3.1.0 or later. Such move has also been done in GDAL 1.11 (http://lists.osgeo.org/pipermail/gdal-dev/2013-August/036877.html) and MapServer 7.0 (https://github.com/mapserver/mapserver/issues/4733) There's no easy way unfortunately to check at compile time that you don't use the non _r API. I have patched my geos_c.h header to #ifdef that API (quite painfull to do..). A postprocessing check can be done however with : objdump -T output/lib/*.so | grep -v Base | grep GEOS | grep -v _r | grep -v "_ZN" | grep -v GEOSversion It should return nothing. --- cmake/FindGEOS.cmake | 6 +- src/analysis/vector/qgsgeometryanalyzer.cpp | 23 +- src/analysis/vector/qgszonalstatistics.cpp | 17 +- src/app/qgsmaptooloffsetcurve.cpp | 2 +- src/core/pal/feature.cpp | 56 +- src/core/pal/layer.cpp | 36 +- src/core/pal/pointset.cpp | 22 +- src/core/pal/util.cpp | 9 +- src/core/qgsgeometry.cpp | 751 +++++++++----------- src/core/qgsgeometry.h | 10 +- src/core/qgsgeometryvalidator.cpp | 15 +- src/core/qgspalgeometry.h | 3 +- src/core/qgspallabeling.cpp | 4 +- src/plugins/topology/topolTest.cpp | 11 +- 14 files changed, 464 insertions(+), 501 deletions(-) diff --git a/cmake/FindGEOS.cmake b/cmake/FindGEOS.cmake index c73ff366ac5..d316042a8fe 100644 --- a/cmake/FindGEOS.cmake +++ b/cmake/FindGEOS.cmake @@ -84,9 +84,9 @@ ELSE(WIN32) STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GEOS_VERSION_MAJOR "${GEOS_VERSION}") STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GEOS_VERSION_MINOR "${GEOS_VERSION}") - IF (GEOS_VERSION_MAJOR LESS 3) - MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.0.0 or higher.") - ENDIF (GEOS_VERSION_MAJOR LESS 3) + IF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) ) + MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.1.0 or higher.") + ENDIF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 1) ) # set INCLUDE_DIR to prefix+include EXEC_PROGRAM(${GEOS_CONFIG} diff --git a/src/analysis/vector/qgsgeometryanalyzer.cpp b/src/analysis/vector/qgsgeometryanalyzer.cpp index 5ef3bd252c4..c104636d2fb 100644 --- a/src/analysis/vector/qgsgeometryanalyzer.cpp +++ b/src/analysis/vector/qgsgeometryanalyzer.cpp @@ -1100,6 +1100,7 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* QList outputGeomList; QList::const_iterator inputGeomIt = inputGeomList.constBegin(); + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); for ( ; inputGeomIt != inputGeomList.constEnd(); ++inputGeomIt ) { if ( geom->type() == QGis::Line ) @@ -1107,29 +1108,29 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* //geos 3.3 needed for line offsets #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) - GEOSGeometry* offsetGeom = GEOSOffsetCurve(( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ ); - if ( !offsetGeom || !GEOSisValid( offsetGeom ) ) + GEOSGeometry* offsetGeom = GEOSOffsetCurve_r(geosctxt, ( *inputGeomIt )->asGeos(), -offset, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ ); + if ( !offsetGeom || !GEOSisValid_r(geosctxt, offsetGeom ) ) { return false; } - if ( !GEOSisValid( offsetGeom ) || GEOSGeomTypeId( offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints( offsetGeom ) < 1 ) + if ( !GEOSisValid_r(geosctxt, offsetGeom ) || GEOSGeomTypeId_r(geosctxt, offsetGeom ) != GEOS_LINESTRING || GEOSGeomGetNumPoints_r(geosctxt, offsetGeom ) < 1 ) { - GEOSGeom_destroy( offsetGeom ); + GEOSGeom_destroy_r(geosctxt, offsetGeom ); return false; } outputGeomList.push_back( offsetGeom ); #else - outputGeomList.push_back( GEOSGeom_clone(( *inputGeomIt )->asGeos() ) ); + outputGeomList.push_back( GEOSGeom_clone_r(geosctxt, ( *inputGeomIt )->asGeos() ) ); #endif } else if ( geom->type() == QGis::Point ) { QgsPoint p = ( *inputGeomIt )->asPoint(); p = createPointOffset( p.x(), p.y(), offset, lineGeom ); - GEOSCoordSequence* ptSeq = GEOSCoordSeq_create( 1, 2 ); - GEOSCoordSeq_setX( ptSeq, 0, p.x() ); - GEOSCoordSeq_setY( ptSeq, 0, p.y() ); - GEOSGeometry* geosPt = GEOSGeom_createPoint( ptSeq ); + GEOSCoordSequence* ptSeq = GEOSCoordSeq_create_r(geosctxt, 1, 2 ); + GEOSCoordSeq_setX_r(geosctxt, ptSeq, 0, p.x() ); + GEOSCoordSeq_setY_r(geosctxt, ptSeq, 0, p.y() ); + GEOSGeometry* geosPt = GEOSGeom_createPoint_r(geosctxt, ptSeq ); outputGeomList.push_back( geosPt ); } } @@ -1152,11 +1153,11 @@ bool QgsGeometryAnalyzer::createOffsetGeometry( QgsGeometry* geom, QgsGeometry* GEOSGeometry* collection = 0; if ( geom->type() == QGis::Point ) { - collection = GEOSGeom_createCollection( GEOS_MULTIPOINT, geomArray, outputGeomList.size() ); + collection = GEOSGeom_createCollection_r(geosctxt, GEOS_MULTIPOINT, geomArray, outputGeomList.size() ); } else if ( geom->type() == QGis::Line ) { - collection = GEOSGeom_createCollection( GEOS_MULTILINESTRING, geomArray, outputGeomList.size() ); + collection = GEOSGeom_createCollection_r(geosctxt, GEOS_MULTILINESTRING, geomArray, outputGeomList.size() ); } geom->fromGeos( collection ); delete[] geomArray; diff --git a/src/analysis/vector/qgszonalstatistics.cpp b/src/analysis/vector/qgszonalstatistics.cpp index b2ab04501d5..bd1af06390d 100644 --- a/src/analysis/vector/qgszonalstatistics.cpp +++ b/src/analysis/vector/qgszonalstatistics.cpp @@ -281,7 +281,8 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry* return; } - const GEOSPreparedGeometry* polyGeosPrepared = GEOSPrepare( poly->asGeos() ); + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); + const GEOSPreparedGeometry* polyGeosPrepared = GEOSPrepare_r( geosctxt, poly->asGeos() ); if ( !polyGeosPrepared ) { return; @@ -300,15 +301,15 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry* cellCenterX = rasterBBox.xMinimum() + pixelOffsetX * cellSizeX + cellSizeX / 2; for ( int j = 0; j < nCellsX; ++j ) { - GEOSGeom_destroy( currentCellCenter ); - cellCenterCoords = GEOSCoordSeq_create( 1, 2 ); - GEOSCoordSeq_setX( cellCenterCoords, 0, cellCenterX ); - GEOSCoordSeq_setY( cellCenterCoords, 0, cellCenterY ); - currentCellCenter = GEOSGeom_createPoint( cellCenterCoords ); + GEOSGeom_destroy_r( geosctxt, currentCellCenter ); + cellCenterCoords = GEOSCoordSeq_create_r( geosctxt, 1, 2 ); + GEOSCoordSeq_setX_r( geosctxt, cellCenterCoords, 0, cellCenterX ); + GEOSCoordSeq_setY_r( geosctxt, cellCenterCoords, 0, cellCenterY ); + currentCellCenter = GEOSGeom_createPoint_r( geosctxt, cellCenterCoords ); if ( scanLine[j] != mInputNodataValue ) //don't consider nodata values { - if ( GEOSPreparedContains( polyGeosPrepared, currentCellCenter ) ) + if ( GEOSPreparedContains_r( geosctxt, polyGeosPrepared, currentCellCenter ) ) { if ( !qIsNaN( scanLine[j] ) ) { @@ -322,7 +323,7 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( void* band, QgsGeometry* cellCenterY -= cellSizeY; } CPLFree( scanLine ); - GEOSPreparedGeom_destroy( polyGeosPrepared ); + GEOSPreparedGeom_destroy_r( geosctxt, polyGeosPrepared ); } void QgsZonalStatistics::statisticsFromPreciseIntersection( void* band, QgsGeometry* poly, int pixelOffsetX, diff --git a/src/app/qgsmaptooloffsetcurve.cpp b/src/app/qgsmaptooloffsetcurve.cpp index 6b820327d31..c59b4e2765d 100644 --- a/src/app/qgsmaptooloffsetcurve.cpp +++ b/src/app/qgsmaptooloffsetcurve.cpp @@ -367,7 +367,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset, bool leftSide int quadSegments = s.value( "/qgis/digitizing/offset_quad_seg", 8 ).toInt(); double mitreLimit = s.value( "/qgis/digitizing/offset_miter_limit", 5.0 ).toDouble(); - GEOSGeometry* offsetGeom = GEOSOffsetCurve( geosGeom, leftSide ? offset : -offset, quadSegments, joinStyle, mitreLimit ); + GEOSGeometry* offsetGeom = GEOSOffsetCurve_r( QgsGeometry::getGEOSHandler(), geosGeom, leftSide ? offset : -offset, quadSegments, joinStyle, mitreLimit ); if ( !offsetGeom ) { deleteRubberBandAndGeometry(); diff --git a/src/core/pal/feature.cpp b/src/core/pal/feature.cpp index b63a3a46227..5f7965134e8 100644 --- a/src/core/pal/feature.cpp +++ b/src/core/pal/feature.cpp @@ -39,6 +39,7 @@ #endif #include +#include #include #include @@ -109,7 +110,7 @@ namespace pal if ( ownsGeom ) { - GEOSGeom_destroy( the_geom ); + GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), the_geom ); the_geom = NULL; } } @@ -123,15 +124,16 @@ namespace pal int i, j; const GEOSCoordSequence *coordSeq; + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); - type = GEOSGeomTypeId( geom ); + type = GEOSGeomTypeId_r( geosctxt, geom ); if ( type == GEOS_POLYGON ) { - if ( GEOSGetNumInteriorRings( geom ) > 0 ) + if ( GEOSGetNumInteriorRings_r( geosctxt, geom ) > 0 ) { // set nbHoles, holes member variables - nbHoles = GEOSGetNumInteriorRings( geom ); + nbHoles = GEOSGetNumInteriorRings_r( geosctxt, geom ); holes = new PointSet*[nbHoles]; for ( i = 0; i < nbHoles; i++ ) @@ -139,20 +141,20 @@ namespace pal holes[i] = new PointSet(); holes[i]->holeOf = NULL; - const GEOSGeometry* interior = GEOSGetInteriorRingN( geom, i ); - holes[i]->nbPoints = GEOSGetNumCoordinates( interior ); + const GEOSGeometry* interior = GEOSGetInteriorRingN_r( geosctxt, geom, i ); + holes[i]->nbPoints = GEOSGetNumCoordinates_r( geosctxt, interior ); holes[i]->x = new double[holes[i]->nbPoints]; holes[i]->y = new double[holes[i]->nbPoints]; holes[i]->xmin = holes[i]->ymin = DBL_MAX; holes[i]->xmax = holes[i]->ymax = -DBL_MAX; - coordSeq = GEOSGeom_getCoordSeq( interior ); + coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, interior ); for ( j = 0; j < holes[i]->nbPoints; j++ ) { - GEOSCoordSeq_getX( coordSeq, j, &holes[i]->x[j] ); - GEOSCoordSeq_getY( coordSeq, j, &holes[i]->y[j] ); + GEOSCoordSeq_getX_r( geosctxt, coordSeq, j, &holes[i]->x[j] ); + GEOSCoordSeq_getY_r( geosctxt, coordSeq, j, &holes[i]->y[j] ); holes[i]->xmax = holes[i]->x[j] > holes[i]->xmax ? holes[i]->x[j] : holes[i]->xmax; holes[i]->xmin = holes[i]->x[j] < holes[i]->xmin ? holes[i]->x[j] : holes[i]->xmin; @@ -166,7 +168,7 @@ namespace pal } // use exterior ring for the extraction of coordinates that follows - geom = GEOSGetExteriorRing( geom ); + geom = GEOSGetExteriorRing_r( geosctxt, geom ); } else { @@ -175,8 +177,8 @@ namespace pal } // find out number of points - nbPoints = GEOSGetNumCoordinates( geom ); - coordSeq = GEOSGeom_getCoordSeq( geom ); + nbPoints = GEOSGetNumCoordinates_r( geosctxt, geom ); + coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, geom ); // initialize bounding box xmin = ymin = DBL_MAX; @@ -188,8 +190,8 @@ namespace pal for ( i = 0; i < nbPoints; i++ ) { - GEOSCoordSeq_getX( coordSeq, i, &x[i] ); - GEOSCoordSeq_getY( coordSeq, i, &y[i] ); + GEOSCoordSeq_getX_r( geosctxt, coordSeq, i, &x[i] ); + GEOSCoordSeq_getY_r( geosctxt, coordSeq, i, &y[i] ); xmax = x[i] > xmax ? x[i] : xmax; xmin = x[i] < xmin ? x[i] : xmin; @@ -1393,13 +1395,14 @@ namespace pal void FeaturePart::addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4] ) { - int geomType = GEOSGeomTypeId( the_geom ); + GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler(); + int geomType = GEOSGeomTypeId_r( ctxt, the_geom ); double sizeCost = 0; if ( geomType == GEOS_LINESTRING ) { double length; - if ( GEOSLength( the_geom, &length ) != 1 ) + if ( GEOSLength_r( ctxt, the_geom, &length ) != 1 ) return; // failed to calculate length double bbox_length = max( bbx[2] - bbx[0], bby[2] - bby[0] ); if ( length >= bbox_length / 4 ) @@ -1410,7 +1413,7 @@ namespace pal else if ( geomType == GEOS_POLYGON ) { double area; - if ( GEOSArea( the_geom, &area ) != 1 ) + if ( GEOSArea_r( ctxt, the_geom, &area ) != 1 ) return; double bbox_area = ( bbx[2] - bbx[0] ) * ( bby[2] - bby[0] ); if ( area >= bbox_area / 16 ) @@ -1432,27 +1435,28 @@ namespace pal bool FeaturePart::isConnected( FeaturePart* p2 ) { - return ( GEOSTouches( the_geom, p2->the_geom ) == 1 ); + return ( GEOSTouches_r( QgsGeometry::getGEOSHandler(), the_geom, p2->the_geom ) == 1 ); } bool FeaturePart::mergeWithFeaturePart( FeaturePart* other ) { - GEOSGeometry* g1 = GEOSGeom_clone( the_geom ); - GEOSGeometry* g2 = GEOSGeom_clone( other->the_geom ); + GEOSContextHandle_t ctxt = QgsGeometry::getGEOSHandler(); + GEOSGeometry* g1 = GEOSGeom_clone_r( ctxt, the_geom ); + GEOSGeometry* g2 = GEOSGeom_clone_r( ctxt, other->the_geom ); GEOSGeometry* geoms[2] = { g1, g2 }; - GEOSGeometry* g = GEOSGeom_createCollection( GEOS_MULTILINESTRING, geoms, 2 ); - GEOSGeometry* gTmp = GEOSLineMerge( g ); - GEOSGeom_destroy( g ); + GEOSGeometry* g = GEOSGeom_createCollection_r( ctxt, GEOS_MULTILINESTRING, geoms, 2 ); + GEOSGeometry* gTmp = GEOSLineMerge_r( ctxt, g ); + GEOSGeom_destroy_r( ctxt, g ); - if ( GEOSGeomTypeId( gTmp ) != GEOS_LINESTRING ) + if ( GEOSGeomTypeId_r( ctxt, gTmp ) != GEOS_LINESTRING ) { // sometimes it's not possible to merge lines (e.g. they don't touch at endpoints) - GEOSGeom_destroy( gTmp ); + GEOSGeom_destroy_r( ctxt, gTmp ); return false; } if ( ownsGeom ) // delete old geometry if we own it - GEOSGeom_destroy( the_geom ); + GEOSGeom_destroy_r( ctxt, the_geom ); // set up new geometry the_geom = gTmp; ownsGeom = true; diff --git a/src/core/pal/layer.cpp b/src/core/pal/layer.cpp index 04fe9c24525..dd49e020b7d 100644 --- a/src/core/pal/layer.cpp +++ b/src/core/pal/layer.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -285,6 +286,7 @@ namespace pal throw InternalException::UnknownGeometry(); } + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); // if multiple labels are requested for lines, split the line in pieces of desired distance if ( repeatDistance > 0 ) { @@ -292,20 +294,20 @@ namespace pal for ( int i = 0; i < nSimpleGeometries; ++i ) { const GEOSGeometry* geom = simpleGeometries->pop_front(); - if ( GEOSGeomTypeId( geom ) == GEOS_LINESTRING ) + if ( GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING ) { - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom ); // get number of points unsigned int n; - GEOSCoordSeq_getSize( cs, &n ); + GEOSCoordSeq_getSize_r( geosctxt, cs, &n ); // Read points std::vector points( n ); for ( unsigned int i = 0; i < n; ++i ) { - GEOSCoordSeq_getX( cs, i, &points[i].x ); - GEOSCoordSeq_getY( cs, i, &points[i].y ); + GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x ); + GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y ); } // Cumulative length vector @@ -337,26 +339,26 @@ namespace pal p.x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x ); p.y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y ); part.push_back( p ); - GEOSCoordSequence* cooSeq = GEOSCoordSeq_create( part.size(), 2 ); + GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 ); for ( std::size_t i = 0; i < part.size(); ++i ) { - GEOSCoordSeq_setX( cooSeq, i, part[i].x ); - GEOSCoordSeq_setY( cooSeq, i, part[i].y ); + GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x ); + GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y ); } - simpleGeometries->push_back( GEOSGeom_createLineString( cooSeq ) ); + simpleGeometries->push_back( GEOSGeom_createLineString_r( geosctxt, cooSeq ) ); part.clear(); part.push_back( p ); } // Create final part part.push_back( points[n - 1] ); - GEOSCoordSequence* cooSeq = GEOSCoordSeq_create( part.size(), 2 ); + GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 ); for ( std::size_t i = 0; i < part.size(); ++i ) { - GEOSCoordSeq_setX( cooSeq, i, part[i].x ); - GEOSCoordSeq_setY( cooSeq, i, part[i].y ); + GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x ); + GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y ); } - simpleGeometries->push_back( GEOSGeom_createLineString( cooSeq ) ); + simpleGeometries->push_back( GEOSGeom_createLineString_r( geosctxt, cooSeq ) ); } else { @@ -370,13 +372,13 @@ namespace pal const GEOSGeometry* geom = simpleGeometries->pop_front(); // ignore invalid geometries (e.g. polygons with self-intersecting rings) - if ( GEOSisValid( geom ) != 1 ) // 0=invalid, 1=valid, 2=exception + if ( GEOSisValid_r( geosctxt, geom ) != 1 ) // 0=invalid, 1=valid, 2=exception { std::cerr << "ignoring invalid feature " << geom_id << std::endl; continue; } - int type = GEOSGeomTypeId( geom ); + int type = GEOSGeomTypeId_r( geosctxt, geom ); if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON ) { @@ -404,9 +406,9 @@ namespace pal if ( mode == LabelPerFeature && repeatDistance == 0.0 && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) ) { if ( type == GEOS_LINESTRING ) - GEOSLength( geom, &geom_size ); + GEOSLength_r( geosctxt, geom, &geom_size ); else if ( type == GEOS_POLYGON ) - GEOSArea( geom, &geom_size ); + GEOSArea_r( geosctxt, geom, &geom_size ); if ( geom_size > biggest_size ) { diff --git a/src/core/pal/pointset.cpp b/src/core/pal/pointset.cpp index df590f99041..6f1de64a15e 100644 --- a/src/core/pal/pointset.cpp +++ b/src/core/pal/pointset.cpp @@ -39,6 +39,7 @@ #endif #include +#include #include "pointset.h" #include "util.h" @@ -988,29 +989,30 @@ namespace pal // check if centroid inside in polygon if ( forceInside && !isPointInPolygon( nbPoints, x, y, px, py ) ) { - GEOSCoordSequence *coord = GEOSCoordSeq_create( nbPoints, 2 ); + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); + GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, nbPoints, 2 ); for ( int i = 0; i < nbPoints; ++i ) { - GEOSCoordSeq_setX( coord, i, x[i] ); - GEOSCoordSeq_setY( coord, i, y[i] ); + GEOSCoordSeq_setX_r( geosctxt, coord, i, x[i] ); + GEOSCoordSeq_setY_r( geosctxt, coord, i, y[i] ); } - GEOSGeometry *geom = GEOSGeom_createPolygon( GEOSGeom_createLinearRing( coord ), 0, 0 ); + GEOSGeometry *geom = GEOSGeom_createPolygon_r( geosctxt, GEOSGeom_createLinearRing_r( geosctxt, coord ), 0, 0 ); if ( geom ) { - GEOSGeometry *pointGeom = GEOSPointOnSurface( geom ); + GEOSGeometry *pointGeom = GEOSPointOnSurface_r( geosctxt, geom ); if ( pointGeom ) { - const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq( pointGeom ); - GEOSCoordSeq_getX( coordSeq, 0, &px ); - GEOSCoordSeq_getY( coordSeq, 0, &py ); + const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, pointGeom ); + GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, &px ); + GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, &py ); - GEOSGeom_destroy( pointGeom ); + GEOSGeom_destroy_r( geosctxt, pointGeom ); } - GEOSGeom_destroy( geom ); + GEOSGeom_destroy_r( geosctxt, geom ); } } } diff --git a/src/core/pal/util.cpp b/src/core/pal/util.cpp index 65d79bc34c1..ae4c1523d1c 100644 --- a/src/core/pal/util.cpp +++ b/src/core/pal/util.cpp @@ -42,6 +42,8 @@ #include #include +#include "qgsgeometry.h" + #include #include "internalexception.h" @@ -211,7 +213,8 @@ namespace pal while ( queue->size() > 0 ) { geom = queue->pop_front(); - switch ( GEOSGeomTypeId( geom ) ) + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); + switch ( GEOSGeomTypeId_r( geosctxt, geom ) ) { //case geos::geom::GEOS_MULTIPOINT: //case geos::geom::GEOS_MULTILINESTRING: @@ -219,10 +222,10 @@ namespace pal case GEOS_MULTIPOINT: case GEOS_MULTILINESTRING: case GEOS_MULTIPOLYGON: - nGeom = GEOSGetNumGeometries( geom ); + nGeom = GEOSGetNumGeometries_r( geosctxt, geom ); for ( i = 0; i < nGeom; i++ ) { - queue->push_back( GEOSGetGeometryN( geom, i ) ); + queue->push_back( GEOSGetGeometryN_r( geosctxt, geom, i ) ); } break; case GEOS_POINT: diff --git a/src/core/qgsgeometry.cpp b/src/core/qgsgeometry.cpp index 20e75aa5450..8f1b7f7a2f3 100644 --- a/src/core/qgsgeometry.cpp +++ b/src/core/qgsgeometry.cpp @@ -120,74 +120,26 @@ static void printGEOSNotice( const char *fmt, ... ) class GEOSInit { public: + GEOSContextHandle_t ctxt; + GEOSInit() { - initGEOS( printGEOSNotice, throwGEOSException ); + ctxt = initGEOS_r( printGEOSNotice, throwGEOSException ); } ~GEOSInit() { - finishGEOS(); + finishGEOS_r(ctxt); } }; static GEOSInit geosinit; - -#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3) -#define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g ) -#define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g ) -#define GEOSGetNumInteriorRings(g) GEOSGetNumInteriorRings( (GEOSGeometry *)g ) -#define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i ) -#define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 ) -#define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 ) -#define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s ) -#define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a ) -#define GEOSTopologyPreserveSimplify(g, t) GEOSTopologyPreserveSimplify( (GEOSGeometry*) g, t ) -#define GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g ) -#define GEOSPointOnSurface(g) GEOSPointOnSurface( (GEOSGeometry*) g ) - -#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n ) -#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x ) -#define GEOSCoordSeq_getY(cs,i,y) GEOSCoordSeq_getY( (GEOSCoordSequence *)cs, i, y ) - -static GEOSGeometry *createGeosCollection( int typeId, QVector geoms ); - -static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom ) +GEOSContextHandle_t QgsGeometry::getGEOSHandler() { - // for GEOS < 3.0 we have own cloning function - // because when cloning multipart geometries they're copied into more general geometry collection instance - int type = GEOSGeomTypeId(( GEOSGeometry * ) geom ); - - if ( type == GEOS_MULTIPOINT || type == GEOS_MULTILINESTRING || type == GEOS_MULTIPOLYGON ) - { - QVector geoms; - - try - { - for ( int i = 0; i < GEOSGetNumGeometries(( GEOSGeometry * )geom ); ++i ) - geoms << GEOSGeom_clone(( GEOSGeometry * ) GEOSGetGeometryN(( GEOSGeometry * ) geom, i ) ); - - return createGeosCollection( type, geoms ); - } - catch ( GEOSException &e ) - { - QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); - for ( int i = 0; i < geoms.count(); i++ ) - GEOSGeom_destroy( geoms[i] ); - - return 0; - } - } - else - { - return GEOSGeom_clone(( GEOSGeometry * ) geom ); - } + return geosinit.ctxt; } -#define GEOSGeom_clone(g) cloneGeosGeom(g) -#endif - QgsGeometry::QgsGeometry() : mGeometry( 0 ) , mGeometrySize( 0 ) @@ -211,7 +163,7 @@ QgsGeometry::QgsGeometry( QgsGeometry const & rhs ) // deep-copy the GEOS Geometry if appropriate if ( rhs.mGeos ) - mGeos = GEOSGeom_clone( rhs.mGeos ); + mGeos = GEOSGeom_clone_r( geosinit.ctxt, rhs.mGeos ); else mGeos = 0; @@ -224,24 +176,24 @@ QgsGeometry::~QgsGeometry() delete [] mGeometry; if ( mGeos ) - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); } static unsigned int getNumGeosPoints( const GEOSGeometry *geom ) { unsigned int n; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom ); - GEOSCoordSeq_getSize( cs, &n ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, geom ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, cs, &n ); return n; } static GEOSGeometry *createGeosPoint( const QgsPoint &point ) { - GEOSCoordSequence *coord = GEOSCoordSeq_create( 1, 2 ); - GEOSCoordSeq_setX( coord, 0, point.x() ); - GEOSCoordSeq_setY( coord, 0, point.y() ); - return GEOSGeom_createPoint( coord ); + GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosinit.ctxt, 1, 2 ); + GEOSCoordSeq_setX_r( geosinit.ctxt, coord, 0, point.x() ); + GEOSCoordSeq_setY_r( geosinit.ctxt, coord, 0, point.y() ); + return GEOSGeom_createPoint_r(geosinit.ctxt, coord ); } static GEOSCoordSequence *createGeosCoordSequence( const QgsPolyline& points ) @@ -250,12 +202,12 @@ static GEOSCoordSequence *createGeosCoordSequence( const QgsPolyline& points ) try { - coord = GEOSCoordSeq_create( points.count(), 2 ); + coord = GEOSCoordSeq_create_r( geosinit.ctxt, points.count(), 2 ); int i; for ( i = 0; i < points.count(); i++ ) { - GEOSCoordSeq_setX( coord, i, points[i].x() ); - GEOSCoordSeq_setY( coord, i, points[i].y() ); + GEOSCoordSeq_setX_r( geosinit.ctxt, coord, i, points[i].x() ); + GEOSCoordSeq_setY_r( geosinit.ctxt, coord, i, points[i].y() ); } return coord; } @@ -281,7 +233,7 @@ static GEOSGeometry *createGeosCollection( int typeId, QVector ge try { - geom = GEOSGeom_createCollection( typeId, geomarr, geoms.size() ); + geom = GEOSGeom_createCollection_r( geosinit.ctxt, typeId, geomarr, geoms.size() ); } catch ( GEOSException &e ) { @@ -300,7 +252,7 @@ static GEOSGeometry *createGeosLineString( const QgsPolyline& polyline ) try { coord = createGeosCoordSequence( polyline ); - return GEOSGeom_createLineString( coord ); + return GEOSGeom_createLineString_r( geosinit.ctxt, coord ); } catch ( GEOSException &e ) { @@ -333,7 +285,7 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline ) coord = createGeosCoordSequence( polyline ); } - return GEOSGeom_createLinearRing( coord ); + return GEOSGeom_createLinearRing_r( geosinit.ctxt, coord ); } catch ( GEOSException &e ) { @@ -353,9 +305,9 @@ static GEOSGeometry *createGeosPolygon( const QVector &rings ) { #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) - return GEOSGeom_createEmptyPolygon(); + return GEOSGeom_createEmptyPolygon_r(geosinit.ctxt); #else - shell = GEOSGeom_createLinearRing( GEOSCoordSeq_create( 0, 2 ) ); + shell = GEOSGeom_createLinearRing_r( geosinit.ctxt, GEOSCoordSeq_create_r( geosinit.ctxt, 0, 2 ) ); #endif } else @@ -377,7 +329,7 @@ static GEOSGeometry *createGeosPolygon( const QVector &rings ) holes[i] = rings[i+1]; } - GEOSGeometry *geom = GEOSGeom_createPolygon( shell, holes, nHoles ); + GEOSGeometry *geom = GEOSGeom_createPolygon_r( geosinit.ctxt, shell, holes, nHoles ); if ( holes ) delete [] holes; @@ -408,7 +360,7 @@ static GEOSGeometry *createGeosPolygon( const QgsPolygon& polygon ) { QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); for ( int i = 0; i < geoms.count(); i++ ) - GEOSGeom_destroy( geoms[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, geoms[i] ); return 0; } } @@ -427,14 +379,10 @@ QgsGeometry* QgsGeometry::fromWkt( QString wkt ) { try { -#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR>=3) - GEOSWKTReader *reader = GEOSWKTReader_create(); - QgsGeometry *g = fromGeosGeom( GEOSWKTReader_read( reader, wkt.toLocal8Bit().data() ) ); - GEOSWKTReader_destroy( reader ); + GEOSWKTReader *reader = GEOSWKTReader_create_r(geosinit.ctxt); + QgsGeometry *g = fromGeosGeom( GEOSWKTReader_read_r( geosinit.ctxt, reader, wkt.toLocal8Bit().data() ) ); + GEOSWKTReader_destroy_r( geosinit.ctxt, reader ); return g; -#else - return fromGeosGeom( GEOSGeomFromWKT( wkt.toLocal8Bit().data() ) ); -#endif } catch ( GEOSException &e ) { @@ -474,7 +422,7 @@ QgsGeometry* QgsGeometry::fromMultiPoint( const QgsMultiPoint& multipoint ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); for ( int i = 0; i < geoms.size(); ++i ) - GEOSGeom_destroy( geoms[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, geoms[i] ); return 0; } @@ -496,7 +444,7 @@ QgsGeometry* QgsGeometry::fromMultiPolyline( const QgsMultiPolyline& multiline ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); for ( int i = 0; i < geoms.count(); i++ ) - GEOSGeom_destroy( geoms[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, geoms[i] ); return 0; } @@ -521,7 +469,7 @@ QgsGeometry* QgsGeometry::fromMultiPolygon( const QgsMultiPolygon& multipoly ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); for ( int i = 0; i < geoms.count(); i++ ) - GEOSGeom_destroy( geoms[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, geoms[i] ); return 0; } @@ -558,8 +506,8 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs ) mGeometrySize = rhs.mGeometrySize; // deep-copy the GEOS Geometry if appropriate - GEOSGeom_destroy( mGeos ); - mGeos = rhs.mGeos ? GEOSGeom_clone( rhs.mGeos ) : 0; + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); + mGeos = rhs.mGeos ? GEOSGeom_clone_r( geosinit.ctxt, rhs.mGeos ) : 0; mDirtyGeos = rhs.mDirtyGeos; mDirtyWkb = rhs.mDirtyWkb; @@ -585,7 +533,7 @@ void QgsGeometry::fromWkb( unsigned char *wkb, size_t length ) if ( mGeos ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = 0; } @@ -687,7 +635,7 @@ void QgsGeometry::fromGeos( GEOSGeometry *geos ) if ( mGeos ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = 0; } @@ -1152,9 +1100,9 @@ bool QgsGeometry::insertVertex( double x, double y, } unsigned int numPoints; - GEOSCoordSeq_getSize( old_sequence, &numPoints ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, old_sequence, &numPoints ); - *new_sequence = GEOSCoordSeq_create( numPoints + 1, 2 ); + *new_sequence = GEOSCoordSeq_create_r( geosinit.ctxt, numPoints + 1, 2 ); if ( !*new_sequence ) return false; @@ -1164,26 +1112,26 @@ bool QgsGeometry::insertVertex( double x, double y, // Do we insert the new vertex here? if ( beforeVertex == static_cast( i ) ) { - GEOSCoordSeq_setX( *new_sequence, j, x ); - GEOSCoordSeq_setY( *new_sequence, j, y ); + GEOSCoordSeq_setX_r( geosinit.ctxt, *new_sequence, j, x ); + GEOSCoordSeq_setY_r( geosinit.ctxt, *new_sequence, j, y ); j++; inserted = true; } double aX, aY; - GEOSCoordSeq_getX( old_sequence, i, &aX ); - GEOSCoordSeq_getY( old_sequence, i, &aY ); + GEOSCoordSeq_getX_r( geosinit.ctxt, old_sequence, i, &aX ); + GEOSCoordSeq_getY_r( geosinit.ctxt, old_sequence, i, &aY ); - GEOSCoordSeq_setX( *new_sequence, j, aX ); - GEOSCoordSeq_setY( *new_sequence, j, aY ); + GEOSCoordSeq_setX_r( geosinit.ctxt, *new_sequence, j, aX ); + GEOSCoordSeq_setY_r( geosinit.ctxt, *new_sequence, j, aY ); } if ( !inserted ) { // The beforeVertex is greater than the actual number of vertices // in the geometry - append it. - GEOSCoordSeq_setX( *new_sequence, numPoints, x ); - GEOSCoordSeq_setY( *new_sequence, numPoints, y ); + GEOSCoordSeq_setX_r( geosinit.ctxt, *new_sequence, numPoints, x ); + GEOSCoordSeq_setY_r( geosinit.ctxt, *new_sequence, numPoints, y ); } // TODO: Check that the sequence is still simple, e.g. with GEOS_GEOM::Geometry->isSimple() @@ -1973,20 +1921,20 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert if ( !mGeos ) return -1; - const GEOSGeometry *g = GEOSGetExteriorRing( mGeos ); + const GEOSGeometry *g = GEOSGetExteriorRing_r( geosinit.ctxt, mGeos ); if ( !g ) return -1; - const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g ); + const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq_r( geosinit.ctxt, g ); unsigned int n; - GEOSCoordSeq_getSize( sequence, &n ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, sequence, &n ); for ( unsigned int i = 0; i < n; i++ ) { double x, y; - GEOSCoordSeq_getX( sequence, i, &x ); - GEOSCoordSeq_getY( sequence, i, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, sequence, i, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, sequence, i, &y ); double testDist = point.sqrDist( x, y ); if ( testDist < sqrDist ) @@ -2258,7 +2206,7 @@ int QgsGeometry::addRing( const QList& ring ) return 6; } - int type = GEOSGeomTypeId( mGeos ); + int type = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); //Fill GEOS Polygons of the feature into list QVector polygonList; @@ -2275,8 +2223,8 @@ int QgsGeometry::addRing( const QList& ring ) if ( type != GEOS_MULTIPOLYGON ) return 1; - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); ++i ) - polygonList << GEOSGetGeometryN( mGeos, i ); + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); ++i ) + polygonList << GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); } //create new ring @@ -2286,13 +2234,13 @@ int QgsGeometry::addRing( const QList& ring ) try { newRing = createGeosLinearRing( ring.toVector() ); - if ( !GEOSisValid( newRing ) ) + if ( !GEOSisValid_r( geosinit.ctxt, newRing ) ) { throwGEOSException( "ring is invalid" ); } newRingPolygon = createGeosPolygon( newRing ); - if ( !GEOSisValid( newRingPolygon ) ) + if ( !GEOSisValid_r( geosinit.ctxt, newRingPolygon ) ) { throwGEOSException( "ring is invalid" ); } @@ -2302,9 +2250,9 @@ int QgsGeometry::addRing( const QList& ring ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); if ( newRingPolygon ) - GEOSGeom_destroy( newRingPolygon ); + GEOSGeom_destroy_r( geosinit.ctxt, newRingPolygon ); else if ( newRing ) - GEOSGeom_destroy( newRing ); + GEOSGeom_destroy_r( geosinit.ctxt, newRing ); return 3; } @@ -2315,19 +2263,19 @@ int QgsGeometry::addRing( const QList& ring ) for ( i = 0; i < polygonList.size(); i++ ) { for ( int j = 0; j < rings.size(); j++ ) - GEOSGeom_destroy( rings[j] ); + GEOSGeom_destroy_r( geosinit.ctxt, rings[j] ); rings.clear(); GEOSGeometry *shellRing = 0; GEOSGeometry *shell = 0; try { - shellRing = GEOSGeom_clone( GEOSGetExteriorRing( polygonList[i] ) ); + shellRing = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetExteriorRing_r( geosinit.ctxt, polygonList[i] ) ); shell = createGeosPolygon( shellRing ); - if ( !GEOSWithin( newRingPolygon, shell ) ) + if ( !GEOSWithin_r( geosinit.ctxt, newRingPolygon, shell ) ) { - GEOSGeom_destroy( shell ); + GEOSGeom_destroy_r( geosinit.ctxt, shell ); continue; } } @@ -2336,22 +2284,22 @@ int QgsGeometry::addRing( const QList& ring ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); if ( shell ) - GEOSGeom_destroy( shell ); + GEOSGeom_destroy_r( geosinit.ctxt, shell ); else if ( shellRing ) - GEOSGeom_destroy( shellRing ); + GEOSGeom_destroy_r( geosinit.ctxt, shellRing ); - GEOSGeom_destroy( newRingPolygon ); + GEOSGeom_destroy_r( geosinit.ctxt, newRingPolygon ); return 4; } // add outer ring - rings << GEOSGeom_clone( shellRing ); + rings << GEOSGeom_clone_r( geosinit.ctxt, shellRing ); - GEOSGeom_destroy( shell ); + GEOSGeom_destroy_r( geosinit.ctxt, shell ); // check inner rings - int n = GEOSGetNumInteriorRings( polygonList[i] ); + int n = GEOSGetNumInteriorRings_r( geosinit.ctxt, polygonList[i] ); int j; for ( j = 0; j < n; j++ ) @@ -2360,12 +2308,12 @@ int QgsGeometry::addRing( const QList& ring ) GEOSGeometry *hole = 0; try { - holeRing = GEOSGeom_clone( GEOSGetInteriorRingN( polygonList[i], j ) ); + holeRing = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetInteriorRingN_r( geosinit.ctxt, polygonList[i], j ) ); hole = createGeosPolygon( holeRing ); - if ( !GEOSDisjoint( hole, newRingPolygon ) ) + if ( !GEOSDisjoint_r( geosinit.ctxt, hole, newRingPolygon ) ) { - GEOSGeom_destroy( hole ); + GEOSGeom_destroy_r( geosinit.ctxt, hole ); break; } } @@ -2374,15 +2322,15 @@ int QgsGeometry::addRing( const QList& ring ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); if ( hole ) - GEOSGeom_destroy( hole ); + GEOSGeom_destroy_r( geosinit.ctxt, hole ); else if ( holeRing ) - GEOSGeom_destroy( holeRing ); + GEOSGeom_destroy_r( geosinit.ctxt, holeRing ); break; } - rings << GEOSGeom_clone( holeRing ); - GEOSGeom_destroy( hole ); + rings << GEOSGeom_clone_r( geosinit.ctxt, holeRing ); + GEOSGeom_destroy_r( geosinit.ctxt, hole ); } if ( j == n ) @@ -2394,23 +2342,23 @@ int QgsGeometry::addRing( const QList& ring ) { // clear rings for ( int j = 0; j < rings.size(); j++ ) - GEOSGeom_destroy( rings[j] ); + GEOSGeom_destroy_r( geosinit.ctxt, rings[j] ); rings.clear(); - GEOSGeom_destroy( newRingPolygon ); + GEOSGeom_destroy_r( geosinit.ctxt, newRingPolygon ); // no containing polygon found return 5; } - rings << GEOSGeom_clone( newRing ); - GEOSGeom_destroy( newRingPolygon ); + rings << GEOSGeom_clone_r( geosinit.ctxt, newRing ); + GEOSGeom_destroy_r( geosinit.ctxt, newRingPolygon ); GEOSGeometry *newPolygon = createGeosPolygon( rings ); if ( wkbType() == QGis::WKBPolygon ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = newPolygon; } else if ( wkbType() == QGis::WKBMultiPolygon ) @@ -2419,10 +2367,10 @@ int QgsGeometry::addRing( const QList& ring ) for ( int j = 0; j < polygonList.size(); j++ ) { - newPolygons << ( i == j ? newPolygon : GEOSGeom_clone( polygonList[j] ) ); + newPolygons << ( i == j ? newPolygon : GEOSGeom_clone_r( geosinit.ctxt, polygonList[j] ) ); } - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = createGeosCollection( GEOS_MULTIPOLYGON, newPolygons ); } @@ -2499,7 +2447,7 @@ int QgsGeometry::addPart( const QList &points, QGis::GeometryType geom try { newRing = createGeosLinearRing( points.toVector() ); - if ( !GEOSisValid( newRing ) ) + if ( !GEOSisValid_r( geosinit.ctxt, newRing ) ) throw GEOSException( "ring invalid" ); newPart = createGeosPolygon( newRing ); @@ -2509,7 +2457,7 @@ int QgsGeometry::addPart( const QList &points, QGis::GeometryType geom QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); if ( newRing ) - GEOSGeom_destroy( newRing ); + GEOSGeom_destroy_r( geosinit.ctxt, newRing ); return 2; } @@ -2535,7 +2483,7 @@ int QgsGeometry::addPart( QgsGeometry *newPart ) return 4; const GEOSGeometry * geosPart = newPart->asGeos(); - return addPart( GEOSGeom_clone( geosPart ) ); + return addPart( GEOSGeom_clone_r( geosinit.ctxt, geosPart ) ); } int QgsGeometry::addPart( GEOSGeometry *newPart ) @@ -2560,13 +2508,13 @@ int QgsGeometry::addPart( GEOSGeometry *newPart ) return 4; } - int geosType = GEOSGeomTypeId( mGeos ); + int geosType = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); Q_ASSERT( newPart ); try { - if ( !GEOSisValid( newPart ) ) + if ( !GEOSisValid_r( geosinit.ctxt, newPart ) ) throw GEOSException( "new part geometry invalid" ); } catch ( GEOSException &e ) @@ -2574,7 +2522,7 @@ int QgsGeometry::addPart( GEOSGeometry *newPart ) QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); if ( newPart ) - GEOSGeom_destroy( newPart ); + GEOSGeom_destroy_r( geosinit.ctxt, newPart ); QgsDebugMsg( "part invalid: " + e.what() ); return 2; @@ -2583,37 +2531,37 @@ int QgsGeometry::addPart( GEOSGeometry *newPart ) QVector parts; //create new multipolygon - int n = GEOSGetNumGeometries( mGeos ); + int n = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); int i; for ( i = 0; i < n; ++i ) { - const GEOSGeometry *partN = GEOSGetGeometryN( mGeos, i ); + const GEOSGeometry *partN = GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); - if ( geomType == QGis::Polygon && GEOSOverlaps( partN, newPart ) ) + if ( geomType == QGis::Polygon && GEOSOverlaps_r( geosinit.ctxt, partN, newPart ) ) //bail out if new polygon overlaps with existing ones break; - parts << GEOSGeom_clone( partN ); + parts << GEOSGeom_clone_r( geosinit.ctxt, partN ); } if ( i < n ) { // bailed out for ( int i = 0; i < parts.size(); i++ ) - GEOSGeom_destroy( parts[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, parts[i] ); QgsDebugMsg( "new polygon part overlaps" ); return 3; } - int nPartGeoms = GEOSGetNumGeometries( newPart ); + int nPartGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, newPart ); for ( int i = 0; i < nPartGeoms; ++i ) { - parts << GEOSGeom_clone( GEOSGetGeometryN( newPart, i ) ); + parts << GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, newPart, i ) ); } - GEOSGeom_destroy( newPart ); + GEOSGeom_destroy_r( geosinit.ctxt, newPart ); - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = createGeosCollection( geosType, parts ); @@ -2875,7 +2823,7 @@ int QgsGeometry::splitGeometry( const QList& splitLine, QList& splitLine, QList& splitLine, QList& reshapeWithLine ) return 1; //single or multi? - int numGeoms = GEOSGetNumGeometries( mGeos ); + int numGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); if ( numGeoms == -1 ) return 1; bool isMultiGeom = false; - int geosTypeId = GEOSGeomTypeId( mGeos ); + int geosTypeId = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); if ( geosTypeId == GEOS_MULTILINESTRING || geosTypeId == GEOS_MULTIPOLYGON ) isMultiGeom = true; @@ -2973,10 +2921,10 @@ int QgsGeometry::reshapeGeometry( const QList& reshapeWithLine ) else reshapedGeometry = reshapePolygon( mGeos, reshapeLineGeos ); - GEOSGeom_destroy( reshapeLineGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, reshapeLineGeos ); if ( reshapedGeometry ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = reshapedGeometry; mDirtyWkb = true; return 0; @@ -2997,9 +2945,9 @@ int QgsGeometry::reshapeGeometry( const QList& reshapeWithLine ) for ( int i = 0; i < numGeoms; ++i ) { if ( isLine ) - currentReshapeGeometry = reshapeLine( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos ); + currentReshapeGeometry = reshapeLine( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos ); else - currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN( mGeos, i ), reshapeLineGeos ); + currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos ); if ( currentReshapeGeometry ) { @@ -3008,19 +2956,19 @@ int QgsGeometry::reshapeGeometry( const QList& reshapeWithLine ) } else { - newGeoms[i] = GEOSGeom_clone( GEOSGetGeometryN( mGeos, i ) ); + newGeoms[i] = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ) ); } } - GEOSGeom_destroy( reshapeLineGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, reshapeLineGeos ); GEOSGeometry* newMultiGeom = 0; if ( isLine ) { - newMultiGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, newGeoms, numGeoms ); + newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTILINESTRING, newGeoms, numGeoms ); } else //multipolygon { - newMultiGeom = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, newGeoms, numGeoms ); + newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTIPOLYGON, newGeoms, numGeoms ); } delete[] newGeoms; @@ -3029,14 +2977,14 @@ int QgsGeometry::reshapeGeometry( const QList& reshapeWithLine ) if ( reshapeTookPlace ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = newMultiGeom; mDirtyWkb = true; return 0; } else { - GEOSGeom_destroy( newMultiGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, newMultiGeom ); return 1; } } @@ -3054,10 +3002,10 @@ int QgsGeometry::makeDifference( QgsGeometry* other ) if ( !mGeos ) return 1; - if ( !GEOSisValid( mGeos ) ) + if ( !GEOSisValid_r( geosinit.ctxt, mGeos ) ) return 2; - if ( !GEOSisSimple( mGeos ) ) + if ( !GEOSisSimple_r( geosinit.ctxt, mGeos ) ) return 3; //convert other geometry to geos @@ -3070,12 +3018,12 @@ int QgsGeometry::makeDifference( QgsGeometry* other ) //make geometry::difference try { - if ( GEOSIntersects( mGeos, other->mGeos ) ) + if ( GEOSIntersects_r( geosinit.ctxt, mGeos, other->mGeos ) ) { //check if multitype before and after bool multiType = isMultipart(); - mGeos = GEOSDifference( mGeos, other->mGeos ); + mGeos = GEOSDifference_r( geosinit.ctxt, mGeos, other->mGeos ); mDirtyWkb = true; if ( multiType && !isMultipart() ) @@ -3358,7 +3306,7 @@ bool QgsGeometry::intersects( const QgsGeometry* geometry ) const return false; } - return GEOSIntersects( mGeos, geometry->mGeos ); + return GEOSIntersects_r( geosinit.ctxt, mGeos, geometry->mGeos ); } CATCH_GEOS( false ) } @@ -3386,7 +3334,7 @@ bool QgsGeometry::contains( const QgsPoint* p ) const try { geosPoint = createGeosPoint( *p ); - returnval = GEOSContains( mGeos, geosPoint ); + returnval = GEOSContains_r( geosinit.ctxt, mGeos, geosPoint ); } catch ( GEOSException &e ) { @@ -3395,13 +3343,13 @@ bool QgsGeometry::contains( const QgsPoint* p ) const } if ( geosPoint ) - GEOSGeom_destroy( geosPoint ); + GEOSGeom_destroy_r( geosinit.ctxt, geosPoint ); return returnval; } bool QgsGeometry::geosRelOp( - char( *op )( const GEOSGeometry*, const GEOSGeometry * ), + char( *op )( GEOSContextHandle_t handle, const GEOSGeometry*, const GEOSGeometry * ), const QgsGeometry *a, const QgsGeometry *b ) { @@ -3419,44 +3367,44 @@ bool QgsGeometry::geosRelOp( QgsDebugMsg( "GEOS geometry not available!" ); return false; } - return op( a->mGeos, b->mGeos ); + return op( geosinit.ctxt, a->mGeos, b->mGeos ); } CATCH_GEOS( false ) } bool QgsGeometry::contains( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSContains, this, geometry ); + return geosRelOp( GEOSContains_r, this, geometry ); } bool QgsGeometry::disjoint( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSDisjoint, this, geometry ); + return geosRelOp( GEOSDisjoint_r, this, geometry ); } bool QgsGeometry::equals( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSEquals, this, geometry ); + return geosRelOp( GEOSEquals_r, this, geometry ); } bool QgsGeometry::touches( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSTouches, this, geometry ); + return geosRelOp( GEOSTouches_r, this, geometry ); } bool QgsGeometry::overlaps( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSOverlaps, this, geometry ); + return geosRelOp( GEOSOverlaps_r, this, geometry ); } bool QgsGeometry::within( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSWithin, this, geometry ); + return geosRelOp( GEOSWithin_r, this, geometry ); } bool QgsGeometry::crosses( const QgsGeometry* geometry ) const { - return geosRelOp( GEOSCrosses, this, geometry ); + return geosRelOp( GEOSCrosses_r, this, geometry ); } QString QgsGeometry::exportToWkt() const @@ -3897,7 +3845,7 @@ bool QgsGeometry::exportWkbToGeos() const if ( mGeos ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = 0; } @@ -4130,7 +4078,7 @@ bool QgsGeometry::exportGeosToWkb() const // set up byteOrder char byteOrder = QgsApplication::endian(); - switch ( GEOSGeomTypeId( mGeos ) ) + switch ( GEOSGeomTypeId_r( geosinit.ctxt, mGeos ) ) { case GEOS_POINT: // a point { @@ -4140,11 +4088,11 @@ bool QgsGeometry::exportGeosToWkb() const mGeometry = new unsigned char[mGeometrySize]; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( mGeos ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, mGeos ); double x, y; - GEOSCoordSeq_getX( cs, 0, &x ); - GEOSCoordSeq_getY( cs, 0, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, 0, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, 0, &y ); QgsWkbPtr wkbPtr( mGeometry ); wkbPtr << byteOrder << QGis::WKBPoint << x << y; @@ -4157,9 +4105,9 @@ bool QgsGeometry::exportGeosToWkb() const { //QgsDebugMsg("Got a geos::GEOS_LINESTRING."); - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( mGeos ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, mGeos ); unsigned int nPoints; - GEOSCoordSeq_getSize( cs, &nPoints ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, cs, &nPoints ); // allocate some space for the WKB mGeometrySize = 1 + // sizeof(byte) @@ -4173,14 +4121,14 @@ bool QgsGeometry::exportGeosToWkb() const wkbPtr << byteOrder << QGis::WKBLineString << nPoints; - const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( mGeos ); + const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq_r( geosinit.ctxt, mGeos ); // assign points for ( unsigned int n = 0; n < nPoints; n++ ) { double x, y; - GEOSCoordSeq_getX( sequence, n, &x ); - GEOSCoordSeq_getY( sequence, n, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, sequence, n, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, sequence, n, &y ); wkbPtr << x << y; } @@ -4202,16 +4150,16 @@ bool QgsGeometry::exportGeosToWkb() const //first calculate the geometry size int geometrySize = 1 + 2 * sizeof( int ); //endian, type, number of rings - const GEOSGeometry *theRing = GEOSGetExteriorRing( mGeos ); + const GEOSGeometry *theRing = GEOSGetExteriorRing_r( geosinit.ctxt, mGeos ); if ( theRing ) { geometrySize += sizeof( int ); geometrySize += getNumGeosPoints( theRing ) * 2 * sizeof( double ); } - for ( int i = 0; i < GEOSGetNumInteriorRings( mGeos ); ++i ) + for ( int i = 0; i < GEOSGetNumInteriorRings_r( geosinit.ctxt, mGeos ); ++i ) { geometrySize += sizeof( int ); //number of points in ring - theRing = GEOSGetInteriorRingN( mGeos, i ); + theRing = GEOSGetInteriorRingN_r( geosinit.ctxt, mGeos, i ); if ( theRing ) { geometrySize += getNumGeosPoints( theRing ) * 2 * sizeof( double ); @@ -4224,46 +4172,46 @@ bool QgsGeometry::exportGeosToWkb() const //then fill the geometry itself into the wkb QgsWkbPtr wkbPtr( mGeometry ); - int nRings = GEOSGetNumInteriorRings( mGeos ) + 1; + int nRings = GEOSGetNumInteriorRings_r( geosinit.ctxt, mGeos ) + 1; wkbPtr << byteOrder << QGis::WKBPolygon << nRings; //exterior ring first - theRing = GEOSGetExteriorRing( mGeos ); + theRing = GEOSGetExteriorRing_r( geosinit.ctxt, mGeos ); if ( theRing ) { nPointsInRing = getNumGeosPoints( theRing ); wkbPtr << nPointsInRing; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, theRing ); unsigned int n; - GEOSCoordSeq_getSize( cs, &n ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, cs, &n ); for ( unsigned int j = 0; j < n; ++j ) { double x, y; - GEOSCoordSeq_getX( cs, j, &x ); - GEOSCoordSeq_getY( cs, j, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, j, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, j, &y ); wkbPtr << x << y; } } //interior rings after - for ( int i = 0; i < GEOSGetNumInteriorRings( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumInteriorRings_r( geosinit.ctxt, mGeos ); i++ ) { - theRing = GEOSGetInteriorRingN( mGeos, i ); + theRing = GEOSGetInteriorRingN_r( geosinit.ctxt, mGeos, i ); - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, theRing ); unsigned int nPointsInRing; - GEOSCoordSeq_getSize( cs, &nPointsInRing ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, cs, &nPointsInRing ); wkbPtr << nPointsInRing; for ( unsigned int j = 0; j < nPointsInRing; j++ ) { double x, y; - GEOSCoordSeq_getX( cs, j, &x ); - GEOSCoordSeq_getY( cs, j, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, j, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, j, &y ); wkbPtr << x << y; } } @@ -4276,7 +4224,7 @@ bool QgsGeometry::exportGeosToWkb() const { // determine size of geometry int geometrySize = 1 + 2 * sizeof( int ); - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { geometrySize += 1 + sizeof( int ) + 2 * sizeof( double ); } @@ -4285,22 +4233,22 @@ bool QgsGeometry::exportGeosToWkb() const mGeometrySize = geometrySize; QgsWkbPtr wkbPtr( mGeometry ); - int numPoints = GEOSGetNumGeometries( mGeos ); + int numPoints = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); wkbPtr << byteOrder << QGis::WKBMultiPoint << numPoints; - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { //copy endian and point type wkbPtr << byteOrder << QGis::WKBPoint; - const GEOSGeometry *currentPoint = GEOSGetGeometryN( mGeos, i ); + const GEOSGeometry *currentPoint = GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( currentPoint ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, currentPoint ); double x, y; - GEOSCoordSeq_getX( cs, 0, &x ); - GEOSCoordSeq_getY( cs, 0, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, 0, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, 0, &y ); wkbPtr << x << y; } mDirtyWkb = false; @@ -4311,10 +4259,10 @@ bool QgsGeometry::exportGeosToWkb() const { // determine size of geometry int geometrySize = 1 + 2 * sizeof( int ); - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { geometrySize += 1 + 2 * sizeof( int ); - geometrySize += getNumGeosPoints( GEOSGetGeometryN( mGeos, i ) ) * 2 * sizeof( double ); + geometrySize += getNumGeosPoints( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ) ) * 2 * sizeof( double ); } mGeometry = new unsigned char[geometrySize]; @@ -4322,28 +4270,28 @@ bool QgsGeometry::exportGeosToWkb() const QgsWkbPtr wkbPtr( mGeometry ); - int numLines = GEOSGetNumGeometries( mGeos ); + int numLines = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); wkbPtr << byteOrder << QGis::WKBMultiLineString << numLines; //loop over lines - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { //endian and type WKBLineString wkbPtr << byteOrder << QGis::WKBLineString; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( GEOSGetGeometryN( mGeos, i ) ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ) ); //line size unsigned int lineSize; - GEOSCoordSeq_getSize( cs, &lineSize ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, cs, &lineSize ); wkbPtr << lineSize; //vertex coordinates for ( unsigned int j = 0; j < lineSize; ++j ) { double x, y; - GEOSCoordSeq_getX( cs, j, &x ); - GEOSCoordSeq_getY( cs, j, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, j, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, j, &y ); wkbPtr << x << y; } } @@ -4355,20 +4303,20 @@ bool QgsGeometry::exportGeosToWkb() const { //first determine size of geometry int geometrySize = 1 + 2 * sizeof( int ); //endian, type, number of polygons - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { - const GEOSGeometry *thePoly = GEOSGetGeometryN( mGeos, i ); + const GEOSGeometry *thePoly = GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); geometrySize += 1 + 2 * sizeof( int ); //endian, type, number of rings //exterior ring geometrySize += sizeof( int ); //number of points in exterior ring - const GEOSGeometry *exRing = GEOSGetExteriorRing( thePoly ); + const GEOSGeometry *exRing = GEOSGetExteriorRing_r( geosinit.ctxt, thePoly ); geometrySize += 2 * sizeof( double ) * getNumGeosPoints( exRing ); const GEOSGeometry *intRing = 0; - for ( int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ ) + for ( int j = 0; j < GEOSGetNumInteriorRings_r( geosinit.ctxt, thePoly ); j++ ) { geometrySize += sizeof( int ); //number of points in ring - intRing = GEOSGetInteriorRingN( thePoly, j ); + intRing = GEOSGetInteriorRingN_r( geosinit.ctxt, thePoly, j ); geometrySize += 2 * sizeof( double ) * getNumGeosPoints( intRing ); } } @@ -4377,46 +4325,46 @@ bool QgsGeometry::exportGeosToWkb() const mGeometrySize = geometrySize; QgsWkbPtr wkbPtr( mGeometry ); - int numPolygons = GEOSGetNumGeometries( mGeos ); + int numPolygons = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); wkbPtr << byteOrder << QGis::WKBMultiPolygon << numPolygons; //loop over polygons - for ( int i = 0; i < GEOSGetNumGeometries( mGeos ); i++ ) + for ( int i = 0; i < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); i++ ) { - const GEOSGeometry *thePoly = GEOSGetGeometryN( mGeos, i ); - int numRings = GEOSGetNumInteriorRings( thePoly ) + 1; + const GEOSGeometry *thePoly = GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); + int numRings = GEOSGetNumInteriorRings_r( geosinit.ctxt, thePoly ) + 1; //exterior ring - const GEOSGeometry *theRing = GEOSGetExteriorRing( thePoly ); + const GEOSGeometry *theRing = GEOSGetExteriorRing_r( geosinit.ctxt, thePoly ); int nPointsInRing = getNumGeosPoints( theRing ); wkbPtr << byteOrder << QGis::WKBPolygon << numRings << nPointsInRing; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, theRing ); for ( int k = 0; k < nPointsInRing; ++k ) { double x, y; - GEOSCoordSeq_getX( cs, k, &x ); - GEOSCoordSeq_getY( cs, k, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, k, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, k, &y ); wkbPtr << x << y; } //interior rings - for ( int j = 0; j < GEOSGetNumInteriorRings( thePoly ); j++ ) + for ( int j = 0; j < GEOSGetNumInteriorRings_r( geosinit.ctxt, thePoly ); j++ ) { - theRing = GEOSGetInteriorRingN( thePoly, j ); + theRing = GEOSGetInteriorRingN_r( geosinit.ctxt, thePoly, j ); int nPointsInRing = getNumGeosPoints( theRing ); wkbPtr << nPointsInRing; - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( theRing ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, theRing ); for ( int k = 0; k < nPointsInRing; ++k ) { double x, y; - GEOSCoordSeq_getX( cs, k, &x ); - GEOSCoordSeq_getY( cs, k, &y ); + GEOSCoordSeq_getX_r( geosinit.ctxt, cs, k, &x ); + GEOSCoordSeq_getY_r( geosinit.ctxt, cs, k, &y ); wkbPtr << x << y; } } @@ -4565,7 +4513,7 @@ void QgsGeometry::transformVertex( QgsWkbPtr &wkbPtr, const QgsCoordinateTransfo GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint ) { - int type = GEOSGeomTypeId( mGeos ); + int type = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); QgsMultiPolyline multiLine; if ( type == GEOS_MULTILINESTRING ) @@ -4602,7 +4550,7 @@ GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint ) lines.append( newline ); } QgsGeometry* splitLines = fromMultiPolyline( lines ); - GEOSGeometry* splitGeom = GEOSGeom_clone( splitLines->asGeos() ); + GEOSGeometry* splitGeom = GEOSGeom_clone_r( geosinit.ctxt, splitLines->asGeos() ); return splitGeom; @@ -4620,15 +4568,15 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList 0 ) return 3; - int splitGeomType = GEOSGeomTypeId( splitLine ); + int splitGeomType = GEOSGeomTypeId_r( geosinit.ctxt, splitLine ); GEOSGeometry* splitGeom; if ( splitGeomType == GEOS_POINT ) @@ -4637,28 +4585,28 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList lineGeoms; - int splitType = GEOSGeomTypeId( splitGeom ); + int splitType = GEOSGeomTypeId_r( geosinit.ctxt, splitGeom ); if ( splitType == GEOS_MULTILINESTRING ) { - int nGeoms = GEOSGetNumGeometries( splitGeom ); + int nGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, splitGeom ); for ( int i = 0; i < nGeoms; ++i ) - lineGeoms << GEOSGeom_clone( GEOSGetGeometryN( splitGeom, i ) ); + lineGeoms << GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, splitGeom, i ) ); } else { - lineGeoms << GEOSGeom_clone( splitGeom ); + lineGeoms << GEOSGeom_clone_r( geosinit.ctxt, splitGeom ); } mergeGeometriesMultiTypeSplit( lineGeoms ); if ( lineGeoms.size() > 0 ) { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = lineGeoms[0]; mDirtyWkb = true; } @@ -4668,7 +4616,7 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList 0.99 && areaRatio < 1.01 ) - testedGeometries << GEOSGeom_clone( polygon ); + testedGeometries << GEOSGeom_clone_r( geosinit.ctxt, polygon ); - GEOSGeom_destroy( intersectGeometry ); + GEOSGeom_destroy_r( geosinit.ctxt, intersectGeometry ); } bool splitDone = true; @@ -4750,25 +4698,25 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList 0 ) //split successfull { - GEOSGeom_destroy( mGeos ); + GEOSGeom_destroy_r( geosinit.ctxt, mGeos ); mGeos = testedGeometries[0]; mDirtyWkb = true; } int i; - for ( i = 1; i < testedGeometries.size() && GEOSisValid( testedGeometries[i] ); ++i ) + for ( i = 1; i < testedGeometries.size() && GEOSisValid_r( geosinit.ctxt, testedGeometries[i] ); ++i ) ; if ( i < testedGeometries.size() ) { for ( i = 0; i < testedGeometries.size(); ++i ) - GEOSGeom_destroy( testedGeometries[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, testedGeometries[i] ); return 3; } @@ -4776,7 +4724,7 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList ringList; if ( nRings > 0 ) { - GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon( GEOSGeom_clone( newOuterRing ), 0, 0 ); + GEOSGeometry* outerRingPoly = GEOSGeom_createPolygon_r( geosinit.ctxt, GEOSGeom_clone_r( geosinit.ctxt, newOuterRing ), 0, 0 ); if ( outerRingPoly ) { GEOSGeometry* currentRing = 0; @@ -4869,16 +4817,16 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE if ( lastIntersectingRing == i ) currentRing = newRing; else - currentRing = GEOSGeom_clone( innerRings[i] ); + currentRing = GEOSGeom_clone_r( geosinit.ctxt, innerRings[i] ); //possibly a ring is no longer contained in the result polygon after reshape - if ( GEOSContains( outerRingPoly, currentRing ) == 1 ) + if ( GEOSContains_r( geosinit.ctxt, outerRingPoly, currentRing ) == 1 ) ringList.push_back( currentRing ); else - GEOSGeom_destroy( currentRing ); + GEOSGeom_destroy_r( geosinit.ctxt, currentRing ); } } - GEOSGeom_destroy( outerRingPoly ); + GEOSGeom_destroy_r( geosinit.ctxt, outerRingPoly ); } GEOSGeometry** newInnerRings = new GEOSGeometry*[ringList.size()]; @@ -4887,7 +4835,7 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE delete [] innerRings; - GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon( newOuterRing, newInnerRings, ringList.size() ); + GEOSGeometry* reshapedPolygon = GEOSGeom_createPolygon_r( geosinit.ctxt, newOuterRing, newInnerRings, ringList.size() ); delete[] newInnerRings; return reshapedPolygon; @@ -4903,11 +4851,11 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom try { //make sure there are at least two intersection between line and reshape geometry - GEOSGeometry* intersectGeom = GEOSIntersection( line, reshapeLineGeos ); + GEOSGeometry* intersectGeom = GEOSIntersection_r( geosinit.ctxt, line, reshapeLineGeos ); if ( intersectGeom ) { - atLeastTwoIntersections = ( GEOSGeomTypeId( intersectGeom ) == GEOS_MULTIPOINT && GEOSGetNumGeometries( intersectGeom ) > 1 ); - GEOSGeom_destroy( intersectGeom ); + atLeastTwoIntersections = ( GEOSGeomTypeId_r( geosinit.ctxt, intersectGeom ) == GEOS_MULTIPOINT && GEOSGetNumGeometries_r( geosinit.ctxt, intersectGeom ) > 1 ); + GEOSGeom_destroy_r( geosinit.ctxt, intersectGeom ); } } catch ( GEOSException &e ) @@ -4920,12 +4868,12 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom return 0; //begin and end point of original line - const GEOSCoordSequence* lineCoordSeq = GEOSGeom_getCoordSeq( line ); + const GEOSCoordSequence* lineCoordSeq = GEOSGeom_getCoordSeq_r( geosinit.ctxt, line ); if ( !lineCoordSeq ) return 0; unsigned int lineCoordSeqSize; - if ( GEOSCoordSeq_getSize( lineCoordSeq, &lineCoordSeqSize ) == 0 ) + if ( GEOSCoordSeq_getSize_r( geosinit.ctxt, lineCoordSeq, &lineCoordSeqSize ) == 0 ) return 0; if ( lineCoordSeqSize < 2 ) @@ -4933,43 +4881,43 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom //first and last vertex of line double x1, y1, x2, y2; - GEOSCoordSeq_getX( lineCoordSeq, 0, &x1 ); - GEOSCoordSeq_getY( lineCoordSeq, 0, &y1 ); - GEOSCoordSeq_getX( lineCoordSeq, lineCoordSeqSize - 1, &x2 ); - GEOSCoordSeq_getY( lineCoordSeq, lineCoordSeqSize - 1, &y2 ); + GEOSCoordSeq_getX_r( geosinit.ctxt, lineCoordSeq, 0, &x1 ); + GEOSCoordSeq_getY_r( geosinit.ctxt, lineCoordSeq, 0, &y1 ); + GEOSCoordSeq_getX_r( geosinit.ctxt, lineCoordSeq, lineCoordSeqSize - 1, &x2 ); + GEOSCoordSeq_getY_r( geosinit.ctxt, lineCoordSeq, lineCoordSeqSize - 1, &y2 ); GEOSGeometry* beginLineVertex = createGeosPoint( QgsPoint( x1, y1 ) ); GEOSGeometry* endLineVertex = createGeosPoint( QgsPoint( x2, y2 ) ); bool isRing = false; - if ( GEOSGeomTypeId( line ) == GEOS_LINEARRING || GEOSEquals( beginLineVertex, endLineVertex ) == 1 ) + if ( GEOSGeomTypeId_r( geosinit.ctxt, line ) == GEOS_LINEARRING || GEOSEquals_r( geosinit.ctxt, beginLineVertex, endLineVertex ) == 1 ) isRing = true; //node line and reshape line GEOSGeometry* nodedGeometry = nodeGeometries( reshapeLineGeos, line ); if ( !nodedGeometry ) { - GEOSGeom_destroy( beginLineVertex ); - GEOSGeom_destroy( endLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, beginLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, endLineVertex ); return 0; } //and merge them together - GEOSGeometry *mergedLines = GEOSLineMerge( nodedGeometry ); - GEOSGeom_destroy( nodedGeometry ); + GEOSGeometry *mergedLines = GEOSLineMerge_r( geosinit.ctxt, nodedGeometry ); + GEOSGeom_destroy_r( geosinit.ctxt, nodedGeometry ); if ( !mergedLines ) { - GEOSGeom_destroy( beginLineVertex ); - GEOSGeom_destroy( endLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, beginLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, endLineVertex ); return 0; } - int numMergedLines = GEOSGetNumGeometries( mergedLines ); + int numMergedLines = GEOSGetNumGeometries_r( geosinit.ctxt, mergedLines ); if ( numMergedLines < 2 ) //some special cases. Normally it is >2 { - GEOSGeom_destroy( beginLineVertex ); - GEOSGeom_destroy( endLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, beginLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, endLineVertex ); if ( numMergedLines == 1 ) //reshape line is from begin to endpoint. So we keep the reshapeline - return GEOSGeom_clone( reshapeLineGeos ); + return GEOSGeom_clone_r( geosinit.ctxt, reshapeLineGeos ); else return 0; } @@ -4981,19 +4929,19 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom { const GEOSGeometry* currentGeom; - currentGeom = GEOSGetGeometryN( mergedLines, i ); - const GEOSCoordSequence* currentCoordSeq = GEOSGeom_getCoordSeq( currentGeom ); + currentGeom = GEOSGetGeometryN_r( geosinit.ctxt, mergedLines, i ); + const GEOSCoordSequence* currentCoordSeq = GEOSGeom_getCoordSeq_r( geosinit.ctxt, currentGeom ); unsigned int currentCoordSeqSize; - GEOSCoordSeq_getSize( currentCoordSeq, ¤tCoordSeqSize ); + GEOSCoordSeq_getSize_r( geosinit.ctxt, currentCoordSeq, ¤tCoordSeqSize ); if ( currentCoordSeqSize < 2 ) continue; //get the two endpoints of the current line merge result double xBegin, xEnd, yBegin, yEnd; - GEOSCoordSeq_getX( currentCoordSeq, 0, &xBegin ); - GEOSCoordSeq_getY( currentCoordSeq, 0, &yBegin ); - GEOSCoordSeq_getX( currentCoordSeq, currentCoordSeqSize - 1, &xEnd ); - GEOSCoordSeq_getY( currentCoordSeq, currentCoordSeqSize - 1, &yEnd ); + GEOSCoordSeq_getX_r( geosinit.ctxt, currentCoordSeq, 0, &xBegin ); + GEOSCoordSeq_getY_r( geosinit.ctxt, currentCoordSeq, 0, &yBegin ); + GEOSCoordSeq_getX_r( geosinit.ctxt, currentCoordSeq, currentCoordSeqSize - 1, &xEnd ); + GEOSCoordSeq_getY_r( geosinit.ctxt, currentCoordSeq, currentCoordSeqSize - 1, &yEnd ); GEOSGeometry* beginCurrentGeomVertex = createGeosPoint( QgsPoint( xBegin, yBegin ) ); GEOSGeometry* endCurrentGeomVertex = createGeosPoint( QgsPoint( xEnd, yEnd ) ); @@ -5007,10 +4955,10 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom //check how many endpoints equal the endpoints of the original line int nEndpointsSameAsOriginalLine = 0; - if ( GEOSEquals( beginCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( beginCurrentGeomVertex, endLineVertex ) == 1 ) + if ( GEOSEquals_r( geosinit.ctxt, beginCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals_r( geosinit.ctxt, beginCurrentGeomVertex, endLineVertex ) == 1 ) nEndpointsSameAsOriginalLine += 1; - if ( GEOSEquals( endCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals( endCurrentGeomVertex, endLineVertex ) == 1 ) + if ( GEOSEquals_r( geosinit.ctxt, endCurrentGeomVertex, beginLineVertex ) == 1 || GEOSEquals_r( geosinit.ctxt, endCurrentGeomVertex, endLineVertex ) == 1 ) nEndpointsSameAsOriginalLine += 1; //check if the current geometry overlaps the original geometry (GEOSOverlap does not seem to work with linestrings) @@ -5025,28 +4973,28 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom //logic to decide if this part belongs to the result if ( nEndpointsSameAsOriginalLine == 1 && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom ) { - resultLineParts.push_back( GEOSGeom_clone( currentGeom ) ); + resultLineParts.push_back( GEOSGeom_clone_r( geosinit.ctxt, currentGeom ) ); } //for closed rings, we take one segment from the candidate list else if ( isRing && nEndpointsOnOriginalLine == 2 && currentGeomOverlapsOriginalGeom ) { - probableParts.push_back( GEOSGeom_clone( currentGeom ) ); + probableParts.push_back( GEOSGeom_clone_r( geosinit.ctxt, currentGeom ) ); } else if ( nEndpointsOnOriginalLine == 2 && !currentGeomOverlapsOriginalGeom ) { - resultLineParts.push_back( GEOSGeom_clone( currentGeom ) ); + resultLineParts.push_back( GEOSGeom_clone_r( geosinit.ctxt, currentGeom ) ); } else if ( nEndpointsSameAsOriginalLine == 2 && !currentGeomOverlapsOriginalGeom ) { - resultLineParts.push_back( GEOSGeom_clone( currentGeom ) ); + resultLineParts.push_back( GEOSGeom_clone_r( geosinit.ctxt, currentGeom ) ); } else if ( currentGeomOverlapsOriginalGeom && currentGeomOverlapsReshapeLine ) { - resultLineParts.push_back( GEOSGeom_clone( currentGeom ) ); + resultLineParts.push_back( GEOSGeom_clone_r( geosinit.ctxt, currentGeom ) ); } - GEOSGeom_destroy( beginCurrentGeomVertex ); - GEOSGeom_destroy( endCurrentGeomVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, beginCurrentGeomVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, endCurrentGeomVertex ); } //add the longest segment from the probable list for rings (only used for polygon rings) @@ -5059,24 +5007,24 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom for ( int i = 0; i < probableParts.size(); ++i ) { currentGeom = probableParts.at( i ); - GEOSLength( currentGeom, ¤tLength ); + GEOSLength_r( geosinit.ctxt, currentGeom, ¤tLength ); if ( currentLength > maxLength ) { maxLength = currentLength; - GEOSGeom_destroy( maxGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, maxGeom ); maxGeom = currentGeom; } else { - GEOSGeom_destroy( currentGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, currentGeom ); } } resultLineParts.push_back( maxGeom ); } - GEOSGeom_destroy( beginLineVertex ); - GEOSGeom_destroy( endLineVertex ); - GEOSGeom_destroy( mergedLines ); + GEOSGeom_destroy_r( geosinit.ctxt, beginLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, endLineVertex ); + GEOSGeom_destroy_r( geosinit.ctxt, mergedLines ); GEOSGeometry* result = 0; if ( resultLineParts.size() < 1 ) @@ -5095,18 +5043,18 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom } //create multiline from resultLineParts - GEOSGeometry* multiLineGeom = GEOSGeom_createCollection( GEOS_MULTILINESTRING, lineArray, resultLineParts.size() ); + GEOSGeometry* multiLineGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTILINESTRING, lineArray, resultLineParts.size() ); delete [] lineArray; //then do a linemerge with the newly combined partstrings - result = GEOSLineMerge( multiLineGeom ); - GEOSGeom_destroy( multiLineGeom ); + result = GEOSLineMerge_r( geosinit.ctxt, multiLineGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, multiLineGeom ); } //now test if the result is a linestring. Otherwise something went wrong - if ( GEOSGeomTypeId( result ) != GEOS_LINESTRING ) + if ( GEOSGeomTypeId_r( geosinit.ctxt, result ) != GEOS_LINESTRING ) { - GEOSGeom_destroy( result ); + GEOSGeom_destroy_r( geosinit.ctxt, result ); return 0; } @@ -5120,17 +5068,17 @@ int QgsGeometry::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QLis //if topological editing is enabled testPoints.clear(); - GEOSGeometry* intersectionGeom = GEOSIntersection( mGeos, splitLine ); + GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosinit.ctxt, mGeos, splitLine ); if ( !intersectionGeom ) return 1; bool simple = false; int nIntersectGeoms = 1; - if ( GEOSGeomTypeId( intersectionGeom ) == GEOS_LINESTRING || GEOSGeomTypeId( intersectionGeom ) == GEOS_POINT ) + if ( GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_LINESTRING || GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_POINT ) simple = true; if ( !simple ) - nIntersectGeoms = GEOSGetNumGeometries( intersectionGeom ); + nIntersectGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, intersectionGeom ); for ( int i = 0; i < nIntersectGeoms; ++i ) { @@ -5138,18 +5086,18 @@ int QgsGeometry::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QLis if ( simple ) currentIntersectGeom = intersectionGeom; else - currentIntersectGeom = GEOSGetGeometryN( intersectionGeom, i ); + currentIntersectGeom = GEOSGetGeometryN_r( geosinit.ctxt, intersectionGeom, i ); - const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq( currentIntersectGeom ); + const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq_r( geosinit.ctxt, currentIntersectGeom ); unsigned int sequenceSize = 0; double x, y; - if ( GEOSCoordSeq_getSize( lineSequence, &sequenceSize ) != 0 ) + if ( GEOSCoordSeq_getSize_r( geosinit.ctxt, lineSequence, &sequenceSize ) != 0 ) { for ( unsigned int i = 0; i < sequenceSize; ++i ) { - if ( GEOSCoordSeq_getX( lineSequence, i, &x ) != 0 ) + if ( GEOSCoordSeq_getX_r( geosinit.ctxt, lineSequence, i, &x ) != 0 ) { - if ( GEOSCoordSeq_getY( lineSequence, i, &y ) != 0 ) + if ( GEOSCoordSeq_getY_r( geosinit.ctxt, lineSequence, i, &y ) != 0 ) { testPoints.push_back( QgsPoint( x, y ) ); } @@ -5157,7 +5105,7 @@ int QgsGeometry::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QLis } } } - GEOSGeom_destroy( intersectionGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom ); return 0; } @@ -5167,16 +5115,16 @@ GEOSGeometry *QgsGeometry::nodeGeometries( const GEOSGeometry *splitLine, const return 0; GEOSGeometry *geometryBoundary = 0; - if ( GEOSGeomTypeId( geom ) == GEOS_POLYGON || GEOSGeomTypeId( geom ) == GEOS_MULTIPOLYGON ) - geometryBoundary = GEOSBoundary( geom ); + if ( GEOSGeomTypeId_r( geosinit.ctxt, geom ) == GEOS_POLYGON || GEOSGeomTypeId_r( geosinit.ctxt, geom ) == GEOS_MULTIPOLYGON ) + geometryBoundary = GEOSBoundary_r( geosinit.ctxt, geom ); else - geometryBoundary = GEOSGeom_clone( geom ); + geometryBoundary = GEOSGeom_clone_r( geosinit.ctxt, geom ); - GEOSGeometry *splitLineClone = GEOSGeom_clone( splitLine ); - GEOSGeometry *unionGeometry = GEOSUnion( splitLineClone, geometryBoundary ); - GEOSGeom_destroy( splitLineClone ); + GEOSGeometry *splitLineClone = GEOSGeom_clone_r( geosinit.ctxt, splitLine ); + GEOSGeometry *unionGeometry = GEOSUnion_r( geosinit.ctxt, splitLineClone, geometryBoundary ); + GEOSGeom_destroy_r( geosinit.ctxt, splitLineClone ); - GEOSGeom_destroy( geometryBoundary ); + GEOSGeom_destroy_r( geosinit.ctxt, geometryBoundary ); return unionGeometry; } @@ -5189,21 +5137,21 @@ int QgsGeometry::lineContainedInLine( const GEOSGeometry* line1, const GEOSGeome double bufferDistance = pow( 1.0L, geomDigits( line2 ) - 11 ); - GEOSGeometry* bufferGeom = GEOSBuffer( line2, bufferDistance, DEFAULT_QUADRANT_SEGMENTS ); + GEOSGeometry* bufferGeom = GEOSBuffer_r( geosinit.ctxt, line2, bufferDistance, DEFAULT_QUADRANT_SEGMENTS ); if ( !bufferGeom ) return -2; - GEOSGeometry* intersectionGeom = GEOSIntersection( bufferGeom, line1 ); + GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosinit.ctxt, bufferGeom, line1 ); //compare ratio between line1Length and intersectGeomLength (usually close to 1 if line1 is contained in line2) double intersectGeomLength; double line1Length; - GEOSLength( intersectionGeom, &intersectGeomLength ); - GEOSLength( line1, &line1Length ); + GEOSLength_r( geosinit.ctxt, intersectionGeom, &intersectGeomLength ); + GEOSLength_r( geosinit.ctxt, line1, &line1Length ); - GEOSGeom_destroy( bufferGeom ); - GEOSGeom_destroy( intersectionGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, bufferGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom ); double intersectRatio = line1Length / intersectGeomLength; if ( intersectRatio > 0.9 && intersectRatio < 1.1 ) @@ -5219,49 +5167,49 @@ int QgsGeometry::pointContainedInLine( const GEOSGeometry* point, const GEOSGeom double bufferDistance = pow( 1.0L, geomDigits( line ) - 11 ); - GEOSGeometry* lineBuffer = GEOSBuffer( line, bufferDistance, 8 ); + GEOSGeometry* lineBuffer = GEOSBuffer_r( geosinit.ctxt, line, bufferDistance, 8 ); if ( !lineBuffer ) return -2; bool contained = false; - if ( GEOSContains( lineBuffer, point ) == 1 ) + if ( GEOSContains_r( geosinit.ctxt, lineBuffer, point ) == 1 ) contained = true; - GEOSGeom_destroy( lineBuffer ); + GEOSGeom_destroy_r( geosinit.ctxt, lineBuffer ); return contained; } int QgsGeometry::geomDigits( const GEOSGeometry* geom ) { - GEOSGeometry* bbox = GEOSEnvelope( geom ); + GEOSGeometry* bbox = GEOSEnvelope_r( geosinit.ctxt, geom ); if ( !bbox ) return -1; - const GEOSGeometry* bBoxRing = GEOSGetExteriorRing( bbox ); + const GEOSGeometry* bBoxRing = GEOSGetExteriorRing_r( geosinit.ctxt, bbox ); if ( !bBoxRing ) return -1; - const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq( bBoxRing ); + const GEOSCoordSequence* bBoxCoordSeq = GEOSGeom_getCoordSeq_r( geosinit.ctxt, bBoxRing ); if ( !bBoxCoordSeq ) return -1; unsigned int nCoords = 0; - if ( !GEOSCoordSeq_getSize( bBoxCoordSeq, &nCoords ) ) + if ( !GEOSCoordSeq_getSize_r( geosinit.ctxt, bBoxCoordSeq, &nCoords ) ) return -1; int maxDigits = -1; for ( unsigned int i = 0; i < nCoords - 1; ++i ) { double t; - GEOSCoordSeq_getX( bBoxCoordSeq, i, &t ); + GEOSCoordSeq_getX_r( geosinit.ctxt, bBoxCoordSeq, i, &t ); int digits; digits = ceil( log10( fabs( t ) ) ); if ( digits > maxDigits ) maxDigits = digits; - GEOSCoordSeq_getY( bBoxCoordSeq, i, &t ); + GEOSCoordSeq_getY_r( geosinit.ctxt, bBoxCoordSeq, i, &t ); digits = ceil( log10( fabs( t ) ) ); if ( digits > maxDigits ) maxDigits = digits; @@ -5275,13 +5223,13 @@ int QgsGeometry::numberOfGeometries( GEOSGeometry* g ) const if ( !g ) return 0; - int geometryType = GEOSGeomTypeId( g ); + int geometryType = GEOSGeomTypeId_r( geosinit.ctxt, g ); if ( geometryType == GEOS_POINT || geometryType == GEOS_LINESTRING || geometryType == GEOS_LINEARRING || geometryType == GEOS_POLYGON ) return 1; //calling GEOSGetNumGeometries is save for multi types and collections also in geos2 - return GEOSGetNumGeometries( g ); + return GEOSGetNumGeometries_r( geosinit.ctxt, g ); } int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector& splitResult ) @@ -5293,7 +5241,7 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector& splitRes return 1; //convert mGeos to geometry collection - int type = GEOSGeomTypeId( mGeos ); + int type = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); if ( type != GEOS_GEOMETRYCOLLECTION && type != GEOS_MULTILINESTRING && type != GEOS_MULTIPOLYGON && @@ -5310,9 +5258,9 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector& splitRes { //is this geometry a part of the original multitype? bool isPart = false; - for ( int j = 0; j < GEOSGetNumGeometries( mGeos ); j++ ) + for ( int j = 0; j < GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); j++ ) { - if ( GEOSEquals( copyList[i], GEOSGetGeometryN( mGeos, j ) ) ) + if ( GEOSEquals_r( geosinit.ctxt, copyList[i], GEOSGetGeometryN_r( geosinit.ctxt, mGeos, j ) ) ) { isPart = true; break; @@ -5333,7 +5281,7 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector& splitRes else if ( type == GEOS_MULTIPOLYGON ) splitResult << createGeosCollection( GEOS_MULTIPOLYGON, geomVector ); else - GEOSGeom_destroy( copyList[i] ); + GEOSGeom_destroy_r( geosinit.ctxt, copyList[i] ); } } @@ -5530,7 +5478,7 @@ double QgsGeometry::area() try { - if ( GEOSArea( mGeos, &area ) == 0 ) + if ( GEOSArea_r( geosinit.ctxt, mGeos, &area ) == 0 ) return -1.0; } CATCH_GEOS( -1.0 ) @@ -5550,7 +5498,7 @@ double QgsGeometry::length() try { - if ( GEOSLength( mGeos, &length ) == 0 ) + if ( GEOSLength_r( geosinit.ctxt, mGeos, &length ) == 0 ) return -1.0; } CATCH_GEOS( -1.0 ) @@ -5572,7 +5520,7 @@ double QgsGeometry::distance( QgsGeometry& geom ) try { - GEOSDistance( mGeos, geom.mGeos, &dist ); + GEOSDistance_r( geosinit.ctxt, mGeos, geom.mGeos, &dist ); } CATCH_GEOS( -1.0 ) @@ -5589,7 +5537,7 @@ QgsGeometry* QgsGeometry::buffer( double distance, int segments ) try { - return fromGeosGeom( GEOSBuffer( mGeos, distance, segments ) ); + return fromGeosGeom( GEOSBuffer_r( geosinit.ctxt, mGeos, distance, segments ) ); } CATCH_GEOS( 0 ) } @@ -5606,7 +5554,7 @@ QgsGeometry*QgsGeometry::buffer( double distance, int segments, int endCapStyle, try { - return fromGeosGeom( GEOSBufferWithStyle( mGeos, distance, segments, endCapStyle, joinStyle, mitreLimit ) ); + return fromGeosGeom( GEOSBufferWithStyle_r( geosinit.ctxt, mGeos, distance, segments, endCapStyle, joinStyle, mitreLimit ) ); } CATCH_GEOS( 0 ) #else @@ -5626,7 +5574,7 @@ QgsGeometry* QgsGeometry::offsetCurve( double distance, int segments, int joinSt try { - return fromGeosGeom( GEOSOffsetCurve( mGeos, distance, segments, joinStyle, mitreLimit ) ); + return fromGeosGeom( GEOSOffsetCurve_r( geosinit.ctxt, mGeos, distance, segments, joinStyle, mitreLimit ) ); } CATCH_GEOS( 0 ) #else @@ -5644,7 +5592,7 @@ QgsGeometry* QgsGeometry::simplify( double tolerance ) try { - return fromGeosGeom( GEOSTopologyPreserveSimplify( mGeos, tolerance ) ); + return fromGeosGeom( GEOSTopologyPreserveSimplify_r( geosinit.ctxt, mGeos, tolerance ) ); } CATCH_GEOS( 0 ) } @@ -5659,7 +5607,7 @@ QgsGeometry* QgsGeometry::centroid() try { - return fromGeosGeom( GEOSGetCentroid( mGeos ) ); + return fromGeosGeom( GEOSGetCentroid_r( geosinit.ctxt, mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5674,7 +5622,7 @@ QgsGeometry* QgsGeometry::pointOnSurface() try { - return fromGeosGeom( GEOSPointOnSurface( mGeos ) ); + return fromGeosGeom( GEOSPointOnSurface_r( geosinit.ctxt, mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5689,7 +5637,7 @@ QgsGeometry* QgsGeometry::convexHull() try { - return fromGeosGeom( GEOSConvexHull( mGeos ) ); + return fromGeosGeom( GEOSConvexHull_r( geosinit.ctxt, mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5706,11 +5654,12 @@ QgsGeometry* QgsGeometry::interpolate( double distance ) try { - return fromGeosGeom( GEOSInterpolate( mGeos, distance ) ); + return fromGeosGeom( GEOSInterpolate_r( geosinit.ctxt, mGeos, distance ) ); } CATCH_GEOS( 0 ) #else QgsMessageLog::logMessage( QObject::tr( "GEOS prior to 3.2 doesn't support GEOSInterpolate" ), QObject::tr( "GEOS" ) ); + return NULL; #endif } @@ -5730,7 +5679,7 @@ QgsGeometry* QgsGeometry::intersection( QgsGeometry* geometry ) try { - return fromGeosGeom( GEOSIntersection( mGeos, geometry->mGeos ) ); + return fromGeosGeom( GEOSIntersection_r( geosinit.ctxt, mGeos, geometry->mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5751,16 +5700,16 @@ QgsGeometry* QgsGeometry::combine( QgsGeometry* geometry ) try { - GEOSGeometry* unionGeom = GEOSUnion( mGeos, geometry->mGeos ); + GEOSGeometry* unionGeom = GEOSUnion_r( geosinit.ctxt, mGeos, geometry->mGeos ); if ( !unionGeom ) return 0; if ( type() == QGis::Line ) { - GEOSGeometry* mergedGeom = GEOSLineMerge( unionGeom ); + GEOSGeometry* mergedGeom = GEOSLineMerge_r( geosinit.ctxt, unionGeom ); if ( mergedGeom ) { - GEOSGeom_destroy( unionGeom ); + GEOSGeom_destroy_r( geosinit.ctxt, unionGeom ); unionGeom = mergedGeom; } } @@ -5785,7 +5734,7 @@ QgsGeometry* QgsGeometry::difference( QgsGeometry* geometry ) try { - return fromGeosGeom( GEOSDifference( mGeos, geometry->mGeos ) ); + return fromGeosGeom( GEOSDifference_r( geosinit.ctxt, mGeos, geometry->mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5806,7 +5755,7 @@ QgsGeometry* QgsGeometry::symDifference( QgsGeometry* geometry ) try { - return fromGeosGeom( GEOSSymDifference( mGeos, geometry->mGeos ) ); + return fromGeosGeom( GEOSSymDifference_r( geosinit.ctxt, mGeos, geometry->mGeos ) ); } CATCH_GEOS( 0 ) } @@ -5819,7 +5768,7 @@ QList QgsGeometry::asGeometryCollection() const if ( !mGeos ) return QList(); - int type = GEOSGeomTypeId( mGeos ); + int type = GEOSGeomTypeId_r( geosinit.ctxt, mGeos ); QgsDebugMsg( "geom type: " + QString::number( type ) ); QList geomCollection; @@ -5834,13 +5783,13 @@ QList QgsGeometry::asGeometryCollection() const return geomCollection; } - int count = GEOSGetNumGeometries( mGeos ); + int count = GEOSGetNumGeometries_r( geosinit.ctxt, mGeos ); QgsDebugMsg( "geom count: " + QString::number( count ) ); for ( int i = 0; i < count; ++i ) { - const GEOSGeometry * geometry = GEOSGetGeometryN( mGeos, i ); - geomCollection.append( fromGeosGeom( GEOSGeom_clone( geometry ) ) ); + const GEOSGeometry * geometry = GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ); + geomCollection.append( fromGeosGeom( GEOSGeom_clone_r( geosinit.ctxt, geometry ) ) ); } return geomCollection; @@ -5965,8 +5914,8 @@ static GEOSGeometry* _makeUnion( QList geoms ) #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && (((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)) || (GEOS_VERSION_MAJOR>3)) GEOSGeometry* geomCollection = 0; geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geoms.toVector() ); - GEOSGeometry* geomUnion = GEOSUnaryUnion( geomCollection ); - GEOSGeom_destroy( geomCollection ); + GEOSGeometry* geomUnion = GEOSUnaryUnion_r( geosinit.ctxt, geomCollection ); + GEOSGeom_destroy_r( geosinit.ctxt, geomCollection ); return geomUnion; #else GEOSGeometry* geomCollection = geoms.takeFirst(); @@ -5974,9 +5923,9 @@ static GEOSGeometry* _makeUnion( QList geoms ) while ( !geoms.isEmpty() ) { GEOSGeometry* g = geoms.takeFirst(); - GEOSGeometry* geomCollectionNew = GEOSUnion( geomCollection, g ); - GEOSGeom_destroy( geomCollection ); - GEOSGeom_destroy( g ); + GEOSGeometry* geomCollectionNew = GEOSUnion_r( geosinit.ctxt, geomCollection, g ); + GEOSGeom_destroy_r( geosinit.ctxt, geomCollection ); + GEOSGeom_destroy_r( geosinit.ctxt, g ); geomCollection = geomCollectionNew; } @@ -6027,7 +5976,7 @@ int QgsGeometry::avoidIntersections( QMap if ( !f.geometry() ) continue; - nearGeometries << GEOSGeom_clone( f.geometry()->asGeos() ); + nearGeometries << GEOSGeom_clone_r( geosinit.ctxt, f.geometry()->asGeos() ); } } } @@ -6040,18 +5989,18 @@ int QgsGeometry::avoidIntersections( QMap try { nearGeometriesUnion = _makeUnion( nearGeometries ); - geomWithoutIntersections = GEOSDifference( asGeos(), nearGeometriesUnion ); + geomWithoutIntersections = GEOSDifference_r( geosinit.ctxt, asGeos(), nearGeometriesUnion ); fromGeos( geomWithoutIntersections ); - GEOSGeom_destroy( nearGeometriesUnion ); + GEOSGeom_destroy_r( geosinit.ctxt, nearGeometriesUnion ); } catch ( GEOSException &e ) { if ( nearGeometriesUnion ) - GEOSGeom_destroy( nearGeometriesUnion ); + GEOSGeom_destroy_r( geosinit.ctxt, nearGeometriesUnion ); if ( geomWithoutIntersections ) - GEOSGeom_destroy( geomWithoutIntersections ); + GEOSGeom_destroy_r( geosinit.ctxt, geomWithoutIntersections ); QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) ); return 3; @@ -6078,7 +6027,7 @@ bool QgsGeometry::isGeosValid() if ( !g ) return false; - return GEOSisValid( g ); + return GEOSisValid_r( geosinit.ctxt, g ); } catch ( GEOSException &e ) { @@ -6089,7 +6038,7 @@ bool QgsGeometry::isGeosValid() bool QgsGeometry::isGeosEqual( QgsGeometry &g ) { - return geosRelOp( GEOSEquals, this, &g ); + return geosRelOp( GEOSEquals_r, this, &g ); } bool QgsGeometry::isGeosEmpty() @@ -6101,7 +6050,7 @@ bool QgsGeometry::isGeosEmpty() if ( !g ) return false; - return GEOSisEmpty( g ); + return GEOSisEmpty_r( geosinit.ctxt, g ); } catch ( GEOSException &e ) { @@ -6442,7 +6391,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList &geometryList ) QList geoms; foreach( QgsGeometry* g, geometryList ) { - geoms.append( GEOSGeom_clone(g->asGeos()) ); + geoms.append( GEOSGeom_clone_r( geosinit.ctxt, g->asGeos()) ); } GEOSGeometry *geomUnion = _makeUnion( geoms ); QgsGeometry *ret = new QgsGeometry(); diff --git a/src/core/qgsgeometry.h b/src/core/qgsgeometry.h index bf522a7e458..239561a9688 100644 --- a/src/core/qgsgeometry.h +++ b/src/core/qgsgeometry.h @@ -24,11 +24,6 @@ email : morb at ozemail dot com dot au #include -#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3) -#define GEOSGeometry struct GEOSGeom_t -#define GEOSCoordSequence struct GEOSCoordSeq_t -#endif - #include "qgspoint.h" #include "qgscoordinatetransform.h" #include "qgsfeature.h" @@ -88,6 +83,9 @@ class CORE_EXPORT QgsGeometry //! Destructor ~QgsGeometry(); + /** return GEOS context handle */ + static GEOSContextHandle_t getGEOSHandler(); + /** static method that creates geometry from Wkt */ static QgsGeometry* fromWkt( QString wkt ); @@ -640,7 +638,7 @@ class CORE_EXPORT QgsGeometry /** return polygon from wkb */ QgsPolygon asPolygon( QgsConstWkbPtr &wkbPtr, bool hasZValue ) const; - static bool geosRelOp( char( *op )( const GEOSGeometry*, const GEOSGeometry * ), + static bool geosRelOp( char( *op )( GEOSContextHandle_t handle, const GEOSGeometry*, const GEOSGeometry * ), const QgsGeometry* a, const QgsGeometry* b ); /**Returns < 0 if point(x/y) is left of the line x1,y1 -> x1,y2*/ diff --git a/src/core/qgsgeometryvalidator.cpp b/src/core/qgsgeometryvalidator.cpp index d287647f2ba..f038642b31c 100644 --- a/src/core/qgsgeometryvalidator.cpp +++ b/src/core/qgsgeometryvalidator.cpp @@ -201,6 +201,7 @@ void QgsGeometryValidator::run() { char *r = 0; const GEOSGeometry *g0 = mG.asGeos(); + GEOSContextHandle_t handle = QgsGeometry::getGEOSHandler(); if ( !g0 ) { emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:could not produce geometry for GEOS (check log window)" ) ) ); @@ -208,23 +209,23 @@ void QgsGeometryValidator::run() else { GEOSGeometry *g1 = 0; - if ( GEOSisValidDetail( g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 ) + if ( GEOSisValidDetail_r( handle, g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 ) { if ( g1 ) { - const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g1 ); + const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( handle, g1 ); unsigned int n; - if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 ) + if ( GEOSCoordSeq_getSize_r( handle, cs, &n ) && n == 1 ) { double x, y; - GEOSCoordSeq_getX( cs, 0, &x ); - GEOSCoordSeq_getY( cs, 0, &y ); + GEOSCoordSeq_getX_r( handle, cs, 0, &x ); + GEOSCoordSeq_getY_r( handle, cs, 0, &y ); emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) ); mErrorCount++; } - GEOSGeom_destroy( g1 ); + GEOSGeom_destroy_r( handle, g1 ); } else { @@ -232,7 +233,7 @@ void QgsGeometryValidator::run() mErrorCount++; } - GEOSFree( r ); + GEOSFree_r( handle, r ); } } diff --git a/src/core/qgspalgeometry.h b/src/core/qgspalgeometry.h index c0517a0913a..e76ab319363 100644 --- a/src/core/qgspalgeometry.h +++ b/src/core/qgspalgeometry.h @@ -1,6 +1,7 @@ #ifndef QGSPALGEOMETRY_H #define QGSPALGEOMETRY_H +#include "qgsgeometry.h" #include #include @@ -29,7 +30,7 @@ class QgsPalGeometry : public PalGeometry ~QgsPalGeometry() { if ( mG ) - GEOSGeom_destroy( mG ); + GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mG ); delete mInfo; delete mFontMetrics; } diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index c8d3cdedd3d..812774b0aa1 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -1985,7 +1985,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext } } - GEOSGeometry* geos_geom_clone = GEOSGeom_clone( geos_geom ); + GEOSGeometry* geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom ); //data defined position / alignment / rotation? bool dataDefinedPosition = false; @@ -3536,7 +3536,7 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature& } //create PALGeometry with diagram = true - QgsPalGeometry* lbl = new QgsPalGeometry( feat.id(), "", GEOSGeom_clone( geos_geom ) ); + QgsPalGeometry* lbl = new QgsPalGeometry( feat.id(), "", GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom ) ); lbl->setIsDiagram( true ); // record the created geometry - it will be deleted at the end. diff --git a/src/plugins/topology/topolTest.cpp b/src/plugins/topology/topolTest.cpp index 04a1a076cdd..2446365ac9d 100644 --- a/src/plugins/topology/topolTest.cpp +++ b/src/plugins/topology/topolTest.cpp @@ -589,6 +589,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec int i = 0; ErrorList errorList; + GEOSContextHandle_t geosctxt = QgsGeometry::getGEOSHandler(); // could be enabled for lines and points too // so duplicate rule may be removed? @@ -646,13 +647,13 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec QgsGeometry* polyGeom = QgsGeometry::fromPolygon( polygon ); - geomList.push_back( GEOSGeom_clone( polyGeom->asGeos() ) ); + geomList.push_back( GEOSGeom_clone_r( geosctxt, polyGeom->asGeos() ) ); } } else { - geomList.push_back( GEOSGeom_clone( g1->asGeos() ) ); + geomList.push_back( GEOSGeom_clone_r( geosctxt, g1->asGeos() ) ); } } @@ -672,11 +673,11 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec } GEOSGeometry* collection = 0; - collection = GEOSGeom_createCollection( GEOS_MULTIPOLYGON, geomArray, geomList.size() ); + collection = GEOSGeom_createCollection_r( geosctxt, GEOS_MULTIPOLYGON, geomArray, geomList.size() ); qDebug() << "performing cascaded union..might take time..-"; - GEOSGeometry* unionGeom = GEOSUnionCascaded( collection ); + GEOSGeometry* unionGeom = GEOSUnionCascaded_r( geosctxt, collection ); //delete[] geomArray; QgsGeometry test; @@ -875,7 +876,7 @@ ErrorList topolTest::checkValid( double tolerance, QgsVectorLayer* layer1, QgsVe if ( !g->asGeos() ) continue; - if ( !GEOSisValid( g->asGeos() ) ) + if ( !GEOSisValid_r( QgsGeometry::getGEOSHandler(), g->asGeos() ) ) { QgsRectangle r = g->boundingBox(); QList fls;