25QString QgsPixelCentroidsFromPolygonsAlgorithm::name()
const
27 return QStringLiteral(
"generatepointspixelcentroidsinsidepolygons" );
30QString QgsPixelCentroidsFromPolygonsAlgorithm::displayName()
const
32 return QObject::tr(
"Generate points (pixel centroids) inside polygons" );
35QStringList QgsPixelCentroidsFromPolygonsAlgorithm::tags()
const
37 return QObject::tr(
"raster,polygon,centroid,pixel,create" ).split(
',' );
40QString QgsPixelCentroidsFromPolygonsAlgorithm::group()
const
42 return QObject::tr(
"Vector creation" );
45QString QgsPixelCentroidsFromPolygonsAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorcreation" );
50QString QgsPixelCentroidsFromPolygonsAlgorithm::shortHelpString()
const
52 return QObject::tr(
"This algorithm generates pixel centroids for the raster area falling inside polygons. Used to generate points "
53 "for further raster sampling." );
56QString QgsPixelCentroidsFromPolygonsAlgorithm::shortDescription()
const
58 return QObject::tr(
"Generates pixel centroids for the raster area falling inside polygons." );
66QgsPixelCentroidsFromPolygonsAlgorithm *QgsPixelCentroidsFromPolygonsAlgorithm::createInstance()
const
68 return new QgsPixelCentroidsFromPolygonsAlgorithm();
71void QgsPixelCentroidsFromPolygonsAlgorithm::initAlgorithm(
const QVariantMap & )
81 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
86 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT_VECTOR" ), context ) );
91 fields.
append(
QgsField( QStringLiteral(
"id" ), QMetaType::Type::LongLong ) );
92 fields.
append(
QgsField( QStringLiteral(
"poly_id" ), QMetaType::Type::Int ) );
93 fields.
append(
QgsField( QStringLiteral(
"point_id" ), QMetaType::Type::Int ) );
100 const double step = source->featureCount() ? 100.0 / source->featureCount() : 1;
128 const double xMin = bbox.
xMinimum();
129 const double xMax = bbox.
xMaximum();
130 const double yMin = bbox.
yMinimum();
131 const double yMax = bbox.
yMaximum();
134 int startRow, startColumn;
135 int endRow, endColumn;
136 QgsRasterAnalysisUtils::mapToPixel( xMin, yMax, extent, xPixel, yPixel, startRow, startColumn );
137 QgsRasterAnalysisUtils::mapToPixel( xMax, yMin, extent, xPixel, yPixel, endRow, endColumn );
140 engine->prepareGeometry();
142 for (
int row = startRow; row <= endRow; row++ )
144 for (
int col = startColumn; col <= endColumn; col++ )
151 QgsRasterAnalysisUtils::pixelToMap( row, col, extent, xPixel, yPixel, x, y );
152 if ( engine->contains( x, y ) )
154 feature.
setGeometry( std::make_unique<QgsPoint>( x, y ) );
174 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
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).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
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.
void setProgress(double progress)
Sets the current progress for the feedback object.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A raster layer parameter for processing algorithms.
Represents a raster layer.
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
A rectangle specified with double values.