QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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#include "qgsspatialindex.h"
21
22#include <random>
23
24// The algorithm parameter names:
25static const QString INPUT = QStringLiteral( "INPUT" );
26static const QString POINTS_NUMBER = QStringLiteral( "POINTS_NUMBER" );
27static const QString MIN_DISTANCE_GLOBAL = QStringLiteral( "MIN_DISTANCE_GLOBAL" );
28static const QString MIN_DISTANCE = QStringLiteral( "MIN_DISTANCE" );
29static const QString MAX_TRIES_PER_POINT = QStringLiteral( "MAX_TRIES_PER_POINT" );
30static const QString SEED = QStringLiteral( "SEED" );
31static const QString INCLUDE_POLYGON_ATTRIBUTES = QStringLiteral( "INCLUDE_POLYGON_ATTRIBUTES" );
32static const QString OUTPUT = QStringLiteral( "OUTPUT" );
33static const QString OUTPUT_POINTS = QStringLiteral( "OUTPUT_POINTS" );
34static const QString POINTS_MISSED = QStringLiteral( "POINTS_MISSED" );
35static const QString POLYGONS_WITH_MISSED_POINTS = QStringLiteral( "POLYGONS_WITH_MISSED_POINTS" );
36static const QString FEATURES_WITH_EMPTY_OR_NO_GEOMETRY = QStringLiteral( "FEATURES_WITH_EMPTY_OR_NO_GEOMETRY" );
38
39QString QgsRandomPointsInPolygonsAlgorithm::name() const
40{
41 return QStringLiteral( "randompointsinpolygons" );
42}
43
44QString QgsRandomPointsInPolygonsAlgorithm::displayName() const
45{
46 return QObject::tr( "Random points in polygons" );
47}
48
49QStringList QgsRandomPointsInPolygonsAlgorithm::tags() const
50{
51 return QObject::tr( "seed,attributes,create" ).split( ',' );
52}
53
54QString QgsRandomPointsInPolygonsAlgorithm::group() const
55{
56 return QObject::tr( "Vector creation" );
57}
58
59QString QgsRandomPointsInPolygonsAlgorithm::groupId() const
60{
61 return QStringLiteral( "vectorcreation" );
62}
63
64void QgsRandomPointsInPolygonsAlgorithm::initAlgorithm( const QVariantMap & )
65{
66 addParameter( new QgsProcessingParameterFeatureSource( INPUT, QObject::tr( "Input polygon layer" ), QList< int >() << QgsProcessing::TypeVectorPolygon ) );
67 std::unique_ptr< QgsProcessingParameterNumber > numberPointsParam = std::make_unique< QgsProcessingParameterNumber >( POINTS_NUMBER, QObject::tr( "Number of points for each feature" ), QgsProcessingParameterNumber::Integer, 1, false, 1 );
68 numberPointsParam->setIsDynamic( true );
69 numberPointsParam->setDynamicPropertyDefinition( QgsPropertyDefinition( POINTS_NUMBER, QObject::tr( "Number of points for each feature" ), QgsPropertyDefinition::IntegerPositive ) );
70 numberPointsParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
71 addParameter( numberPointsParam.release() );
72
73 std::unique_ptr< QgsProcessingParameterDistance > minDistParam = std::make_unique< QgsProcessingParameterDistance >( MIN_DISTANCE, QObject::tr( "Minimum distance between points" ), 0, INPUT, true, 0 );
74 minDistParam->setIsDynamic( true );
75 minDistParam->setDynamicPropertyDefinition( QgsPropertyDefinition( MIN_DISTANCE, QObject::tr( "Minimum distance between points" ), QgsPropertyDefinition::DoublePositive ) );
76 minDistParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
77 addParameter( minDistParam.release() );
78
79 std::unique_ptr< QgsProcessingParameterDistance > minDistGlobalParam = std::make_unique< QgsProcessingParameterDistance >( MIN_DISTANCE_GLOBAL, QObject::tr( "Global minimum distance between points" ), 0, INPUT, true, 0 );
80 minDistGlobalParam->setFlags( minDistGlobalParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
81 addParameter( minDistGlobalParam.release() );
82
83 std::unique_ptr< QgsProcessingParameterNumber > maxAttemptsParam = std::make_unique< QgsProcessingParameterNumber >( MAX_TRIES_PER_POINT, QObject::tr( "Maximum number of search attempts (for Min. dist. > 0)" ), QgsProcessingParameterNumber::Integer, 10, true, 1 );
84 maxAttemptsParam->setFlags( maxAttemptsParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
85 maxAttemptsParam->setIsDynamic( true );
86 maxAttemptsParam->setDynamicPropertyDefinition( QgsPropertyDefinition( MAX_TRIES_PER_POINT, QObject::tr( "Maximum number of attempts per point (for Min. dist. > 0)" ), QgsPropertyDefinition::IntegerPositiveGreaterZero ) );
87 maxAttemptsParam->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
88 addParameter( maxAttemptsParam.release() );
89
90 std::unique_ptr< QgsProcessingParameterNumber > randomSeedParam = std::make_unique< QgsProcessingParameterNumber >( SEED, QObject::tr( "Random seed" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 );
91 randomSeedParam->setFlags( randomSeedParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
92 addParameter( randomSeedParam.release() );
93
94 std::unique_ptr< QgsProcessingParameterBoolean > includePolygonAttrParam = std::make_unique< QgsProcessingParameterBoolean >( INCLUDE_POLYGON_ATTRIBUTES, QObject::tr( "Include polygon attributes" ), true );
95 includePolygonAttrParam->setFlags( includePolygonAttrParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
96 addParameter( includePolygonAttrParam.release() );
97
98 addParameter( new
99 QgsProcessingParameterFeatureSink( OUTPUT, QObject::tr( "Random points in polygons" ), QgsProcessing::TypeVectorPoint ) );
100
101 addOutput( new QgsProcessingOutputNumber( OUTPUT_POINTS, QObject::tr( "Total number of points generated" ) ) );
102 addOutput( new QgsProcessingOutputNumber( POINTS_MISSED, QObject::tr( "Number of missed points" ) ) );
103 addOutput( new QgsProcessingOutputNumber( POLYGONS_WITH_MISSED_POINTS, QObject::tr( "Number of polygons with missed points" ) ) );
104 addOutput( new QgsProcessingOutputNumber( FEATURES_WITH_EMPTY_OR_NO_GEOMETRY, QObject::tr( "Number of features with empty or no geometry" ) ) );
105}
106
107QString QgsRandomPointsInPolygonsAlgorithm::shortHelpString() const
108{
109 return QObject::tr( "<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
149
150QgsRandomPointsInPolygonsAlgorithm *QgsRandomPointsInPolygonsAlgorithm::createInstance() const
151{
152 return new QgsRandomPointsInPolygonsAlgorithm();
153}
154
155bool QgsRandomPointsInPolygonsAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
156{
157 mNumPoints = parameterAsInt( parameters, POINTS_NUMBER, context );
158 mDynamicNumPoints = QgsProcessingParameters::isDynamic( parameters, POINTS_NUMBER );
159 if ( mDynamicNumPoints )
160 mNumPointsProperty = parameters.value( POINTS_NUMBER ).value< QgsProperty >();
161
162 mMinDistance = parameterAsDouble( parameters, MIN_DISTANCE, context );
163 mDynamicMinDistance = QgsProcessingParameters::isDynamic( parameters, MIN_DISTANCE );
164 if ( mDynamicMinDistance )
165 mMinDistanceProperty = parameters.value( MIN_DISTANCE ).value< QgsProperty >();
166
167 mMaxAttempts = parameterAsInt( parameters, MAX_TRIES_PER_POINT, context );
168 mDynamicMaxAttempts = QgsProcessingParameters::isDynamic( parameters, MAX_TRIES_PER_POINT );
169 if ( mDynamicMaxAttempts )
170 mMaxAttemptsProperty = parameters.value( MAX_TRIES_PER_POINT ).value< QgsProperty >();
171
172 mMinDistanceGlobal = parameterAsDouble( parameters, MIN_DISTANCE_GLOBAL, context );
173
174 mUseRandomSeed = parameters.value( SEED ).isValid();
175 mRandSeed = parameterAsInt( parameters, SEED, context );
176 mIncludePolygonAttr = parameterAsBoolean( parameters, INCLUDE_POLYGON_ATTRIBUTES, context );
177 return true;
178}
179
180QVariantMap QgsRandomPointsInPolygonsAlgorithm::processAlgorithm( const QVariantMap &parameters,
181 QgsProcessingContext &context, QgsProcessingFeedback *feedback )
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( QStringLiteral( "rand_point_id" ), QVariant::LongLong ) );
189 if ( mIncludePolygonAttr )
190 fields.extend( polygonSource->fields() );
191
192 QString ldest;
193 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, OUTPUT,
194 context, ldest, fields, Qgis::WkbType::Point, polygonSource->sourceCrs() ) );
195 if ( !sink )
196 throw QgsProcessingException( invalidSinkError( parameters, OUTPUT ) );
197
198 QgsExpressionContext expressionContext = createExpressionContext( parameters, context, polygonSource.get() );
199
200 // Initialize random engine -- note that we only use this if the user has specified a fixed seed
201 std::random_device rd;
202 std::mt19937 mt( !mUseRandomSeed ? rd() : mRandSeed );
203 const std::uniform_real_distribution<> uniformDist( 0, 1 );
204 std::uniform_int_distribution<> uniformIntDist( 1, 999999999 );
205
206 // Index for finding global close points (mMinDistance != 0)
207 QgsSpatialIndex globalIndex;
208 int indexPoints = 0;
209
210 int totNPoints = 0;
211 int missedPoints = 0;
212 int missedPolygons = 0;
213 int emptyOrNullGeom = 0;
214
215 long long attempts = 0; // used for unique feature IDs in the indexes
216 const long numberOfFeatures = polygonSource->featureCount();
217 long long desiredNumberOfPoints = 0;
218 const double featureProgressStep = 100.0 / ( numberOfFeatures > 0 ? numberOfFeatures : 1 );
219 double baseFeatureProgress = 0.0;
220 QgsFeature polyFeat;
221 QgsFeatureIterator fitL = mIncludePolygonAttr || mDynamicNumPoints || mDynamicMinDistance || mDynamicMaxAttempts ? polygonSource->getFeatures()
222 : polygonSource->getFeatures( QgsFeatureRequest().setNoAttributes() );
223 while ( fitL.nextFeature( polyFeat ) )
224 {
225 if ( feedback->isCanceled() )
226 {
227 feedback->setProgress( 0 );
228 break;
229 }
230 if ( !polyFeat.hasGeometry() )
231 {
232 // Increment invalid features count
233 emptyOrNullGeom++;
234 baseFeatureProgress += featureProgressStep;
235 feedback->setProgress( baseFeatureProgress );
236 continue;
237 }
238 const QgsGeometry polyGeom( polyFeat.geometry() );
239 if ( polyGeom.isEmpty() )
240 {
241 // Increment invalid features count
242 emptyOrNullGeom++;
243 baseFeatureProgress += featureProgressStep;
244 feedback->setProgress( baseFeatureProgress );
245 continue;
246 }
247 if ( mDynamicNumPoints || mDynamicMinDistance || mDynamicMaxAttempts )
248 {
249 expressionContext.setFeature( polyFeat );
250 }
251 // (Re)initialize the local (per polygon) index
252 QgsSpatialIndex localIndex;
253 int localIndexPoints = 0;
254 int pointsAddedForThisFeature = 0;
255 // Get data defined parameters
256 int numberPointsForThisFeature = mNumPoints;
257 if ( mDynamicNumPoints )
258 numberPointsForThisFeature = mNumPointsProperty.valueAsInt( expressionContext, numberPointsForThisFeature );
259 desiredNumberOfPoints += numberPointsForThisFeature;
260 int maxAttemptsForThisFeature = mMaxAttempts;
261 if ( mDynamicMaxAttempts )
262 maxAttemptsForThisFeature = mMaxAttemptsProperty.valueAsInt( expressionContext, maxAttemptsForThisFeature );
263 double minDistanceForThisFeature = mMinDistance;
264 if ( mDynamicMinDistance )
265 minDistanceForThisFeature = mMinDistanceProperty.valueAsDouble( expressionContext, minDistanceForThisFeature );
266 const double pointProgressIncrement = featureProgressStep / ( numberPointsForThisFeature * maxAttemptsForThisFeature );
267 double pointProgress = 0.0;
268 // Check if we can avoid using the acceptPoint function
269 if ( ( minDistanceForThisFeature == 0 ) && ( mMinDistanceGlobal == 0 ) )
270 {
271 QVector< QgsPointXY > newPoints = polyGeom.randomPointsInPolygon( numberPointsForThisFeature, mUseRandomSeed ? uniformIntDist( mt ) : 0 );
272 for ( int i = 0; i < newPoints.length(); i++ )
273 {
274 // add the point
275 const QgsPointXY pt = newPoints[i];
276 QgsFeature f = QgsFeature( totNPoints );
277 QgsAttributes pAttrs = QgsAttributes();
278 pAttrs.append( totNPoints );
279 if ( mIncludePolygonAttr )
280 {
281 pAttrs.append( polyFeat.attributes() );
282 }
283 f.setAttributes( pAttrs );
284 const QgsGeometry newGeom = QgsGeometry::fromPointXY( pt );
285 f.setGeometry( newGeom );
286 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
287 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
288 totNPoints++;
289 pointsAddedForThisFeature++;
290 pointProgress += pointProgressIncrement * ( maxAttemptsForThisFeature );
291 }
292 feedback->setProgress( baseFeatureProgress + pointProgress );
293 continue;
294 }
295 else
296 {
297 // Have to check for minimum distance, provide the acceptPoints function
298 QVector< QgsPointXY > newPoints = polyGeom.randomPointsInPolygon( numberPointsForThisFeature, [ & ]( const QgsPointXY & newPoint ) -> bool
299 {
300 attempts++;
301 // May have to check minimum distance to existing points
302 // The first point can always be added
303 // Local first (if larger than global)
304 if ( minDistanceForThisFeature != 0 && mMinDistanceGlobal < minDistanceForThisFeature && localIndexPoints > 0 )
305 {
306 const QList<QgsFeatureId> neighbors = localIndex.nearestNeighbor( newPoint, 1, minDistanceForThisFeature );
307 //if ( totNPoints > 0 && !neighbors.empty() )
308 if ( !neighbors.empty() )
309 {
310 return false;
311 }
312 }
313 // The global
314 if ( mMinDistanceGlobal != 0.0 && indexPoints > 0 )
315 {
316 const QList<QgsFeatureId> neighbors = globalIndex.nearestNeighbor( newPoint, 1, mMinDistanceGlobal );
317 //if ( totNPoints > 0 && !neighbors.empty() )
318 if ( !neighbors.empty() )
319 {
320 return false;
321 }
322 }
323 // Point is accepted - add it to the indexes
324 QgsFeature f = QgsFeature( attempts );
325 QgsAttributes pAttrs = QgsAttributes();
326 pAttrs.append( attempts );
327 f.setAttributes( pAttrs );
328 const QgsGeometry newGeom = QgsGeometry::fromPointXY( newPoint );
329
330 f.setGeometry( newGeom );
331 //totNPoints++;
332
333 if ( minDistanceForThisFeature != 0 )
334 {
335 if ( !localIndex.addFeature( f ) )
336 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
337 localIndexPoints++;
338 }
339 if ( mMinDistanceGlobal != 0.0 )
340 {
341 if ( !globalIndex.addFeature( f ) )
342 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
343 indexPoints++;
344 }
345 return true;
346 }, mUseRandomSeed ? uniformIntDist( mt ) : 0, feedback, maxAttemptsForThisFeature );
347
348 // create and output features for the generated points
349 for ( int i = 0; i < newPoints.length(); i++ )
350 {
351 const QgsPointXY pt = newPoints[i];
352 QgsFeature f = QgsFeature( totNPoints );
353 QgsAttributes pAttrs = QgsAttributes();
354 pAttrs.append( totNPoints );
355 if ( mIncludePolygonAttr )
356 {
357 pAttrs.append( polyFeat.attributes() );
358 }
359 f.setAttributes( pAttrs );
360 const QgsGeometry newGeom = QgsGeometry::fromPointXY( pt );
361 f.setGeometry( newGeom );
362 if ( !sink->addFeature( f, QgsFeatureSink::FastInsert ) )
363 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
364 totNPoints++;
365 pointsAddedForThisFeature++;
366 pointProgress += pointProgressIncrement * ( maxAttemptsForThisFeature );
367 }
368 feedback->setProgress( baseFeatureProgress + pointProgress );
369 }
370
371 baseFeatureProgress += featureProgressStep;
372 if ( pointsAddedForThisFeature < numberPointsForThisFeature )
373 {
374 missedPolygons++;
375 }
376 feedback->setProgress( baseFeatureProgress );
377 } // while features
378 missedPoints = desiredNumberOfPoints - totNPoints;
379 feedback->pushInfo( QObject::tr( "Total number of points generated: "
380 "%1\nNumber of missed points: "
381 "%2\nPolygons with missing points: "
382 "%3\nFeatures with empty or missing "
383 "geometries: %4"
384 ).arg( totNPoints ).arg( missedPoints ).arg( missedPolygons ).arg( emptyOrNullGeom ) );
385 QVariantMap outputs;
386 outputs.insert( OUTPUT, ldest );
387 outputs.insert( OUTPUT_POINTS, totNPoints );
388 outputs.insert( POINTS_MISSED, missedPoints );
389 outputs.insert( POLYGONS_WITH_MISSED_POINTS, missedPolygons );
390 outputs.insert( FEATURES_WITH_EMPTY_OR_NO_GEOMETRY, emptyOrNullGeom );
391
392 return outputs;
393}
394
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)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
@ 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:56
QgsAttributes attributes
Definition qgsfeature.h:65
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry geometry
Definition qgsfeature.h:67
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:54
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:63
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:45
void extend(const QgsFields &other)
Extends with fields from another QgsFields container.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
Definition qgsfields.cpp:59
A geometry is the spatial representation of a feature.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
A class to represent a 2D point.
Definition qgspointxy.h:59
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.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A numeric output for processing algorithms.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) 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...
@ TypeVectorPolygon
Vector polygon layers.
@ TypeVectorPoint
Vector point layers.
Definition for a property.
Definition qgsproperty.h:46
@ 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.