Skip to content
Permalink
Browse files
optimization
  • Loading branch information
vcloarec authored and nyalldawson committed Jan 8, 2022
1 parent 0f65a46 commit 4def77c106d87d822c2c477514c3ab67816a0168
Showing with 59 additions and 23 deletions.
  1. +25 −10 src/providers/wms/qgswmsprovider.cpp
  2. +34 −13 src/providers/wms/qgswmsprovider.h
@@ -222,7 +222,7 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri, const ProviderOptions &optio
// 3) http://xxx.xxx.xx/yyy/yyy?zzz=www


mConverter.reset( QgsWmsConverter::createConverter( mSettings.mEncodingScheme ) );
mConverter = QgsWmsConverter::createConverter( mSettings.mEncodingScheme );

mValid = true;
QgsDebugMsgLevel( QStringLiteral( "exiting constructor." ), 4 );
@@ -887,7 +887,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
r.rect.width() / cr,
r.rect.height() / cr );
// if image size is "close enough" to destination size, don't smooth it out. Instead try for pixel-perfect placement!
bool disableSmoothing = ( qgsDoubleNear( dst.width(), tm->tileWidth, 2 ) && qgsDoubleNear( dst.height(), tm->tileHeight, 2 ) ) || mConverter ;
bool disableSmoothing = mConverter || ( qgsDoubleNear( dst.width(), tm->tileWidth, 2 ) && qgsDoubleNear( dst.height(), tm->tileHeight, 2 ) );
tileImages << TileImage( dst, localImage, !disableSmoothing );
}
else
@@ -1038,7 +1038,9 @@ bool QgsWmsProvider::readBlock( int bandNo, QgsRectangle const &viewExtent, int

}
else
{
memcpy( block, ptr, myExpectedSize );
}

return true;
}
@@ -3697,18 +3699,31 @@ QgsLayerMetadata QgsWmsProvider::layerMetadata() const
return mLayerMetadata;
}

QgsRasterBandStats QgsWmsProvider::bandStatistics( int, int, const QgsRectangle &, int, QgsRasterBlockFeedback * )
QgsRasterBandStats QgsWmsProvider::bandStatistics(
int bandNo,
int stats,
const QgsRectangle &extent,
int sampleSize,
QgsRasterBlockFeedback *feedback )
{
if ( mConverter )
return mConverter->statistics();
return mConverter->statistics( bandNo, stats, extent, sampleSize, feedback );
else
return QgsRasterBandStats();
}

QgsRasterHistogram QgsWmsProvider::histogram( int, int, double, double, const QgsRectangle &, int, bool, QgsRasterBlockFeedback * )
QgsRasterHistogram QgsWmsProvider::histogram(
int bandNo,
int binCount,
double minimum,
double maximum,
const QgsRectangle &extent,
int sampleSize,
bool includeOutOfRange,
QgsRasterBlockFeedback *feedback )
{
if ( mConverter )
return mConverter->histogram();
return mConverter->histogram( bandNo, binCount, minimum, maximum, extent, sampleSize, includeOutOfRange, feedback );
else
return QgsRasterHistogram();
}
@@ -4833,10 +4848,10 @@ Qgis::DataType QgsWmsConverter::dataType() const
return Qgis::DataType::Float32;
}

QgsWmsConverter *QgsWmsConverter::createConverter( const QString &key )
std::unique_ptr<QgsWmsConverter> QgsWmsConverter::createConverter( const QString &key )
{
if ( key == QgsWmsConverterMapTilerTerrainRGB::encodingSchemeKey() )
return new QgsWmsConverterMapTilerTerrainRGB();
return std::make_unique<QgsWmsConverterMapTilerTerrainRGB>();

return nullptr;
}
@@ -4850,7 +4865,7 @@ void QgsWmsConverterMapTilerTerrainRGB::convert( const QRgb &color, float *conve
*converted = -10000 + ( ( R * 256 * 256 + G * 256 + B ) ) * 0.1;
}

QgsRasterBandStats QgsWmsConverterMapTilerTerrainRGB::statistics() const
QgsRasterBandStats QgsWmsConverterMapTilerTerrainRGB::statistics( int, int, const QgsRectangle &, int, QgsRasterBlockFeedback * ) const
{
QgsRasterBandStats stat;
stat.minimumValue = 0;
@@ -4859,7 +4874,7 @@ QgsRasterBandStats QgsWmsConverterMapTilerTerrainRGB::statistics() const
return stat;
}

QgsRasterHistogram QgsWmsConverterMapTilerTerrainRGB::histogram() const
QgsRasterHistogram QgsWmsConverterMapTilerTerrainRGB::histogram( int, int, double, double, const QgsRectangle &, int, bool, QgsRasterBlockFeedback * ) const
{
return QgsRasterHistogram();
}
@@ -112,13 +112,23 @@ class QgsWmsConverter
virtual Qgis::DataType dataType() const;

//! Returns statistics related to converted values
virtual QgsRasterBandStats statistics() const = 0;
virtual QgsRasterBandStats statistics( int bandNo,
int stats = QgsRasterBandStats::All,
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) const = 0;

//! Returns the histogram related to converted values
virtual QgsRasterHistogram histogram() const = 0;
virtual QgsRasterHistogram histogram( int bandNo,
int binCount = 0,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0,
bool includeOutOfRange = false,
QgsRasterBlockFeedback *feedback = nullptr ) const = 0;

//! Creates a converter instance corresponding to the \a key
static QgsWmsConverter *createConverter( const QString &key );
static std::unique_ptr<QgsWmsConverter> createConverter( const QString &key );
};


@@ -128,8 +138,19 @@ class QgsWmsConverterMapTilerTerrainRGB : public QgsWmsConverter
public:
void convert( const QRgb &color, float *converted ) const override;

QgsRasterBandStats statistics() const override;
QgsRasterHistogram histogram() const override;
QgsRasterBandStats statistics( int bandNo,
int stats = QgsRasterBandStats::All,
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) const override;

QgsRasterHistogram histogram( int bandNo,
int binCount = 0,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0,
bool includeOutOfRange = false,
QgsRasterBlockFeedback *feedback = nullptr ) const override;

static QString displayName() {return QObject::tr( "MapTiler Terrain RGB" );}
static QString encodingSchemeKey() {return QStringLiteral( "maptilerterrain" );}
@@ -260,14 +281,14 @@ class QgsWmsProvider final: public QgsRasterDataProvider
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) override;

virtual QgsRasterHistogram histogram( int bandNo,
int binCount = 0,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0,
bool includeOutOfRange = false,
QgsRasterBlockFeedback *feedback = nullptr ) override;
QgsRasterHistogram histogram( int bandNo,
int binCount = 0,
double minimum = std::numeric_limits<double>::quiet_NaN(),
double maximum = std::numeric_limits<double>::quiet_NaN(),
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0,
bool includeOutOfRange = false,
QgsRasterBlockFeedback *feedback = nullptr ) override;

static QVector<QgsWmsSupportedFormat> supportedFormats();

0 comments on commit 4def77c

Please sign in to comment.