24QString QgsRasterLayerPropertiesAlgorithm::name()
const
26 return QStringLiteral(
"rasterlayerproperties" );
29QString QgsRasterLayerPropertiesAlgorithm::displayName()
const
31 return QObject::tr(
"Raster layer properties" );
34QStringList QgsRasterLayerPropertiesAlgorithm::tags()
const
36 return QObject::tr(
"extent,pixel,size,width,height" ).split(
',' );
39QString QgsRasterLayerPropertiesAlgorithm::group()
const
41 return QObject::tr(
"Raster analysis" );
44QString QgsRasterLayerPropertiesAlgorithm::groupId()
const
46 return QStringLiteral(
"rasteranalysis" );
49void QgsRasterLayerPropertiesAlgorithm::initAlgorithm(
const QVariantMap & )
52 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band number" ), QVariant(), QStringLiteral(
"INPUT" ),
true ) );
59 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_WIDTH" ), QObject::tr(
"Pixel size (width) in map units" ) ) );
60 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"PIXEL_HEIGHT" ), QObject::tr(
"Pixel size (height) in map units" ) ) );
64 addOutput(
new QgsProcessingOutputBoolean( QStringLiteral(
"HAS_NODATA_VALUE" ), QObject::tr(
"Band has a NoData value set" ) ) );
69QString QgsRasterLayerPropertiesAlgorithm::shortDescription()
const
71 return QObject::tr(
"Returns basic properties of a given raster layer, including the extent, size in pixels and dimensions of pixels (in map units)." );
74QString QgsRasterLayerPropertiesAlgorithm::shortHelpString()
const
76 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"
77 "If an optional band number is specified then the NoData value for the selected band will also be returned." );
80QgsRasterLayerPropertiesAlgorithm *QgsRasterLayerPropertiesAlgorithm::createInstance()
const
82 return new QgsRasterLayerPropertiesAlgorithm();
87 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
94 if ( parameters.value( QStringLiteral(
"BAND" ) ).isValid() )
96 const int band = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
97 if ( band < 1 || band > mBandCount )
98 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( band ).arg( layer->
bandCount() ) );
100 if ( mHasNoDataValue )
104 mLayerWidth = layer->
width();
105 mLayerHeight = layer->
height();
106 mExtent = layer->
extent();
117 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
118 outputs.insert( QStringLiteral(
"X_MIN" ), mExtent.xMinimum() );
119 outputs.insert( QStringLiteral(
"X_MAX" ), mExtent.xMaximum() );
120 outputs.insert( QStringLiteral(
"Y_MIN" ), mExtent.yMinimum() );
121 outputs.insert( QStringLiteral(
"Y_MAX" ), mExtent.yMaximum() );
123 outputs.insert( QStringLiteral(
"PIXEL_WIDTH" ), mRasterUnitsPerPixelX );
124 outputs.insert( QStringLiteral(
"PIXEL_HEIGHT" ), mRasterUnitsPerPixelY );
126 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
127 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
128 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
130 outputs.insert( QStringLiteral(
"HAS_NODATA_VALUE" ), mHasNoDataValue );
131 if ( mHasNoDataValue )
132 outputs.insert( QStringLiteral(
"NODATA_VALUE" ), mNoDataValue );
133 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.