Skip to content

Commit

Permalink
move QgsSpatialIndex to stack and fix QList check
Browse files Browse the repository at this point in the history
  • Loading branch information
root676 authored and nyalldawson committed Nov 26, 2019
1 parent a7ffa9f commit 948ea41
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/analysis/processing/qgsalgorithmrandompointsextent.cpp
Expand Up @@ -83,11 +83,11 @@ QgsRandomPointsExtentAlgorithm *QgsRandomPointsExtentAlgorithm::createInstance()

bool QgsRandomPointsExtentAlgorithm::prepareAlgorithm( const QVariantMap &parameters, 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;
Expand Down Expand Up @@ -140,7 +140,7 @@ QVariantMap QgsRandomPointsExtentAlgorithm::processAlgorithm( const QVariantMap
}
else
{
std::unique_ptr<QgsSpatialIndex> index( new QgsSpatialIndex() );
QgsSpatialIndex index = QgsSpatialIndex();
int distCheckIterations = 0;

int i = 0;
Expand All @@ -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<QgsFeatureId> neighbors = index->nearestNeighbor( randomPointGeom, 1, mDistance );
if ( neighbors.size() == 0 )
QList<QgsFeatureId> 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
Expand Down

0 comments on commit 948ea41

Please sign in to comment.