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 );