41 , visibleName( visibleName )
42 , capabilities( capabilities )
43 , rendererCreateFunction( rendererFunction )
44 , widgetCreateFunction( widgetFunction )
76 mEntries.insert( entry.
name, entry );
77 mSortedEntries.append( entry.
name );
82 if ( !mEntries.contains( rendererName ) )
86 mEntries[rendererName].widgetCreateFunction = func;
91 const QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.find( rendererName );
92 if ( it == mEntries.constEnd() )
102 return mSortedEntries;
107 QList< QgsRasterRendererRegistryEntry > result;
109 QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constBegin();
110 for ( ; it != mEntries.constEnd(); ++it )
112 result.push_back( it.value() );
119 const QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constFind( rendererName );
120 if ( it != mEntries.constEnd() )
122 return it.value().capabilities;
129 if ( !provider || provider->
bandCount() < 1 )
134 std::unique_ptr< QgsRasterRenderer > renderer;
135 switch ( drawingStyle )
139 const int grayBand = 1;
144 std::unique_ptr<QgsColorRamp> ramp;
147 ramp = std::make_unique< QgsRandomColorRamp >();
150 if ( !classes.empty() )
152 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
160 if ( !classes.empty() )
162 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
169 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
175 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
183 const int grayBand = 1;
186 QString ratErrorMessage;
189 renderer.reset( rat->createRenderer( provider, grayBand ) );
192 if ( ! ratErrorMessage.isEmpty() )
194 QgsDebugMsgLevel( QStringLiteral(
"Invalid RAT from band 1, RAT was not used to create the renderer: %1." ).arg( ratErrorMessage ), 2 );
199 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
205 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
212 const int bandNo = 1;
216 minMaxValuesForBand( bandNo, provider, minValue, maxValue );
218 renderer = std::make_unique< QgsSingleBandPseudoColorRenderer >( provider, bandNo, shader );
225 int redBand = s.
value( QStringLiteral(
"/Raster/defaultRedBand" ), 1 ).toInt();
226 if ( redBand < 0 || redBand > provider->
bandCount() )
230 int greenBand = s.
value( QStringLiteral(
"/Raster/defaultGreenBand" ), 2 ).toInt();
231 if ( greenBand < 0 || greenBand > provider->
bandCount() )
235 int blueBand = s.
value( QStringLiteral(
"/Raster/defaultBlueBand" ), 3 ).toInt();
236 if ( blueBand < 0 || blueBand > provider->
bandCount() )
241 renderer = std::make_unique< QgsMultiBandColorRenderer >( provider, redBand, greenBand, blueBand );
246 renderer = std::make_unique< QgsSingleBandColorDataRenderer >( provider, 1 );
253 std::unique_ptr< QgsRasterTransparency > tr = std::make_unique< QgsRasterTransparency >();
254 const int bandCount = renderer->usesBands().size();
255 if ( bandCount == 1 )
257 tr->setTransparentSingleValuePixelList( {} );
259 else if ( bandCount == 3 )
261 tr->setTransparentThreeValuePixelList( {} );
263 renderer->setRasterTransparency( tr.release() );
264 return renderer.release();
267bool QgsRasterRendererRegistry::minMaxValuesForBand(
int band,
QgsRasterDataProvider *provider,
double &minValue,
double &maxValue )
const
278 if ( s.
value( QStringLiteral(
"/Raster/useStandardDeviation" ),
false ).toBool() )
282 const double stdDevFactor = s.
value( QStringLiteral(
"/Raster/defaultStandardDeviation" ), 2.0 ).toDouble();
283 const double diff = stdDevFactor * stats.
stdDev;
284 minValue = stats.
mean - diff;
285 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.
Manipulates raster or point cloud pixel values so that they enhanceContrast or clip into a specified ...
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.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
bool hasColor() const
Returns true if the Raster Attribute Table has color RGBA information.
The RasterBandStats struct is a container for statistics about a single raster band.
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.
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.
bool rendererData(const QString &rendererName, QgsRasterRendererRegistryEntry &data) const
Retrieves renderer data from the registry.
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.
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)
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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