QGIS API Documentation 4.3.0-Master (d3b565c628d)
Loading...
Searching...
No Matches
qgsalgorithmrandompointsinpolygons.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmrandompointsinpolygons.cpp
3 ---------------------
4 begin : March 2020
5 copyright : (C) 2020 by HÃ¥vard Tveite
6 email : havard dot tveite at nmbu dot no
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
20
21#include <random>
22
23#include "qgsspatialindex.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
30
31QString QgsRandomPointsInPolygonsAlgorithm::name() const
32{
33 return u"randompointsinpolygons"_s;
34}
35
36QString QgsRandomPointsInPolygonsAlgorithm::displayName() const
37{
38 return QObject::tr( "Random points in polygons" );
39}
40
41QStringList QgsRandomPointsInPolygonsAlgorithm::tags() const
42{
43 return QObject::tr( "seed,attributes,create" ).split( ',' );
44}
45
46QString QgsRandomPointsInPolygonsAlgorithm::group() const
47{
48 return QObject::tr( "Vector creation" );
49}
50
51QString QgsRandomPointsInPolygonsAlgorithm::groupId() const
52{
53 return u"vectorcreation"_s;
54}
55
56void QgsRandomPointsInPolygonsAlgorithm::initAlgorithm( const QVariantMap & )
57{
58 addParameter( new QgsProcessingParameterFeatureSource( INPUT, QObject::tr( "Input polygon layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon ) ) );
59 auto numberPointsParam = std::make_unique<QgsProcessingParameterNumber>( POINTS_NUMBER, QObject::tr( "Number of points for each feature" ), Qgis::ProcessingNumberParameterType::Integer, 1, false, 1 );
60 numberPointsParam->setIsDynamic( true );
61 numberPointsParam->setDynamicPropertyDefinition( QgsPropertyDefinition( POINTS_NUMBER, QObject::tr( "Number of points for each feature" ), QgsPropertyDefinition::IntegerPositive ) );
62 numberPointsParam->setDynamicLayerParameterName( u"INPUT"_s );
63 addParameter( numberPointsParam.release() );
64
65 auto minDistParam = std::make_unique<QgsProcessingParameterDistance>( MIN_DISTANCE, QObject::tr( "Minimum distance between points" ), 0, INPUT, true, 0 );
66 minDistParam->setIsDynamic( true );
67 minDistParam->setDynamicPropertyDefinition( QgsPropertyDefinition( MIN_DISTANCE, QObject::tr( "Minimum distance between points" ), QgsPropertyDefinition::DoublePositive ) );
68 minDistParam->setDynamicLayerParameterName( u"INPUT"_s );
69 addParameter( minDistParam.release() );
70
71 auto minDistGlobalParam = std::make_unique<QgsProcessingParameterDistance>( MIN_DISTANCE_GLOBAL, QObject::tr( "Global minimum distance between points" ), 0, INPUT, true, 0 );
72 minDistGlobalParam->setFlags( minDistGlobalParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
73 addParameter( minDistGlobalParam.release() );
74
75 auto maxAttemptsParam = std::make_unique<
76 QgsProcessingParameterNumber>( MAX_TRIES_PER_POINT, QObject::tr( "Maximum number of search attempts (for Min. dist. > 0)" ), Qgis::ProcessingNumberParameterType::Integer, 10, true, 1 );
77 maxAttemptsParam->setFlags( maxAttemptsParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
78 maxAttemptsParam->setIsDynamic( true );
79 maxAttemptsParam->setDynamicPropertyDefinition(
80 QgsPropertyDefinition( MAX_TRIES_PER_POINT, QObject::tr( "Maximum number of attempts per point (for Min. dist. > 0)" ), QgsPropertyDefinition::IntegerPositiveGreaterZero )
81 );
82 maxAttemptsParam->setDynamicLayerParameterName( u"INPUT"_s );
83 addParameter( maxAttemptsParam.release() );
84
85 auto randomSeedParam = std::make_unique<QgsProcessingParameterNumber>( SEED, QObject::tr( "Random seed" ), Qgis::ProcessingNumberParameterType::Integer, QVariant(), true, 1 );
86 randomSeedParam->setFlags( randomSeedParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
87 addParameter( randomSeedParam.release() );
88
89 auto includePolygonAttrParam = std::make_unique<QgsProcessingParameterBoolean>( INCLUDE_POLYGON_ATTRIBUTES, QObject::tr( "Include polygon attributes" ), true );
90 includePolygonAttrParam->setFlags( includePolygonAttrParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
91 addParameter( includePolygonAttrParam.release() );
92
93 addParameter( new QgsProcessingParameterFeatureSink( OUTPUT, QObject::tr( "Random points in polygons" ), Qgis::ProcessingSourceType::VectorPoint ) );
94
95 addOutput( new QgsProcessingOutputNumber( OUTPUT_POINTS, QObject::tr( "Total number of points generated" ) ) );
96 addOutput( new QgsProcessingOutputNumber( POINTS_MISSED, QObject::tr( "Number of missed points" ) ) );
97 addOutput( new QgsProcessingOutputNumber( POLYGONS_WITH_MISSED_POINTS, QObject::tr( "Number of polygons with missed points" ) ) );
98 addOutput( new QgsProcessingOutputNumber( FEATURES_WITH_EMPTY_OR_NO_GEOMETRY, QObject::tr( "Number of features with empty or no geometry" ) ) );
99}
100
101QString QgsRandomPointsInPolygonsAlgorithm::shortDescription() const
102{
103 return QObject::tr( "Creates a layer with a number of points placed randomly in each polygon of a given layer." );
104}
105
106QString QgsRandomPointsInPolygonsAlgorithm::shortHelpString() const
107{
108 return QObject::tr(
109 "<p>This algorithm creates a point layer, with points placed randomly "
110 "in the polygons of the <i><b>Input polygon layer</b></i>.</p> "
111 "<ul><li>For each feature in the <i><b>Input polygon layer</b></i>, the algorithm attempts to add "
112 "the specified <i><b>Number of points for each feature</b></i> to the output layer.</li> "
113 "<li>A <i><b>Minimum distance between points</b></i> and a "
114 "<i><b>Global minimum distance between points</b></i> can be specified.<br> "
115 "A point will not be added if there is an already generated point within "
116 "this (Euclidean) distance from the generated location. "
117 "With <i>Minimum distance between points</i>, only points in the same "
118 "polygon feature are considered, while for <i>Global minimum distance "
119 "between points</i> all previously generated points are considered. "
120 "If the <i>Global minimum distance between points</i> is set equal to "
121 "or larger than the (local) <i>Minimum distance between points</i>, the "
122 "latter has no effect.<br> "
123 "If the <i>Minimum distance between points</i> is too large, "
124 "it may not be possible to generate the specified <i>Number of points "
125 "for each feature</i>, but all the generated points are returned.</li> "
126 "<li>The <i><b>Maximum number of attempts per point</b></i> can be specified.</li> "
127 "<li>The seed for the random generator can be provided (<b><i>Random seed</i></b> "
128 "- integer, greater than 0).</li> "
129 "<li>The user can choose not to <i><b>Include polygon feature attributes</b></i> in "
130 "the attributes of the generated point features.</li> "
131 "</ul> "
132 "The total number of points will be<br> <b>'number of input features'</b> * "
133 "<i><b>Number of points for each feature</b></i><br> if there are no misses. "
134 "The <i>Number of points for each feature</i>, <i>Minimum distance between points</i> "
135 "and <i>Maximum number of attempts per point</i> can be data defined. "
136 "<p>Output from the algorithm:</p> "
137 "<ul> "
138 "<li> The number of features with an empty or no geometry "
139 "(<code>FEATURES_WITH_EMPTY_OR_NO_GEOMETRY</code>).</li> "
140 "<li> A point layer containing the random points (<code>OUTPUT</code>).</li> "
141 "<li> The number of generated features (<code>OUTPUT_POINTS</code>).</li> "
142 "<li> The number of missed points (<code>POINTS_MISSED</code>).</li> "
143 "<li> The number of features with non-empty geometry and missing points "
144 "(<code>POLYGONS_WITH_MISSED_POINTS</code>).</li> "
145 "</ul>"
146 );
147}
148
149QgsRandomPointsInPolygonsAlgorithm *QgsRandomPointsInPolygonsAlgorithm::createInstance() const
150{
151 return new QgsRandomPointsInPolygonsAlgorithm();
152}
153
154bool QgsRandomPointsInPolygonsAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
155{
156 mNumPoints = parameterAsInt( parameters, POINTS_NUMBER, context );
157 mDynamicNumPoints = QgsProcessingParameters::isDynamic( parameters, POINTS_NUMBER );
158 if ( mDynamicNumPoints )
159 mNumPointsProperty = parameters.value( POINTS_NUMBER ).value<QgsProperty>();
160
161 mMinDistance = parameterAsDouble( parameters, MIN_DISTANCE, context );
162 mDynamicMinDistance = QgsProcessingParameters::isDynamic( parameters, MIN_DISTANCE );
163 if ( mDynamicMinDistance )
164 mMinDistanceProperty = parameters.value( MIN_DISTANCE ).value<QgsProperty>();
165
166 mMaxAttempts = parameterAsInt( parameters, MAX_TRIES_PER_POINT, context );
167 mDynamicMaxAttempts = QgsProcessingParameters::isDynamic( parameters, MAX_TRIES_PER_POINT );
168 if ( mDynamicMaxAttempts )
169 mMaxAttemptsProperty = parameters.value( MAX_TRIES_PER_POINT ).value<QgsProperty>();
170
171 mMinDistanceGlobal = parameterAsDouble( parameters, MIN_DISTANCE_GLOBAL, context );
172
173 mUseRandomSeed = parameters.value( SEED ).isValid();
174 mRandSeed = parameterAsInt( parameters, SEED, context );
175 mIncludePolygonAttr = parameterAsBoolean( parameters, INCLUDE_POLYGON_ATTRIBUTES, context );
176 return true;
177}
178
179QVariantMap QgsRandomPointsInPolygonsAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
180{
181 QGS_MARK_ALGORITHM_SOURCE
182
183 std::unique_ptr<QgsProcessingFeatureSource> polygonSource( parameterAsSource( parameters, INPUT, context ) );
184 if ( !polygonSource )
185 throw QgsProcessingException( invalidSourceError( parameters, INPUT ) );
186
187 QgsFields fields;
188 fields.append( QgsField( u"rand_point_id"_s, QMetaType::Type::LongLong ) );
189 if ( mIncludePolygonAttr )
190 fields.extend( polygonSource->fields() );
191
192 QString ldest;
193 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, OUTPUT, context, ldest, fields, Qgis::WkbType::Point, polygonSource->sourceCrs() ) );
194 if ( !sink )
195 throw QgsProcessingException( invalidSinkError( parameters, OUTPUT ) );
196
197 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, polygonSource.get() );
198
199 // Initialize random engine -- note that we only use this if the user has specified a fixed seed
200 std::random_device rd;
201 std::mt19937 mt( !mUseRandomSeed ? rd() : mRandSeed );
202 const std::uniform_real_distribution<> uniformDist( 0, 1 );
203 std::uniform_int_distribution<> uniformIntDist( 1, 999999999 );
204
205 // Index for finding global close points (mMinDistance != 0)
206 QgsSpatialIndex globalIndex;
207 int indexPoints = 0;
208
209 int totNPoints = 0;
210 int missedPoints = 0;
211 int missedPolygons = 0;
212 int emptyOrNullGeom = 0;
213
214 long long attempts = 0; // used for unique feature IDs in the indexes
215 const long numberOfFeatures = polygonSource->featureCount();
216 long long desiredNumberOfPoints = 0;
217 const double featureProgressStep = 100.0 / ( numberOfFeatures > 0 ? numberOfFeatures : 1 );
218 double baseFeatureProgress = 0.0;
219 QgsFeature polyFeat;
220 QgsFeatureIterator fitL = mIncludePolygonAttr || mDynamicNumPoints || mDynamicMinDistance || mDynamicMaxAttempts ? polygonSource->getFeatures()
221 : polygonSource->getFeatures( QgsFeatureRequest().setNoAttributes() );
222 while ( fitL.nextFeature( polyFeat ) )
223 {
224 if ( feedback->isCanceled() )
225 {
226 feedback->setProgress( 0 );
227 break;
228 }
229 if ( !polyFeat.hasGeometry() )
230 {
231 // Increment invalid features count
232 emptyOrNullGeom++;
233 baseFeatureProgress += featureProgressStep;
234 feedback->setProgress( baseFeatureProgress );
235 continue;
236 }
237 const QgsGeometry polyGeom( polyFeat.geometry() );
238 if ( polyGeom.isEmpty() )
239 {
240 // Increment invalid features count
241 emptyOrNullGeom++;
242 baseFeatureProgress += featureProgressStep;
243 feedback->setProgress( baseFeatureProgress );
244 continue;
245 }
246 if ( mDynamicNumPoints || mDynamicMinDistance || mDynamicMaxAttempts )
247 {
248 expressionContext.setFeature( polyFeat );
249 }
250 // (Re)initialize the local (per polygon) index
251 QgsSpatialIndex localIndex;
252 int localIndexPoints = 0;
253 int pointsAddedForThisFeature = 0;
254 // Get data defined parameters
255 int numberPointsForThisFeature = mNumPoints;
256 if ( mDynamicNumPoints )
257 {
258 numberPointsForThisFeature = mNumPointsProperty.valueAsInt( expressionContext, 0 );
259 }
260 desiredNumberOfPoints += numberPointsForThisFeature;
261 int maxAttemptsForThisFeature = mMaxAttempts;
262 if ( mDynamicMaxAttempts )
263 maxAttemptsForThisFeature = mMaxAttemptsProperty.valueAsInt( expressionContext, maxAttemptsForThisFeature );
264 double minDistanceForThisFeature = mMinDistance;
265 if ( mDynamicMinDistance )
266 minDistanceForThisFeature = mMinDistanceProperty.valueAsDouble( expressionContext, minDistanceForThisFeature );
267 const double pointProgressIncrement = featureProgressStep / ( numberPointsForThisFeature * maxAttemptsForThisFeature );
268 double pointProgress = 0.0;
269 // Check if we can avoid using the acceptPoint function
270 if ( ( minDistanceForThisFeature == 0 ) && ( mMinDistanceGlobal == 0 ) )
271 {
272 QVector<QgsPointXY> newPoints = polyGeom.randomPointsInPolygon( numberPointsForThisFeature, mUseRandomSeed ? uniformIntDist( mt ) : 0 );
273 for ( int i = 0; i < newPoints.length(); i++ )
274 {
275 // add the point
276 const QgsPointXY pt = newPoints[i];
277 QgsFeature f = QgsFeature( totNPoints );
278 QgsAttributes pAttrs = QgsAttributes();
279 pAttrs.append( totNPoints );
280 if ( mIncludePolygonAttr )
281 {
282 pAttrs.append( polyFeat.attributes() );
283 }
284 f.setAttributes( pAttrs );
285 const QgsGeometry newGeom = QgsGeometry::fromPointXY( pt );
286 f.setGeometry( newGeom );
287 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
288 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
289 else
290 feedback->featureAddedToSink( u"OUTPUT"_s );
291 totNPoints++;
292 pointsAddedForThisFeature++;
293 pointProgress += pointProgressIncrement * ( maxAttemptsForThisFeature );
294 }
295 feedback->setProgress( baseFeatureProgress + pointProgress );
296 continue;
297 }
298 else
299 {
300 // Have to check for minimum distance, provide the acceptPoints function
301 QVector<QgsPointXY> newPoints = polyGeom.randomPointsInPolygon(
302 numberPointsForThisFeature,
303 [&]( const QgsPointXY &newPoint ) -> bool {
304 attempts++;
305 // May have to check minimum distance to existing points
306 // The first point can always be added
307 // Local first (if larger than global)
308 if ( minDistanceForThisFeature != 0 && mMinDistanceGlobal < minDistanceForThisFeature && localIndexPoints > 0 )
309 {
310 const QList<QgsFeatureId> neighbors = localIndex.nearestNeighbor( newPoint, 1, minDistanceForThisFeature );
311 //if ( totNPoints > 0 && !neighbors.empty() )
312 if ( !neighbors.empty() )
313 {
314 return false;
315 }
316 }
317 // The global
318 if ( mMinDistanceGlobal != 0.0 && indexPoints > 0 )
319 {
320 const QList<QgsFeatureId> neighbors = globalIndex.nearestNeighbor( newPoint, 1, mMinDistanceGlobal );
321 //if ( totNPoints > 0 && !neighbors.empty() )
322 if ( !neighbors.empty() )
323 {
324 return false;
325 }
326 }
327 // Point is accepted - add it to the indexes
328 QgsFeature f = QgsFeature( attempts );
329 QgsAttributes pAttrs = QgsAttributes();
330 pAttrs.append( attempts );
331 f.setAttributes( pAttrs );
332 const QgsGeometry newGeom = QgsGeometry::fromPointXY( newPoint );
333
334 f.setGeometry( newGeom );
335 //totNPoints++;
336
337 if ( minDistanceForThisFeature != 0 )
338 {
339 if ( !localIndex.addFeature( f ) )
340 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
341 localIndexPoints++;
342 }
343 if ( mMinDistanceGlobal != 0.0 )
344 {
345 if ( !globalIndex.addFeature( f ) )
346 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
347 indexPoints++;
348 }
349 return true;
350 },
351 mUseRandomSeed ? uniformIntDist( mt ) : 0,
352 feedback,
353 maxAttemptsForThisFeature
354 );
355
356 // create and output features for the generated points
357 for ( int i = 0; i < newPoints.length(); i++ )
358 {
359 const QgsPointXY pt = newPoints[i];
360 QgsFeature f = QgsFeature( totNPoints );
361 QgsAttributes pAttrs = QgsAttributes();
362 pAttrs.append( totNPoints );
363 if ( mIncludePolygonAttr )
364 {
365 pAttrs.append( polyFeat.attributes() );
366 }
367 f.setAttributes( pAttrs );
368 const QgsGeometry newGeom = QgsGeometry::fromPointXY( pt );
369 f.setGeometry( newGeom );
370 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
371 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, u"OUTPUT"_s ) );
372 else
373 feedback->featureAddedToSink( u"OUTPUT"_s );
374 totNPoints++;
375 pointsAddedForThisFeature++;
376 pointProgress += pointProgressIncrement * ( maxAttemptsForThisFeature );
377 }
378 feedback->setProgress( baseFeatureProgress + pointProgress );
379 }
380
381 baseFeatureProgress += featureProgressStep;
382 if ( pointsAddedForThisFeature < numberPointsForThisFeature )
383 {
384 missedPolygons++;
385 }
386 feedback->setProgress( baseFeatureProgress );
387 } // while features
388 missedPoints = desiredNumberOfPoints - totNPoints;
389 feedback->pushInfo(
390 QObject::tr(
391 "Total number of points generated: "
392 "%1\nNumber of missed points: "
393 "%2\nPolygons with missing points: "
394 "%3\nFeatures with empty or missing "
395 "geometries: %4"
396 )
397 .arg( totNPoints )
398 .arg( missedPoints )
399 .arg( missedPolygons )
400 .arg( emptyOrNullGeom )
401 );
402
403 sink->finalize();
404 feedback->featureSinkFinalized( u"OUTPUT"_s );
405
406 QVariantMap outputs;
407 outputs.insert( OUTPUT, ldest );
408 outputs.insert( OUTPUT_POINTS, totNPoints );
409 outputs.insert( POINTS_MISSED, missedPoints );
410 outputs.insert( POLYGONS_WITH_MISSED_POINTS, missedPolygons );
411 outputs.insert( FEATURES_WITH_EMPTY_OR_NO_GEOMETRY, emptyOrNullGeom );
412
413 return outputs;
414}
415
@ VectorPoint
Vector point layers.
Definition qgis.h:3750
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3752
@ Point
Point.
Definition qgis.h:296
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3982
A vector of attributes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsAttributes attributes
Definition qgsfeature.h:64
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry geometry
Definition qgsfeature.h:66
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:56
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:65
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
Container of fields for a vector layer.
Definition qgsfields.h:45
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
Definition qgsfields.cpp:75
void extend(const QgsFields &other)
Extends with fields from another QgsFields container.
A geometry is the spatial representation of a feature.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Represents a 2D point.
Definition qgspointxy.h:62
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
A numeric output for processing algorithms.
void setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A numeric parameter for processing algorithms.
static bool isDynamic(const QVariantMap &parameters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
Definition qgsproperty.h:47
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
Definition qgsproperty.h:55
@ IntegerPositive
Positive integer values (including 0).
Definition qgsproperty.h:54
@ DoublePositive
Positive double value (including 0).
Definition qgsproperty.h:57
A store for object properties.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
int valueAsInt(const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as an integer.
A spatial index for QgsFeature objects.
QList< QgsFeatureId > nearestNeighbor(const QgsPointXY &point, int neighbors=1, double maxDistance=0) const
Returns nearest neighbors to a point.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.