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 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band number" ), QVariant(), QStringLiteral(
"INPUT" ),
true ) );
58 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_WIDTH" ), QObject::tr(
"Pixel size (width) in map units" ) ) );
59 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_HEIGHT" ), QObject::tr(
"Pixel size (height) in map units" ) ) );
63 addOutput(
new QgsProcessingOutputBoolean( QStringLiteral(
"HAS_NODATA_VALUE" ), QObject::tr(
"Band has a NoData value set" ) ) );
68QString QgsRasterLayerPropertiesAlgorithm::shortHelpString()
const
70 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"
71 "If an optional band number is specified then the NoData value for the selected band will also be returned." );
74QgsRasterLayerPropertiesAlgorithm *QgsRasterLayerPropertiesAlgorithm::createInstance()
const
76 return new QgsRasterLayerPropertiesAlgorithm();
81 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
88 if ( parameters.value( QStringLiteral(
"BAND" ) ).isValid() )
90 const int band = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
91 if ( band < 1 || band > mBandCount )
92 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( band ).arg( layer->
bandCount() ) );
94 if ( mHasNoDataValue )
98 mLayerWidth = layer->
width();
99 mLayerHeight = layer->
height();
100 mExtent = layer->
extent();
111 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
112 outputs.insert( QStringLiteral(
"X_MIN" ), mExtent.xMinimum() );
113 outputs.insert( QStringLiteral(
"X_MAX" ), mExtent.xMaximum() );
114 outputs.insert( QStringLiteral(
"Y_MIN" ), mExtent.yMinimum() );
115 outputs.insert( QStringLiteral(
"Y_MAX" ), mExtent.yMaximum() );
117 outputs.insert( QStringLiteral(
"PIXEL_WIDTH" ), mRasterUnitsPerPixelX );
118 outputs.insert( QStringLiteral(
"PIXEL_HEIGHT" ), mRasterUnitsPerPixelY );
120 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
121 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
122 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
124 outputs.insert( QStringLiteral(
"HAS_NODATA_VALUE" ), mHasNoDataValue );
125 if ( mHasNoDataValue )
126 outputs.insert( QStringLiteral(
"NODATA_VALUE" ), mNoDataValue );
127 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.