Skip to content

Commit

Permalink
Avoid use of raw GEOS API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 8, 2018
1 parent 1631a82 commit 43d8567
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -397,21 +397,12 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( const QgsGeometry &poly,
cellCenterY = rasterBBox.yMaximum() - pixelOffsetY * cellSizeY - cellSizeY / 2;
stats.reset();

geos::unique_ptr polyGeos( QgsGeos::asGeos( poly ) );
if ( !polyGeos )
std::unique_ptr< QgsGeometryEngine > polyEngine( QgsGeometry::createGeometryEngine( poly.constGet( ) ) );
if ( !polyEngine )
{
return;
}

GEOSContextHandle_t geosctxt = QgsGeos::getGEOSHandler();
geos::prepared_unique_ptr polyGeosPrepared( GEOSPrepare_r( geosctxt, polyGeos.get() ) );
if ( !polyGeosPrepared )
{
return;
}

GEOSCoordSequence *cellCenterCoords = nullptr;
geos::unique_ptr currentCellCenter;
polyEngine->prepareGeometry();

QgsRectangle featureBBox = poly.boundingBox().intersect( &rasterBBox );
QgsRectangle intersectBBox = rasterBBox.intersect( &featureBBox );
Expand All @@ -425,11 +416,8 @@ void QgsZonalStatistics::statisticsFromMiddlePointTest( const QgsGeometry &poly,
double pixelValue = block->value( i, j );
if ( validPixel( pixelValue ) )
{
cellCenterCoords = GEOSCoordSeq_create_r( geosctxt, 1, 2 );
GEOSCoordSeq_setX_r( geosctxt, cellCenterCoords, 0, cellCenterX );
GEOSCoordSeq_setY_r( geosctxt, cellCenterCoords, 0, cellCenterY );
currentCellCenter.reset( GEOSGeom_createPoint_r( geosctxt, cellCenterCoords ) );
if ( GEOSPreparedContains_r( geosctxt, polyGeosPrepared.get(), currentCellCenter.get() ) )
QgsPoint cellCenter( cellCenterX, cellCenterY );
if ( polyEngine->contains( &cellCenter ) )
{
stats.addValue( pixelValue );
}
Expand Down

0 comments on commit 43d8567

Please sign in to comment.