24 QString QgsVectorizeAlgorithmBase::group()
const
26 return QObject::tr(
"Vector creation" );
29 QString QgsVectorizeAlgorithmBase::groupId()
const
31 return QStringLiteral(
"vectorcreation" );
34 void QgsVectorizeAlgorithmBase::initAlgorithm(
const QVariantMap & )
37 QObject::tr(
"Raster layer" ) ) );
39 QObject::tr(
"Band number" ), 1, QStringLiteral(
"INPUT_RASTER" ) ) );
41 QObject::tr(
"Field name" ), QStringLiteral(
"VALUE" ) ) );
48 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
53 mBand = parameterAsInt( parameters, QStringLiteral(
"RASTER_BAND" ), context );
54 if ( mBand < 1 || mBand > layer->
bandCount() )
55 throw QgsProcessingException( QObject::tr(
"Invalid band number for RASTER_BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand )
63 mNbCellsXProvider = mInterface->xSize();
64 mNbCellsYProvider = mInterface->ySize();
70 const QString fieldName = parameterAsString( parameters, QStringLiteral(
"FIELD_NAME" ), context );
72 fields.
append(
QgsField( fieldName, QVariant::Double, QString(), 20, 8 ) );
75 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields, sinkType(), mCrs ) );
84 iter.startRasterRead( mBand, mNbCellsXProvider, mNbCellsYProvider, mExtent );
86 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mNbCellsXProvider / maxWidth ) );
87 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mNbCellsYProvider / maxHeight ) );
88 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
94 std::unique_ptr< QgsRasterBlock > rasterBlock;
96 bool isNoData =
false;
97 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop, &blockExtent ) )
100 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
104 double currentY = blockExtent.
yMaximum() - 0.5 * mRasterUnitsPerPixelY;
106 for (
int row = 0; row < iterRows; row++ )
111 double currentX = blockExtent.
xMinimum() + 0.5 * mRasterUnitsPerPixelX;
113 for (
int column = 0; column < iterCols; column++ )
115 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
118 const QgsGeometry pixelRectGeometry = createGeometryForPixel( currentX, currentY, mRasterUnitsPerPixelX, mRasterUnitsPerPixelY );
126 currentX += mRasterUnitsPerPixelX;
128 currentY -= mRasterUnitsPerPixelY;
133 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
141 QString QgsRasterPixelsToPolygonsAlgorithm::name()
const
143 return QStringLiteral(
"pixelstopolygons" );
146 QString QgsRasterPixelsToPolygonsAlgorithm::displayName()
const
148 return QObject::tr(
"Raster pixels to polygons" );
151 QStringList QgsRasterPixelsToPolygonsAlgorithm::tags()
const
153 return QObject::tr(
"vectorize,polygonize,raster,convert,pixels" ).split(
',' );
156 QString QgsRasterPixelsToPolygonsAlgorithm::shortHelpString()
const
158 return QObject::tr(
"This algorithm converts a raster layer to a vector layer, by creating polygon features "
159 "for each individual pixel's extent in the raster layer.\n\n"
160 "Any nodata pixels are skipped in the output." );
163 QString QgsRasterPixelsToPolygonsAlgorithm::shortDescription()
const
165 return QObject::tr(
"Creates a vector layer of polygons corresponding to each pixel in a raster layer." );
168 QgsRasterPixelsToPolygonsAlgorithm *QgsRasterPixelsToPolygonsAlgorithm::createInstance()
const
170 return new QgsRasterPixelsToPolygonsAlgorithm();
173 QString QgsRasterPixelsToPolygonsAlgorithm::outputName()
const
175 return QObject::tr(
"Vector polygons" );
188 QgsGeometry QgsRasterPixelsToPolygonsAlgorithm::createGeometryForPixel(
double centerX,
double centerY,
double pixelWidthX,
double pixelWidthY )
const
190 const double hCellSizeX = pixelWidthX / 2.0;
191 const double hCellSizeY = pixelWidthY / 2.0;
200 QString QgsRasterPixelsToPointsAlgorithm::name()
const
202 return QStringLiteral(
"pixelstopoints" );
205 QString QgsRasterPixelsToPointsAlgorithm::displayName()
const
207 return QObject::tr(
"Raster pixels to points" );
210 QStringList QgsRasterPixelsToPointsAlgorithm::tags()
const
212 return QObject::tr(
"vectorize,polygonize,raster,convert,pixels,centers" ).split(
',' );
215 QString QgsRasterPixelsToPointsAlgorithm::shortHelpString()
const
217 return QObject::tr(
"This algorithm converts a raster layer to a vector layer, by creating point features "
218 "for each individual pixel's center in the raster layer.\n\n"
219 "Any nodata pixels are skipped in the output." );
222 QString QgsRasterPixelsToPointsAlgorithm::shortDescription()
const
224 return QObject::tr(
"Creates a vector layer of points corresponding to each pixel in a raster layer." );
227 QgsRasterPixelsToPointsAlgorithm *QgsRasterPixelsToPointsAlgorithm::createInstance()
const
229 return new QgsRasterPixelsToPointsAlgorithm();
232 QString QgsRasterPixelsToPointsAlgorithm::outputName()
const
234 return QObject::tr(
"Vector points" );
247 QgsGeometry QgsRasterPixelsToPointsAlgorithm::createGeometryForPixel(
double centerX,
double centerY,
double,
double )
const