31 #define ERR(message) QgsError(message, "Raster provider") 47 return block2( theBandNo, theExtent, theWidth, theHeight );
52 QgsDebugMsgLevel(
QString(
"theBandNo = %1 theWidth = %2 theHeight = %3" ).arg( theBandNo ).arg( theWidth ).arg( theHeight ), 4 );
81 double xRes = theExtent.
width() / theWidth;
82 double yRes = theExtent.
height() / theHeight;
83 double tmpXRes, tmpYRes;
84 double providerXRes = 0;
85 double providerYRes = 0;
90 tmpXRes = qMax( providerXRes, xRes );
91 tmpYRes = qMax( providerYRes, yRes );
101 if ( tmpExtent != theExtent ||
102 tmpXRes > xRes || tmpYRes > yRes )
106 if ( !
extent().contains( theExtent ) )
113 int fromRow = qRound(( theExtent.
yMaximum() - tmpExtent.
yMaximum() ) / yRes );
114 int toRow = qRound(( theExtent.
yMaximum() - tmpExtent.
yMinimum() ) / yRes ) - 1;
115 int fromCol = qRound(( tmpExtent.
xMinimum() - theExtent.
xMinimum() ) / xRes );
116 int toCol = qRound(( tmpExtent.
xMaximum() - theExtent.
xMinimum() ) / xRes ) - 1;
118 QgsDebugMsgLevel(
QString(
"fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
120 if ( fromRow < 0 || fromRow >= theHeight || toRow < 0 || toRow >= theHeight ||
121 fromCol < 0 || fromCol >= theWidth || toCol < 0 || toCol >= theWidth )
124 QgsDebugMsg(
"Row or column limits out of range" );
130 if ( tmpXRes > xRes )
137 if ( tmpYRes > yRes )
139 int row = floor((
extent().yMaximum() - tmpExtent.
yMaximum() ) / providerYRes );
141 row = ceil((
extent().yMaximum() - tmpExtent.
yMinimum() ) / providerYRes );
144 int tmpWidth = qRound( tmpExtent.
width() / tmpXRes );
145 int tmpHeight = qRound( tmpExtent.
height() / tmpYRes );
146 tmpXRes = tmpExtent.
width() / tmpWidth;
147 tmpYRes = tmpExtent.
height() / tmpHeight;
149 QgsDebugMsgLevel(
QString(
"Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ), 4 );
162 readBlock( theBandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->
bits(), feedback );
168 double tmpXMin = tmpExtent.
xMinimum();
169 double tmpYMax = tmpExtent.
yMaximum();
171 for (
int row = fromRow; row <= toRow; row++ )
173 double y = yMax - ( row + 0.5 ) * yRes;
174 int tmpRow = floor(( tmpYMax - y ) / tmpYRes );
176 for (
int col = fromCol; col <= toCol; col++ )
178 double x = xMin + ( col + 0.5 ) * xRes;
179 int tmpCol = floor(( x - tmpXMin ) / tmpXRes );
181 if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
183 QgsDebugMsg(
"Source row or column limits out of range" );
189 qgssize tmpIndex =
static_cast< qgssize >( tmpRow ) * static_cast< qgssize >( tmpWidth ) + tmpCol;
192 char *tmpBits = tmpBlock->
bits( tmpIndex );
193 char *bits = block->
bits( index );
196 QgsDebugMsg(
QString(
"Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
204 memcpy( bits, tmpBits, pixelSize );
212 readBlock( theBandNo, theExtent, theWidth, theHeight, block->
bits(), feedback );
246 for (
qgssize i = 0; stringList[i]; ++i )
248 strings.
append( stringList[i] );
257 return "<p>\n" + value +
"</p>\n";
295 if ( !
extent().contains( thePoint ) )
298 for (
int bandNo = 1; bandNo <=
bandCount(); bandNo++ )
312 if ( theHeight == 0 )
318 double xres = ( myExtent.
width() ) / theWidth;
319 double yres = ( myExtent.
height() ) / theHeight;
321 int col =
static_cast< int >( floor(( thePoint.
x() - myExtent.
xMinimum() ) / xres ) );
322 int row =
static_cast< int >( floor(( myExtent.
yMaximum() - thePoint.
y() ) / yres ) );
324 double xMin = myExtent.
xMinimum() + col * xres;
325 double xMax = xMin + xres;
326 double yMax = myExtent.
yMaximum() - row * yres;
327 double yMin = yMax - yres;
336 double value = myBlock->
value( 0 );
338 results.
insert( i, value );
358 if ( pPyramidResamplingMethods )
363 QgsDebugMsg(
"provider pyramidResamplingMethods returned no methods" );
372 QgsDebugMsg(
"Could not resolve pyramidResamplingMethods provider library" );
385 for ( myRasterPyramidIterator = myPyramidList.
begin();
386 myRasterPyramidIterator != myPyramidList.
end();
387 ++myRasterPyramidIterator )
389 if ( myRasterPyramidIterator->exists )
437 const QString& format,
int nBands,
439 int width,
int height,
double* geoTransform,
446 QgsDebugMsg(
"Cannot resolve 'create' function in " + providerKey +
" provider" );
451 return createFn( uri, format, nBands, type, width, height, geoTransform, crs, createOptions );
476 return tr(
"Value" );
482 return tr(
"Feature" );
bool hasPyramids()
Returns true if raster has at least one populated histogram.
virtual int bandCount() const =0
Get number of bands.
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
A rectangle specified with double values.
void copyBaseSettings(const QgsRasterDataProvider &other)
Copy member variables from other raster data provider.
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 bool contains(double value, const QgsRasterRangeList &rangeList)
Test if value is within the list of ranges.
void setXMaximum(double x)
Set the maximum x value.
virtual QgsCoordinateReferenceSystem crs()=0
Get the QgsCoordinateReferenceSystem for this layer.
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
bool userNoDataValuesContains(int bandNo, double value) const
Returns true if user no data contains value.
void applyNoDataValues(const QgsRasterRangeList &rangeList)
virtual void setUseSrcNoDataValue(int bandNo, bool use)
Set source nodata value usage.
static QString makeTableCell(const QString &value)
virtual int ySize() const
Capability
If you add to this, please also add to capabilitiesString()
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
Abstract base class for spatial data provider implementations.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
double y() const
Get the y value of the point.
bool setIsNoData(int row, int column)
Set no data on pixel.
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
Raster identify results container.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
virtual QgsRasterIdentifyResult identify(const QgsPoint &thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent=QgsRectangle(), int theWidth=0, int theHeight=0, int theDpi=96)
Identify raster value(s) found on the point position.
void append(const T &value)
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
test if rectangle is empty.
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
double width() const
Width of the rectangle.
void setYMinimum(double y)
Set the minimum y value.
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
QList< bool > mSrcHasNoDataValue
Source no data value exists.
bool setIsNoDataExcept(QRect theExceptRect)
Set the whole block to no data except specified rectangle.
virtual QgsRasterBlock * block(int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight) override
Read block of data using given extent and size.
bool isEmpty() const
Returns true if block is empty, i.e.
virtual QgsRasterBlock * block2(int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point.
QgsRasterDataProvider * createFunction_t(const QString &, const QString &, int, QGis::DataType, int, int, double *, const QgsCoordinateReferenceSystem &, QStringList)
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
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...
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
double xMaximum() const
Get the x maximum value (right side of rectangle)
QList< QPair< QString, QString > > * pyramidResamplingMethods_t()
virtual QgsRectangle extent() override=0
Get the extent of the data source.
virtual QGis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
char * bits(int row, int column)
Get pointer to data.
QList< QgsRasterRange > QgsRasterRangeList
void applyScaleOffset(double scale, double offset)
Apply band scale and offset to raster block values @note added in 2.3.
void setYMaximum(double y)
Set the maximum y value.
virtual QString metadata()=0
Get metadata in a format suitable for feeding directly into a subset of the GUI raster properties "Me...
static QString makeTableCells(const QStringList &values)
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
double value(int row, int column) const
Read a single value if type of block is numeric.
int dataTypeSize(int bandNo)
double xMinimum() const
Get the x minimum value (left side of rectangle)
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
static QStringList cStringList2Q_(char **stringList)
double yMaximum() const
Get the y maximum value (top side of rectangle)
iterator insert(const Key &key, const T &value)
void(*)() cast_to_fptr(void *p)
virtual bool srcHasNoDataValue(int bandNo) const
Return true if source band has no data value.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
static QRect subRect(const QgsRectangle &theExtent, int theWidth, int theHeight, const QgsRectangle &theSubExtent)
For theExtent and theWidht, theHeight find rectangle covered by subextent.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
Feedback object tailored for raster block reading.
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
virtual int xSize() const
Get raster size.
double x() const
Get the x value of the point.
void setXMinimum(double x)
Set the minimum x value.
double height() const
Height of the rectangle.
Base class for raster data providers.
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0...
QList< bool > mUseSrcNoDataValue
Use source nodata value.
virtual double bandScale(int bandNo) const
Read band scale for raster value.