23 QString QgsRasterLayerPropertiesAlgorithm::name()
const
25 return QStringLiteral(
"rasterlayerproperties" );
28 QString QgsRasterLayerPropertiesAlgorithm::displayName()
const
30 return QObject::tr(
"Raster layer properties" );
33 QStringList QgsRasterLayerPropertiesAlgorithm::tags()
const
35 return QObject::tr(
"extent,pixel,size,width,height" ).split(
',' );
38 QString QgsRasterLayerPropertiesAlgorithm::group()
const
40 return QObject::tr(
"Raster analysis" );
43 QString QgsRasterLayerPropertiesAlgorithm::groupId()
const
45 return QStringLiteral(
"rasteranalysis" );
48 void 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" ) ) );
70 QString 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." );
76 QgsRasterLayerPropertiesAlgorithm *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 );