QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
32 #define ERR(message) QgsError(message, "Raster provider")
48 QgsDebugMsgLevel( QStringLiteral(
"bandNo = %1 width = %2 height = %3" ).arg( bandNo ).arg( width ).arg( height ), 4 );
51 std::unique_ptr< QgsRasterBlock >
block = qgis::make_unique< QgsRasterBlock >(
dataType( bandNo ), width, height );
59 QgsDebugMsg( QStringLiteral(
"Couldn't create raster block" ) );
60 block->
setError( { tr(
"Couldn't create raster block." ), QStringLiteral(
"Raster" ) } );
62 return block.release();
70 QgsDebugMsg( QStringLiteral(
"Extent outside provider extent" ) );
71 block->
setError( { tr(
"Extent outside provider extent." ), QStringLiteral(
"Raster" ) } );
74 return block.release();
77 double xRes = boundingBox.
width() / width;
78 double yRes = boundingBox.
height() / height;
79 double tmpXRes, tmpYRes;
80 double providerXRes = 0;
81 double providerYRes = 0;
86 tmpXRes = std::max( providerXRes, xRes );
87 tmpYRes = std::max( providerYRes, yRes );
97 if ( tmpExtent != boundingBox ||
98 tmpXRes > xRes || tmpYRes > yRes )
102 if ( !
extent().contains( boundingBox ) )
109 int fromRow = std::round( ( boundingBox.
yMaximum() - tmpExtent.
yMaximum() ) / yRes );
110 int toRow = std::round( ( boundingBox.
yMaximum() - tmpExtent.
yMinimum() ) / yRes ) - 1;
111 int fromCol = std::round( ( tmpExtent.
xMinimum() - boundingBox.
xMinimum() ) / xRes );
112 int toCol = std::round( ( tmpExtent.
xMaximum() - boundingBox.
xMinimum() ) / xRes ) - 1;
114 QgsDebugMsgLevel( QStringLiteral(
"fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
116 if ( fromRow < 0 || fromRow >= height || toRow < 0 || toRow >= height ||
117 fromCol < 0 || fromCol >= width || toCol < 0 || toCol >= width )
120 QgsDebugMsg( QStringLiteral(
"Row or column limits out of range" ) );
121 block->
setError( { tr(
"Row or column limits out of range" ), QStringLiteral(
"Raster" ) } );
123 return block.release();
128 if ( tmpXRes > xRes )
130 int col = std::floor( ( tmpExtent.
xMinimum() -
extent().xMinimum() ) / providerXRes );
132 col = std::ceil( ( tmpExtent.
xMaximum() -
extent().xMinimum() ) / providerXRes );
135 if ( tmpYRes > yRes )
137 int row = std::floor( (
extent().yMaximum() - tmpExtent.
yMaximum() ) / providerYRes );
139 row = std::ceil( (
extent().yMaximum() - tmpExtent.
yMinimum() ) / providerYRes );
142 int tmpWidth = std::round( tmpExtent.
width() / tmpXRes );
143 int tmpHeight = std::round( tmpExtent.
height() / tmpYRes );
144 tmpXRes = tmpExtent.
width() / tmpWidth;
145 tmpYRes = tmpExtent.
height() / tmpHeight;
147 QgsDebugMsgLevel( QStringLiteral(
"Reading smaller block tmpWidth = %1 height = %2" ).arg( tmpWidth ).arg( tmpHeight ), 4 );
150 std::unique_ptr< QgsRasterBlock > tmpBlock = qgis::make_unique< QgsRasterBlock >(
dataType( bandNo ), tmpWidth, tmpHeight );
156 if ( !
readBlock( bandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->bits(), feedback ) )
158 QgsDebugMsg( QStringLiteral(
"Error occurred while reading block" ) );
159 block->
setError( { tr(
"Error occurred while reading block." ), QStringLiteral(
"Raster" ) } );
162 return block.release();
167 double xMin = boundingBox.
xMinimum();
168 double yMax = boundingBox.
yMaximum();
169 double tmpXMin = tmpExtent.
xMinimum();
170 double tmpYMax = tmpExtent.
yMaximum();
172 for (
int row = fromRow; row <= toRow; row++ )
174 double y = yMax - ( row + 0.5 ) * yRes;
175 int tmpRow = std::floor( ( tmpYMax - y ) / tmpYRes );
177 for (
int col = fromCol; col <= toCol; col++ )
179 double x = xMin + ( col + 0.5 ) * xRes;
180 int tmpCol = std::floor( ( x - tmpXMin ) / tmpXRes );
182 if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
184 QgsDebugMsg( QStringLiteral(
"Source row or column limits out of range" ) );
186 block->
setError( { tr(
"Source row or column limits out of range." ), QStringLiteral(
"Raster" ) } );
188 return block.release();
194 char *tmpBits = tmpBlock->
bits( tmpIndex );
198 QgsDebugMsg( QStringLiteral(
"Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
203 QgsDebugMsg( QStringLiteral(
"Cannot set output block data." ) );
206 memcpy( bits, tmpBits, pixelSize );
214 QgsDebugMsg( QStringLiteral(
"Error occurred while reading block" ) );
216 block->
setError( { tr(
"Error occurred while reading block." ), QStringLiteral(
"Raster" ) } );
218 return block.release();
226 return block.release();
238 QgsDataProvider::ReadFlags flags )
268 QMap<int, QVariant> results;
272 QgsDebugMsg( QStringLiteral(
"Format not supported" ) );
276 if ( !
extent().contains( point ) )
279 for (
int bandNo = 1; bandNo <=
bandCount(); bandNo++ )
281 results.insert( bandNo, QVariant() );
300 double xres = ( finalExtent.
width() ) / width;
301 double yres = ( finalExtent.
height() ) / height;
303 int col =
static_cast< int >( std::floor( ( point.
x() - finalExtent.
xMinimum() ) / xres ) );
304 int row =
static_cast< int >( std::floor( ( finalExtent.
yMaximum() - point.
y() ) / yres ) );
306 double xMin = finalExtent.
xMinimum() + col * xres;
307 double xMax = xMin + xres;
308 double yMax = finalExtent.
yMaximum() - row * yres;
309 double yMin = yMax - yres;
314 std::unique_ptr< QgsRasterBlock > bandBlock(
block( i, pixelExtent, 1, 1 ) );
318 double value = bandBlock->value( 0 );
320 results.insert( i, value );
324 results.insert( i, QVariant() );
331 bool *ok,
const QgsRectangle &boundingBox,
int width,
int height,
int dpi )
337 const QVariant value = res.results().value( band );
339 if ( !value.isValid() )
340 return std::numeric_limits<double>::quiet_NaN();
345 return value.toDouble( ok );
350 return QStringLiteral(
"text/plain" );
359 QgsDebugMsg( QStringLiteral(
"writeBlock() called on read-only provider." ) );
369 if ( methods.isEmpty() )
371 QgsDebugMsg( QStringLiteral(
"provider pyramidResamplingMethods returned no methods" ) );
380 if ( myPyramidList.isEmpty() )
383 QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
384 for ( myRasterPyramidIterator = myPyramidList.begin();
385 myRasterPyramidIterator != myPyramidList.end();
386 ++myRasterPyramidIterator )
388 if ( myRasterPyramidIterator->exists )
405 QgsDebugMsgLevel( QStringLiteral(
"set %1 band %1 no data ranges" ).arg( noData.size() ), 4 );
429 return mTemporalCapabilities.get();
434 return mTemporalCapabilities.get();
439 const QString &format,
int nBands,
441 int width,
int height,
double *geoTransform,
443 const QStringList &createOptions )
449 height, geoTransform,
crs, createOptions );
452 QgsDebugMsg(
"Cannot resolve 'createRasterDataProviderFunction' function in " + providerKey +
" provider" );
466 return QStringLiteral(
"Value" );
468 return QStringLiteral(
"Text" );
470 return QStringLiteral(
"Html" );
472 return QStringLiteral(
"Feature" );
474 return QStringLiteral(
"Undefined" );
483 return tr(
"Value" );
489 return tr(
"Feature" );
491 return QStringLiteral(
"Undefined" );
523 return QList< double >();
558 if ( mTemporalCapabilities && other.mTemporalCapabilities )
560 *mTemporalCapabilities = *other.mTemporalCapabilities;
566 if ( str == QLatin1String(
"bilinear" ) )
570 else if ( str == QLatin1String(
"cubic" ) )
579 if ( filterElem.isNull() )
584 QDomElement resamplingElement = filterElem.firstChildElement( QStringLiteral(
"resampling" ) );
585 if ( !resamplingElement.isNull() )
587 setMaxOversampling( resamplingElement.attribute( QStringLiteral(
"maxOversampling" ), QStringLiteral(
"2.0" ) ).toDouble() );
588 setZoomedInResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral(
"zoomedInResamplingMethod" ) ) ) );
589 setZoomedOutResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral(
"zoomedOutResamplingMethod" ) ) ) );
603 return QStringLiteral(
"nearestNeighbour" );
608 QDomElement providerElement = doc.createElement( QStringLiteral(
"provider" ) );
609 parentElem.appendChild( providerElement );
611 QDomElement resamplingElement = doc.createElement( QStringLiteral(
"resampling" ) );
612 providerElement.appendChild( resamplingElement );
614 resamplingElement.setAttribute( QStringLiteral(
"enabled" ),
617 resamplingElement.setAttribute( QStringLiteral(
"zoomedInResamplingMethod" ),
620 resamplingElement.setAttribute( QStringLiteral(
"zoomedOutResamplingMethod" ),
623 resamplingElement.setAttribute( QStringLiteral(
"maxOversampling" ),
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
DataType
Raster data types.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Setting options for creating vector data providers.
Abstract base class for spatial data provider implementations.
void applyNoDataValues(const QgsRasterRangeList &rangeList)
@ Nearest
Nearest-neighbour resamplikng.
Point geometry type, with support for z-dimension and m-values.
int dpi() const
Returns the dpi of the output device.
#define QgsDebugMsgLevel(str, level)
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
@ Cubic
Bicubic resamplikng.
virtual QgsPoint transformCoordinates(const QgsPoint &point, TransformType type)
Transforms coordinates between source image coordinate space [0..width]x[0..height] and layer coordin...
const QgsCoordinateReferenceSystem & crs
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
void copyBaseSettings(const QgsRasterDataProvider &other)
Copy member variables from other raster data provider. Useful for implementation of clone() method in...
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
QList< bool > mSrcHasNoDataValue
Source no data value exists.
QgsRectangle extent() const override=0
Returns the extent of the layer.
int width() const SIP_HOLDGIL
Returns the width (number of columns) of the raster block.
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
ResamplingMethod mZoomedInResamplingMethod
Resampling method for zoomed in pixel extraction.
bool mProviderResamplingEnabled
Whether provider resampling is enabled.
char * bits(int row, int column)
Returns a pointer to block data.
ResamplingMethod mZoomedOutResamplingMethod
Resampling method for zoomed out pixel extraction.
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
virtual bool enableProviderResampling(bool enable)
Enable or disable provider-level resampling.
A rectangle specified with double values.
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0.
@ Bilinear
Bilinear resamplikng.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
virtual bool setZoomedInResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
virtual QList< double > nativeResolutions() const
Returns a list of native resolutions if available, i.e.
virtual bool sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns list of raster pyramid resampling methods.
static QRect subRect(const QgsRectangle &extent, int width, int height, const QgsRectangle &subExtent)
For extent and width, height find rectangle covered by subextent.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
QgsRasterBlock * block(int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
ResamplingMethod
Resampling method for provider-level resampling.
virtual int xSize() const
Gets raster size.
Raster identify results container.
virtual QgsRasterDataProvider * createRasterDataProvider(const QString &providerKey, const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates new instance of raster data provider.
bool writeBlock(QgsRasterBlock *block, int band, int xOffset=0, int yOffset=0)
Writes pixel data from a raster block into the provider data source.
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
virtual double sample(const QgsPointXY &point, int band, bool *ok=nullptr, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Samples a raster value from the specified band found at the point position.
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
bool setIsNoDataExcept(QRect exceptRect)
Set the whole block to no data except specified rectangle.
@ NoProviderCapabilities
Provider has no capabilities.
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
virtual QgsRasterIdentifyResult identify(const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
void setError(const QgsError &error)
Sets the last error.
virtual double bandScale(int bandNo) const
Read band scale for raster value.
QList< QgsRasterRange > QgsRasterRangeList
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
int height() const SIP_HOLDGIL
Returns the height (number of rows) of the raster block.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
bool contains(double value) const
Returns true if this range contains the specified value.
bool isEmpty() const
Returns true if block is empty, i.e.
This class represents a coordinate reference system (CRS).
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
virtual bool ignoreExtents() const
Returns true if the extents reported by the data provider are not reliable and it's possible that the...
virtual int ySize() const
TransformType
Types of transformation in transformCoordinates() function.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
A class to represent a 2D point.
virtual bool setMaxOversampling(double factor)
Sets maximum oversampling factor for zoomed-out operations.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Returns the raster layers pyramid list.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
void setValid(bool valid) SIP_HOLDGIL
Mark block as valid or invalid.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setNoDataValue(double noDataValue) SIP_HOLDGIL
Sets cell value that will be considered as "no data".
Capability
If you add to this, please also add to capabilitiesString()
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QList< bool > mUseSrcNoDataValue
Use source nodata value.
virtual bool readBlock(int bandNo, int xBlock, int yBlock, void *data)
Reads a block of raster data into data.
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
Feedback object tailored for raster block reading.
void applyScaleOffset(double scale, double offset)
Apply band scale and offset to raster block values.
QgsRasterDataProvider()
Provider capabilities.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
virtual bool setZoomedOutResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
bool userNoDataValuesContains(int bandNo, double value) const
Returns true if user no data contains value.
virtual int bandCount() const =0
Gets number of bands.
static QgsRasterDataProvider * create(const QString &providerKey, const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates a new dataset with mDataSourceURI.
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
bool hasPyramids()
Returns true if raster has at least one populated histogram.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
bool isEmpty() const
Returns true if the rectangle is empty.
virtual QString htmlMetadata()=0
Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties...
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Base class for raster data providers.
int dataTypeSize(int bandNo)
Implementation of data provider temporal properties for QgsRasterDataProviders.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
bool setIsNoData(int row, int column) SIP_HOLDGIL
Set no data on pixel.
@ IdentifyFormatUndefined
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...