40 , visibleName( visibleName )
41 , rendererCreateFunction( rendererFunction )
42 , widgetCreateFunction( widgetFunction )
71 mEntries.insert( entry.
name, entry );
72 mSortedEntries.append( entry.
name );
77 if ( !mEntries.contains( rendererName ) )
81 mEntries[rendererName].widgetCreateFunction = func;
86 const QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.find( rendererName );
87 if ( it == mEntries.constEnd() )
97 return mSortedEntries;
102 QList< QgsRasterRendererRegistryEntry > result;
104 QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constBegin();
105 for ( ; it != mEntries.constEnd(); ++it )
107 result.push_back( it.value() );
114 if ( !provider || provider->
bandCount() < 1 )
119 std::unique_ptr< QgsRasterRenderer > renderer;
120 switch ( drawingStyle )
124 const int grayBand = 1;
129 std::unique_ptr<QgsColorRamp> ramp;
132 ramp = std::make_unique< QgsRandomColorRamp >();
135 if ( !classes.empty() )
137 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
145 if ( !classes.empty() )
147 renderer = std::make_unique< QgsPalettedRasterRenderer >( provider, grayBand, classes );
154 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
160 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
168 const int grayBand = 1;
171 QString ratErrorMessage;
174 renderer.reset( rat->createRenderer( provider, grayBand ) );
177 if ( ! ratErrorMessage.isEmpty() )
179 QgsDebugMsgLevel( QStringLiteral(
"Invalid RAT from band 1, RAT was not used to create the renderer: %1." ).arg( ratErrorMessage ), 2 );
184 renderer = std::make_unique< QgsSingleBandGrayRenderer >( provider, grayBand );
190 qgis::down_cast< QgsSingleBandGrayRenderer * >( renderer.get() )->setContrastEnhancement( ce );
197 const int bandNo = 1;
201 minMaxValuesForBand( bandNo, provider, minValue, maxValue );
203 renderer = std::make_unique< QgsSingleBandPseudoColorRenderer >( provider, bandNo, shader );
210 int redBand = s.
value( QStringLiteral(
"/Raster/defaultRedBand" ), 1 ).toInt();
211 if ( redBand < 0 || redBand > provider->
bandCount() )
215 int greenBand = s.
value( QStringLiteral(
"/Raster/defaultGreenBand" ), 2 ).toInt();
216 if ( greenBand < 0 || greenBand > provider->
bandCount() )
220 int blueBand = s.
value( QStringLiteral(
"/Raster/defaultBlueBand" ), 3 ).toInt();
221 if ( blueBand < 0 || blueBand > provider->
bandCount() )
226 renderer = std::make_unique< QgsMultiBandColorRenderer >( provider, redBand, greenBand, blueBand );
229 case Qgis::RasterDrawingStyle::SingleBandColorData:
231 renderer = std::make_unique< QgsSingleBandColorDataRenderer >( provider, 1 );
238 std::unique_ptr< QgsRasterTransparency > tr = std::make_unique< QgsRasterTransparency >();
239 const int bandCount = renderer->usesBands().size();
240 if ( bandCount == 1 )
242 const QList<QgsRasterTransparency::TransparentSingleValuePixel> transparentSingleList;
243 tr->setTransparentSingleValuePixelList( transparentSingleList );
245 else if ( bandCount == 3 )
247 const QList<QgsRasterTransparency::TransparentThreeValuePixel> transparentThreeValueList;
248 tr->setTransparentThreeValuePixelList( transparentThreeValueList );
250 renderer->setRasterTransparency( tr.release() );
251 return renderer.release();
254bool QgsRasterRendererRegistry::minMaxValuesForBand(
int band,
QgsRasterDataProvider *provider,
double &minValue,
double &maxValue )
const
265 if ( s.
value( QStringLiteral(
"/Raster/useStandardDeviation" ),
false ).toBool() )
269 const double stdDevFactor = s.
value( QStringLiteral(
"/Raster/defaultStandardDeviation" ), 2.0 ).toDouble();
270 const double diff = stdDevFactor * stats.
stdDev;
271 minValue = stats.
mean - diff;
272 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.
@ 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.
DataType
Raster data types.
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.
bool isValid(QString *errorMessage=nullptr) const
Returns true if the Raster Attribute Table is valid, optionally reporting validity checks results in ...
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 NULL) 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
virtual int bandCount() const =0
Gets number of bands.
virtual QgsRasterBandStats bandStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
void insertWidgetFunction(const QString &rendererName, QgsRasterRendererWidgetCreateFunc func)
QgsRasterRendererRegistry()
QList< QgsRasterRendererRegistryEntry > entries() const
void insert(const QgsRasterRendererRegistryEntry &entry)
bool rendererData(const QString &rendererName, QgsRasterRendererRegistryEntry &data) const
QgsRasterRenderer * defaultRendererForDrawingStyle(Qgis::RasterDrawingStyle drawingStyle, QgsRasterDataProvider *provider) const
Creates a default renderer for a raster drawing style (considering user options such as default contr...
QStringList renderersList() const
Raster renderer pipe that applies colors to a raster.
Interface for all raster shaders.
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
Constructor for QgsRasterRendererRegistryEntry.