From 948ea41656714a8ead0c2fd72afbb266486b1499 Mon Sep 17 00:00:00 2001 From: root676 Date: Sun, 24 Nov 2019 13:25:46 +0100 Subject: [PATCH] move QgsSpatialIndex to stack and fix QList check --- .../processing/qgsalgorithmrandompointsextent.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/analysis/processing/qgsalgorithmrandompointsextent.cpp b/src/analysis/processing/qgsalgorithmrandompointsextent.cpp index 20fa9a53d7e..8cc804b125a 100644 --- a/src/analysis/processing/qgsalgorithmrandompointsextent.cpp +++ b/src/analysis/processing/qgsalgorithmrandompointsextent.cpp @@ -83,11 +83,11 @@ QgsRandomPointsExtentAlgorithm *QgsRandomPointsExtentAlgorithm::createInstance() bool QgsRandomPointsExtentAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) { - QgsCoordinateReferenceSystem extent_crs = parameterAsExtentCrs( parameters, QStringLiteral( "EXTENT" ), context); + QgsCoordinateReferenceSystem extent_crs = parameterAsExtentCrs( parameters, QStringLiteral( "EXTENT" ), context ); QgsCoordinateReferenceSystem user_crs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context ); //prefer user crs over extent/project crs if defined - if( extent_crs != user_crs ) + if ( extent_crs != user_crs ) mCrs = user_crs; else mCrs = extent_crs; @@ -140,7 +140,7 @@ QVariantMap QgsRandomPointsExtentAlgorithm::processAlgorithm( const QVariantMap } else { - std::unique_ptr index( new QgsSpatialIndex() ); + QgsSpatialIndex index = QgsSpatialIndex(); int distCheckIterations = 0; int i = 0; @@ -155,13 +155,13 @@ QVariantMap QgsRandomPointsExtentAlgorithm::processAlgorithm( const QVariantMap QgsGeometry randomPointGeom = QgsGeometry( new QgsPoint( rx, ry ) ); //check if new random point is inside searching distance to existing points - QList neighbors = index->nearestNeighbor( randomPointGeom, 1, mDistance ); - if ( neighbors.size() == 0 ) + QList neighbors = index.nearestNeighbor( randomPointGeom, 1, mDistance ); + if ( neighbors.empty() ) { QgsFeature f = QgsFeature( i ); f.setAttributes( QgsAttributes() << i ); f.setGeometry( randomPointGeom ); - index->addFeature( f ); + index.addFeature( f ); sink->addFeature( f, QgsFeatureSink::FastInsert ); i++; distCheckIterations = 0; //reset distCheckIterations if a point is added