QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
31 #define ERR(message) QgsError(message, "Raster provider")
47 QgsDebugMsgLevel( QStringLiteral(
"bandNo = %1 width = %2 height = %3" ).arg( bandNo ).arg( width ).arg( height ), 4 );
50 std::unique_ptr< QgsRasterBlock >
block = qgis::make_unique< QgsRasterBlock >(
dataType( bandNo ), width, height );
58 QgsDebugMsg( QStringLiteral(
"Couldn't create raster block" ) );
59 return block.release();
67 QgsDebugMsg( QStringLiteral(
"Extent outside provider extent" ) );
69 return block.release();
72 double xRes = boundingBox.
width() / width;
73 double yRes = boundingBox.
height() / height;
74 double tmpXRes, tmpYRes;
75 double providerXRes = 0;
76 double providerYRes = 0;
81 tmpXRes = std::max( providerXRes, xRes );
82 tmpYRes = std::max( providerYRes, yRes );
92 if ( tmpExtent != boundingBox ||
93 tmpXRes > xRes || tmpYRes > yRes )
97 if ( !
extent().contains( boundingBox ) )
104 int fromRow = std::round( ( boundingBox.
yMaximum() - tmpExtent.
yMaximum() ) / yRes );
105 int toRow = std::round( ( boundingBox.
yMaximum() - tmpExtent.
yMinimum() ) / yRes ) - 1;
106 int fromCol = std::round( ( tmpExtent.
xMinimum() - boundingBox.
xMinimum() ) / xRes );
107 int toCol = std::round( ( tmpExtent.
xMaximum() - boundingBox.
xMinimum() ) / xRes ) - 1;
109 QgsDebugMsgLevel( QStringLiteral(
"fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
111 if ( fromRow < 0 || fromRow >= height || toRow < 0 || toRow >= height ||
112 fromCol < 0 || fromCol >= width || toCol < 0 || toCol >= width )
115 QgsDebugMsg( QStringLiteral(
"Row or column limits out of range" ) );
116 return block.release();
121 if ( tmpXRes > xRes )
123 int col = std::floor( ( tmpExtent.
xMinimum() -
extent().xMinimum() ) / providerXRes );
125 col = std::ceil( ( tmpExtent.
xMaximum() -
extent().xMinimum() ) / providerXRes );
128 if ( tmpYRes > yRes )
130 int row = std::floor( (
extent().yMaximum() - tmpExtent.
yMaximum() ) / providerYRes );
132 row = std::ceil( (
extent().yMaximum() - tmpExtent.
yMinimum() ) / providerYRes );
135 int tmpWidth = std::round( tmpExtent.
width() / tmpXRes );
136 int tmpHeight = std::round( tmpExtent.
height() / tmpYRes );
137 tmpXRes = tmpExtent.
width() / tmpWidth;
138 tmpYRes = tmpExtent.
height() / tmpHeight;
140 QgsDebugMsgLevel( QStringLiteral(
"Reading smaller block tmpWidth = %1 height = %2" ).arg( tmpWidth ).arg( tmpHeight ), 4 );
143 std::unique_ptr< QgsRasterBlock > tmpBlock = qgis::make_unique< QgsRasterBlock >(
dataType( bandNo ), tmpWidth, tmpHeight );
149 if ( !
readBlock( bandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->bits(), feedback ) )
151 QgsDebugMsg( QStringLiteral(
"Error occurred while reading block" ) );
153 return block.release();
158 double xMin = boundingBox.
xMinimum();
159 double yMax = boundingBox.
yMaximum();
160 double tmpXMin = tmpExtent.
xMinimum();
161 double tmpYMax = tmpExtent.
yMaximum();
163 for (
int row = fromRow; row <= toRow; row++ )
165 double y = yMax - ( row + 0.5 ) * yRes;
166 int tmpRow = std::floor( ( tmpYMax - y ) / tmpYRes );
168 for (
int col = fromCol; col <= toCol; col++ )
170 double x = xMin + ( col + 0.5 ) * xRes;
171 int tmpCol = std::floor( ( x - tmpXMin ) / tmpXRes );
173 if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
175 QgsDebugMsg( QStringLiteral(
"Source row or column limits out of range" ) );
177 return block.release();
183 char *tmpBits = tmpBlock->
bits( tmpIndex );
187 QgsDebugMsg( QStringLiteral(
"Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
192 QgsDebugMsg( QStringLiteral(
"Cannot set output block data." ) );
195 memcpy( bits, tmpBits, pixelSize );
203 QgsDebugMsg( QStringLiteral(
"Error occurred while reading block" ) );
205 return block.release();
213 return block.release();
254 QMap<int, QVariant> results;
258 QgsDebugMsg( QStringLiteral(
"Format not supported" ) );
262 if ( !
extent().contains( point ) )
265 for (
int bandNo = 1; bandNo <=
bandCount(); bandNo++ )
267 results.insert( bandNo, QVariant() );
286 double xres = ( finalExtent.
width() ) / width;
287 double yres = ( finalExtent.
height() ) / height;
289 int col =
static_cast< int >( std::floor( ( point.
x() - finalExtent.
xMinimum() ) / xres ) );
290 int row =
static_cast< int >( std::floor( ( finalExtent.
yMaximum() - point.
y() ) / yres ) );
292 double xMin = finalExtent.
xMinimum() + col * xres;
293 double xMax = xMin + xres;
294 double yMax = finalExtent.
yMaximum() - row * yres;
295 double yMin = yMax - yres;
300 std::unique_ptr< QgsRasterBlock > bandBlock(
block( i, pixelExtent, 1, 1 ) );
304 double value = bandBlock->value( 0 );
306 results.insert( i, value );
310 results.insert( i, QVariant() );
317 bool *ok,
const QgsRectangle &boundingBox,
int width,
int height,
int dpi )
323 const QVariant value = res.results().value( band );
325 if ( !value.isValid() )
326 return std::numeric_limits<double>::quiet_NaN();
331 return value.toDouble( ok );
336 return QStringLiteral(
"text/plain" );
345 QgsDebugMsg( QStringLiteral(
"writeBlock() called on read-only provider." ) );
355 if ( methods.isEmpty() )
357 QgsDebugMsg( QStringLiteral(
"provider pyramidResamplingMethods returned no methods" ) );
366 if ( myPyramidList.isEmpty() )
369 QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
370 for ( myRasterPyramidIterator = myPyramidList.begin();
371 myRasterPyramidIterator != myPyramidList.end();
372 ++myRasterPyramidIterator )
374 if ( myRasterPyramidIterator->exists )
391 QgsDebugMsgLevel( QStringLiteral(
"set %1 band %1 no data ranges" ).arg( noData.size() ), 4 );
415 return mTemporalCapabilities.get();
420 return mTemporalCapabilities.get();
425 const QString &format,
int nBands,
427 int width,
int height,
double *geoTransform,
429 const QStringList &createOptions )
435 height, geoTransform,
crs, createOptions );
438 QgsDebugMsg(
"Cannot resolve 'createRasterDataProviderFunction' function in " + providerKey +
" provider" );
452 return QStringLiteral(
"Value" );
454 return QStringLiteral(
"Text" );
456 return QStringLiteral(
"Html" );
458 return QStringLiteral(
"Feature" );
460 return QStringLiteral(
"Undefined" );
469 return tr(
"Value" );
475 return tr(
"Feature" );
477 return QStringLiteral(
"Undefined" );
509 return QList< double >();
540 if ( mTemporalCapabilities && other.mTemporalCapabilities )
542 *mTemporalCapabilities = *other.mTemporalCapabilities;
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
DataType
Raster data types.
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.
void applyNoDataValues(const QgsRasterRangeList &rangeList)
Point geometry type, with support for z-dimension and m-values.
int dpi() const
Returns the dpi of the output device.
void setXMinimum(double x)
Set the minimum x value.
#define QgsDebugMsgLevel(str, level)
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
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
double xMaximum() const
Returns the x maximum value (right side of rectangle).
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...
QList< bool > mSrcHasNoDataValue
Source no data value exists.
QgsRectangle extent() const override=0
Returns the extent of the layer.
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
char * bits(int row, int column)
Returns a pointer to block data.
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
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.
QgsRasterBlock * block(int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
bool setIsNoData(int row, int column)
Set no data on pixel.
virtual int xSize() const
Gets raster size.
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.
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.
void setNoDataValue(double noDataValue)
Sets cell value that will be considered as "no data".
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 setXMaximum(double x)
Set the maximum x value.
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.
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.
virtual bool ignoreExtents() const
Returns true if the extents reported by the data provider are not reliable and it's possible that the...
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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...
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
int width() const
Returns the width (number of columns) of the raster block.
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.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
Capability
If you add to this, please also add to capabilitiesString()
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.
double height() const
Returns the height of the rectangle.
void applyScaleOffset(double scale, double offset)
Apply band scale and offset to raster block values.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsRasterDataProvider()
Provider capabilities.
int height() const
Returns the height (number of rows) of the raster block.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
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.
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
double width() const
Returns the width of the rectangle.
void setYMinimum(double y)
Set the minimum y value.
void setYMaximum(double y)
Set the maximum y value.
int dataTypeSize(int bandNo)
double xMinimum() const
Returns the x minimum value (left side of rectangle).
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
@ 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...