QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
24 QString QgsPixelCentroidsFromPolygonsAlgorithm::name()
const
26 return QStringLiteral(
"generatepointspixelcentroidsinsidepolygons" );
29 QString QgsPixelCentroidsFromPolygonsAlgorithm::displayName()
const
31 return QObject::tr(
"Generate points (pixel centroids) inside polygons" );
34 QStringList QgsPixelCentroidsFromPolygonsAlgorithm::tags()
const
36 return QObject::tr(
"raster,polygon,centroid,pixel,create" ).split(
',' );
39 QString QgsPixelCentroidsFromPolygonsAlgorithm::group()
const
41 return QObject::tr(
"Vector creation" );
44 QString QgsPixelCentroidsFromPolygonsAlgorithm::groupId()
const
46 return QStringLiteral(
"vectorcreation" );
49 QString QgsPixelCentroidsFromPolygonsAlgorithm::shortHelpString()
const
51 return QObject::tr(
"Generates pixel centroids for the raster area falling inside polygons. Used to generate points "
52 "for further raster sampling." );
55 QgsPixelCentroidsFromPolygonsAlgorithm *QgsPixelCentroidsFromPolygonsAlgorithm::createInstance()
const
57 return new QgsPixelCentroidsFromPolygonsAlgorithm();
60 void QgsPixelCentroidsFromPolygonsAlgorithm::initAlgorithm(
const QVariantMap & )
70 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
75 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT_VECTOR" ), context ) );
80 fields.
append(
QgsField( QStringLiteral(
"id" ), QVariant::LongLong ) );
81 fields.
append(
QgsField( QStringLiteral(
"poly_id" ), QVariant::Int ) );
82 fields.
append(
QgsField( QStringLiteral(
"point_id" ), QVariant::Int ) );
89 double step = source->featureCount() ? 100.0 / source->featureCount() : 1;
123 int startRow, startColumn;
124 int endRow, endColumn;
125 QgsRasterAnalysisUtils::mapToPixel( xMin, yMax, extent, xPixel, yPixel, startRow, startColumn );
126 QgsRasterAnalysisUtils::mapToPixel( xMax, yMin, extent, xPixel, yPixel, endRow, endColumn );
129 engine->prepareGeometry();
131 for (
int row = startRow; row <= endRow; row++ )
133 for (
int col = startColumn; col <= endColumn; col++ )
140 QgsRasterAnalysisUtils::pixelToMap( row, col, extent, xPixel, yPixel, x, y );
143 if ( engine->contains( geom.constGet() ) )
162 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
QgsCoordinateReferenceSystem crs
void setProgress(double progress)
Sets the current progress for the feedback object.
Point geometry type, with support for z-dimension and m-values.
Base class for providing feedback from a processing algorithm.
@ TypeVectorPolygon
Vector polygon layers.
Container of fields for a vector layer.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
An input feature source (such as vector layers) parameter for processing algorithms.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
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)
@ TypeVectorPoint
Vector point layers.
A rectangle specified with double values.
A feature sink output for processing algorithms.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
This class wraps a request for features to a vector layer (or directly its vector data provider).
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
Contains information about the context in which a processing algorithm is executed.
virtual QgsRectangle extent() const
Returns the extent of the layer.
A raster layer parameter for processing algorithms.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Represents a raster layer.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
bool isCanceled() const
Tells whether the operation has been canceled already.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Wrapper for iterator of features from vector data provider or vector layer.
Custom exception class for processing related exceptions.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
Encapsulate a field in an attribute table or data source.