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   int nbBlocksWidth = 
static_cast< int >( std::ceil( 1.0 * mNbCellsXProvider / maxWidth ) );
    87   int nbBlocksHeight = 
static_cast< int >( std::ceil( 1.0 * mNbCellsYProvider / maxHeight ) );
    88   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           QgsGeometry pixelRectGeometry = createGeometryForPixel( currentX, currentY, mRasterUnitsPerPixelX, mRasterUnitsPerPixelY );
   125         currentX += mRasterUnitsPerPixelX;
   127       currentY -= mRasterUnitsPerPixelY;
   132   outputs.insert( QStringLiteral( 
"OUTPUT" ), dest );
   140 QString QgsRasterPixelsToPolygonsAlgorithm::name()
 const   142   return QStringLiteral( 
"pixelstopolygons" );
   145 QString QgsRasterPixelsToPolygonsAlgorithm::displayName()
 const   147   return QObject::tr( 
"Raster pixels to polygons" );
   150 QStringList QgsRasterPixelsToPolygonsAlgorithm::tags()
 const   152   return QObject::tr( 
"vectorize,polygonize,raster,convert,pixels" ).split( 
',' );
   155 QString QgsRasterPixelsToPolygonsAlgorithm::shortHelpString()
 const   157   return QObject::tr( 
"This algorithm converts a raster layer to a vector layer, by creating polygon features "   158                       "for each individual pixel's extent in the raster layer.\n\n"   159                       "Any nodata pixels are skipped in the output." );
   162 QString QgsRasterPixelsToPolygonsAlgorithm::shortDescription()
 const   164   return QObject::tr( 
"Creates a vector layer of polygons corresponding to each pixel in a raster layer." );
   167 QgsRasterPixelsToPolygonsAlgorithm *QgsRasterPixelsToPolygonsAlgorithm::createInstance()
 const   169   return new QgsRasterPixelsToPolygonsAlgorithm();
   172 QString QgsRasterPixelsToPolygonsAlgorithm::outputName()
 const   174   return QObject::tr( 
"Vector polygons" );
   187 QgsGeometry QgsRasterPixelsToPolygonsAlgorithm::createGeometryForPixel( 
double centerX, 
double centerY, 
double pixelWidthX, 
double pixelWidthY )
 const   189   const double hCellSizeX = pixelWidthX / 2.0;
   190   const double hCellSizeY = pixelWidthY / 2.0;
   199 QString QgsRasterPixelsToPointsAlgorithm::name()
 const   201   return QStringLiteral( 
"pixelstopoints" );
   204 QString QgsRasterPixelsToPointsAlgorithm::displayName()
 const   206   return QObject::tr( 
"Raster pixels to points" );
   209 QStringList QgsRasterPixelsToPointsAlgorithm::tags()
 const   211   return QObject::tr( 
"vectorize,polygonize,raster,convert,pixels,centers" ).split( 
',' );
   214 QString QgsRasterPixelsToPointsAlgorithm::shortHelpString()
 const   216   return QObject::tr( 
"This algorithm converts a raster layer to a vector layer, by creating point features "   217                       "for each individual pixel's center in the raster layer.\n\n"   218                       "Any nodata pixels are skipped in the output." );
   221 QString QgsRasterPixelsToPointsAlgorithm::shortDescription()
 const   223   return QObject::tr( 
"Creates a vector layer of points corresponding to each pixel in a raster layer." );
   226 QgsRasterPixelsToPointsAlgorithm *QgsRasterPixelsToPointsAlgorithm::createInstance()
 const   228   return new QgsRasterPixelsToPointsAlgorithm();
   231 QString QgsRasterPixelsToPointsAlgorithm::outputName()
 const   233   return QObject::tr( 
"Vector points" );
   246 QgsGeometry QgsRasterPixelsToPointsAlgorithm::createGeometryForPixel( 
double centerX, 
double centerY, 
double, 
double )
 const 
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
A rectangle specified with double values. 
 
Base class for providing feedback from a processing algorithm. 
 
Iterator for sequentially processing raster cells. 
 
int bandCount() const
Returns the number of bands in this layer. 
 
Represents a raster layer. 
 
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis. 
 
QgsRasterInterface * clone() const override=0
Clone itself, create deep copy. 
 
void setProgress(double progress)
Sets the current progress for the feedback object. 
 
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis. 
 
Container of fields for a vector layer. 
 
A geometry is the spatial representation of a feature. 
 
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes. 
 
A raster band parameter for Processing algorithms. 
 
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
 
A feature sink output for processing algorithms. 
 
virtual QgsRectangle extent() const
Returns the extent of the layer. 
 
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle. 
 
QgsRasterDataProvider * dataProvider() override
Returns the source data provider. 
 
A raster layer parameter for processing algorithms. 
 
Type
The WKB type describes the number of dimensions a geometry has. 
 
void startRasterRead(int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Start reading of raster band. 
 
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height. 
 
Custom exception class for processing related exceptions. 
 
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) ...
 
Encapsulate a field in an attribute table or data source. 
 
Point geometry type, with support for z-dimension and m-values. 
 
bool isCanceled() const
Tells whether the operation has been canceled already. 
 
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry. 
 
SourceType
Data source types enum. 
 
double xMinimum() const
Returns the x minimum value (left side of rectangle). 
 
double yMaximum() const
Returns the y maximum value (top side of rectangle). 
 
Contains information about the context in which a processing algorithm is executed. 
 
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width. 
 
A string parameter for processing algorithms. 
 
QgsCoordinateReferenceSystem crs