40using namespace Qt::StringLiterals;
51 =
new QgsSettingsEntryDouble( u
"default-standard-deviation"_s,
QgsSettingsTree::sTreeRaster, 2.0, u
"Default standard deviation multiplier used to compute min/max values for raster contrast enhancement when \"use-standard-deviation\" is enabled."_s );
83 mEntries.insert( entry.
name, entry );
84 mSortedEntries.append( entry.
name );
89 if ( !mEntries.contains( rendererName ) )
93 mEntries[rendererName].widgetCreateFunction = func;
98 const QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.find( rendererName );
99 if ( it == mEntries.constEnd() )
109 return mSortedEntries;
114 QList< QgsRasterRendererRegistryEntry > result;
116 QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constBegin();
117 for ( ; it != mEntries.constEnd(); ++it )
119 result.push_back( it.value() );
126 const QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constFind( rendererName );
127 if ( it != mEntries.constEnd() )
129 return it.value().capabilities;
136 if ( !provider || provider->
bandCount() < 1 )
141 std::unique_ptr< QgsRasterRenderer > renderer;
142 switch ( drawingStyle )
146 const int grayBand = 1;
151 std::unique_ptr<QgsColorRamp> ramp;
154 ramp = std::make_unique< QgsRandomColorRamp >();
157 if ( !classes.empty() )
159 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
167 if ( !classes.empty() )
169 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
176 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
181 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
189 const int grayBand = 1;
192 QString ratErrorMessage;
195 renderer.reset( rat->createRenderer( provider, grayBand ) );
198 if ( !ratErrorMessage.isEmpty() )
200 QgsDebugMsgLevel( u
"Invalid RAT from band 1, RAT was not used to create the renderer: %1."_s.arg( ratErrorMessage ), 2 );
205 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
210 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
217 const int bandNo = 1;
221 minMaxValuesForBand( bandNo, provider, minValue, maxValue );
223 renderer = std::make_unique< QgsSingleBandPseudoColorRenderer >( provider, bandNo, shader );
229 if ( redBand < 0 || redBand > provider->
bandCount() )
234 if ( greenBand < 0 || greenBand > provider->
bandCount() )
239 if ( blueBand < 0 || blueBand > provider->
bandCount() )
244 renderer = std::make_unique< QgsMultiBandColorRenderer >( provider, redBand, greenBand, blueBand );
249 renderer = std::make_unique< QgsSingleBandColorDataRenderer >( provider, 1 );
256 auto tr = std::make_unique< QgsRasterTransparency >();
257 const int bandCount = renderer->usesBands().size();
258 if ( bandCount == 1 )
260 tr->setTransparentSingleValuePixelList( {} );
262 else if ( bandCount == 3 )
264 tr->setTransparentThreeValuePixelList( {} );
266 renderer->setRasterTransparency( tr.release() );
267 return renderer.release();
270bool QgsRasterRendererRegistry::minMaxValuesForBand(
int band,
QgsRasterDataProvider *provider,
double &minValue,
double &maxValue )
const
285 const double diff = stdDevFactor * stats.
stdDev;
286 minValue = stats.
mean - diff;
287 maxValue = stats.
mean + diff;
RasterDrawingStyle
Raster drawing styles.
@ SingleBandGray
A single band image drawn as a range of gray colors.
@ MultiBandSingleBandGray
A layer containing 2 or more bands, but a single band drawn as a range of gray colors.
@ SingleBandColorData
ARGB values rendered directly.
@ MultiBandColor
A layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only t...
@ PalettedColor
A "Palette" image drawn using color table.
@ SingleBandPseudoColor
A single band image drawn using a pseudocolor algorithm.
QFlags< RasterRendererCapability > RasterRendererCapabilities
Raster renderer capabilities.
@ StdDev
Standard deviation.
DataType
Raster data types.
@ UsesMultipleBands
The renderer utilizes multiple raster bands for color data (note that alpha bands are not considered ...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Handles contrast enhancement and clipping.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Factory method to create a new renderer.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData(const QgsRasterAttributeTable *attributeTable, int classificationColumn=-1, QgsColorRamp *ramp=nullptr)
Reads and returns classes from the Raster Attribute Table attributeTable, optionally classifying the ...
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
QList< QgsPalettedRasterRenderer::MultiValueClass > MultiValueClassData
Map of multi value to class properties.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
static QgsPalettedRasterRenderer::ClassData colorTableToClassData(const QList< QgsColorRampShader::ColorRampItem > &table)
Converts a raster color table to paletted renderer class data.
Represents a Raster Attribute Table (RAT).
bool hasColor() const
Returns true if the Raster Attribute Table has color RGBA information.
bool isValid(QString *errorMessage=nullptr) const
Returns true if the Raster Attribute Table is valid, optionally reporting validity checks results in ...
double mean
The mean cell value for the band. NO_DATA values are excluded.
double stdDev
The standard deviation of the cell values.
double minimumValue
The minimum cell value in the raster band.
double maximumValue
The maximum cell value in the raster band.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Creates an instance of the renderer based on definition from XML (used by renderer registry).
Base class for raster data providers.
QgsRasterAttributeTable * attributeTable(int bandNumber) const
Returns the (possibly nullptr) attribute table for the specified bandNumber.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics(int bandNo, int stats, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
virtual int bandCount() const =0
Gets number of bands.
static const QgsSettingsEntryInteger * settingsDefaultGreenBand
void insertWidgetFunction(const QString &rendererName, QgsRasterRendererWidgetCreateFunc func)
Sets the widget creation function for a renderer.
QgsRasterRendererRegistry()
Constructor for QgsRasterRendererRegistry.
QList< QgsRasterRendererRegistryEntry > entries() const
Returns the list of registered renderers.
void insert(const QgsRasterRendererRegistryEntry &entry)
Inserts a new entry into the registry.
static const QgsSettingsEntryBool * settingsUseStandardDeviation
static const QgsSettingsEntryDouble * settingsDefaultStandardDeviation
bool rendererData(const QString &rendererName, QgsRasterRendererRegistryEntry &data) const
Retrieves renderer data from the registry.
static const QgsSettingsEntryInteger * settingsDefaultRedBand
QgsRasterRenderer * defaultRendererForDrawingStyle(Qgis::RasterDrawingStyle drawingStyle, QgsRasterDataProvider *provider) const
Creates a default renderer for a raster drawing style (considering user options such as default contr...
Qgis::RasterRendererCapabilities rendererCapabilities(const QString &rendererName) const
Returns the capabilities for the renderer with the specified name.
QStringList renderersList() const
Returns a list of the names of registered renderers.
static const QgsSettingsEntryInteger * settingsDefaultBlueBand
Raster renderer pipe that applies colors to a raster.
Interface for all raster shaders.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Creates an instance of the renderer based on definition from XML (used by the renderer registry).
A boolean settings entry.
An integer settings entry.
static QgsSettingsTreeNode * sTreeRaster
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
#define QgsDebugMsgLevel(str, level)
QgsRasterRendererWidget *(* QgsRasterRendererWidgetCreateFunc)(QgsRasterLayer *, const QgsRectangle &extent)
QgsRasterRenderer *(* QgsRasterRendererCreateFunc)(const QDomElement &, QgsRasterInterface *input)
Registry for raster renderer entries.
QgsRasterRendererRegistryEntry()=default
QgsRasterRendererWidgetCreateFunc widgetCreateFunction
Qgis::RasterRendererCapabilities capabilities
Renderer capabilities.
QgsRasterRendererCreateFunc rendererCreateFunction