23QString QgsRasterLayerPropertiesAlgorithm::name()
const
25 return QStringLiteral(
"rasterlayerproperties" );
28QString QgsRasterLayerPropertiesAlgorithm::displayName()
const
30 return QObject::tr(
"Raster layer properties" );
33QStringList QgsRasterLayerPropertiesAlgorithm::tags()
const
35 return QObject::tr(
"extent,pixel,size,width,height" ).split(
',' );
38QString QgsRasterLayerPropertiesAlgorithm::group()
const
40 return QObject::tr(
"Raster analysis" );
43QString QgsRasterLayerPropertiesAlgorithm::groupId()
const
45 return QStringLiteral(
"rasteranalysis" );
48void QgsRasterLayerPropertiesAlgorithm::initAlgorithm(
const QVariantMap & )
51 QObject::tr(
"Input layer" ) ) );
53 QObject::tr(
"Band number" ), QVariant(), QStringLiteral(
"INPUT" ),
true ) );
60 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_WIDTH" ), QObject::tr(
"Pixel size (width) in map units" ) ) );
61 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_HEIGHT" ), QObject::tr(
"Pixel size (height) in map units" ) ) );
65 addOutput(
new QgsProcessingOutputBoolean( QStringLiteral(
"HAS_NODATA_VALUE" ), QObject::tr(
"Band has a nodata value set" ) ) );
70QString QgsRasterLayerPropertiesAlgorithm::shortHelpString()
const
72 return QObject::tr(
"This algorithm returns basic properties of the given raster layer, including the extent, size in pixels and dimensions of pixels (in map units).\n\n"
73 "If an optional band number is specified then the nodata value for the selected band will also be returned." );
76QgsRasterLayerPropertiesAlgorithm *QgsRasterLayerPropertiesAlgorithm::createInstance()
const
78 return new QgsRasterLayerPropertiesAlgorithm();
83 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
90 if ( parameters.value( QStringLiteral(
"BAND" ) ).isValid() )
92 const int band = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
93 if ( band < 1 || band > mBandCount )
94 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( band )
97 if ( mHasNoDataValue )
101 mLayerWidth = layer->
width();
102 mLayerHeight = layer->
height();
103 mExtent = layer->
extent();
114 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
115 outputs.insert( QStringLiteral(
"X_MIN" ), mExtent.xMinimum() );
116 outputs.insert( QStringLiteral(
"X_MAX" ), mExtent.xMaximum() );
117 outputs.insert( QStringLiteral(
"Y_MIN" ), mExtent.yMinimum() );
118 outputs.insert( QStringLiteral(
"Y_MAX" ), mExtent.yMaximum() );
120 outputs.insert( QStringLiteral(
"PIXEL_WIDTH" ), mRasterUnitsPerPixelX );
121 outputs.insert( QStringLiteral(
"PIXEL_HEIGHT" ), mRasterUnitsPerPixelY );
123 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
124 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
125 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
127 outputs.insert( QStringLiteral(
"HAS_NODATA_VALUE" ), mHasNoDataValue );
128 if ( mHasNoDataValue )
129 outputs.insert( QStringLiteral(
"NODATA_VALUE" ), mNoDataValue );
130 outputs.insert( QStringLiteral(
"BAND_COUNT" ), mBandCount );
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A boolean output for processing algorithms.
A numeric output for processing algorithms.
A string output for processing algorithms.
A raster band parameter for Processing algorithms.
A raster layer parameter for processing algorithms.
virtual bool sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
Represents a raster layer.
int height() const
Returns the height of the (unclipped) raster.
int bandCount() const
Returns the number of bands in this layer.
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
int width() const
Returns the width of the (unclipped) raster.