31 #define ERRMSG(message) QGS_ERROR_MESSAGE(message, "Raster provider")
32 #define ERR(message) QgsError(message, "Raster provider")
48 QgsDebugMsg( QString(
"theBandNo = %1 theWidth = %2 theHeight = %3" ).arg( theBandNo ).arg( theWidth ).arg( theHeight ) );
77 double xRes = theExtent.
width() / theWidth;
78 double yRes = theExtent.
height() / theHeight;
79 double tmpXRes, tmpYRes;
80 double providerXRes = 0;
81 double providerYRes = 0;
86 tmpXRes = qMax( providerXRes, xRes );
87 tmpYRes = qMax( providerYRes, yRes );
97 if ( tmpExtent != theExtent ||
98 tmpXRes > xRes || tmpYRes > yRes )
102 if ( !
extent().contains( theExtent ) )
109 int fromRow = qRound(( theExtent.
yMaximum() - tmpExtent.
yMaximum() ) / yRes );
110 int toRow = qRound(( theExtent.
yMaximum() - tmpExtent.
yMinimum() ) / yRes ) - 1;
111 int fromCol = qRound(( tmpExtent.
xMinimum() - theExtent.
xMinimum() ) / xRes ) ;
112 int toCol = qRound(( tmpExtent.
xMaximum() - theExtent.
xMinimum() ) / xRes ) - 1;
114 QgsDebugMsg( QString(
"fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ) );
116 if ( fromRow < 0 || fromRow >= theHeight || toRow < 0 || toRow >= theHeight ||
117 fromCol < 0 || fromCol >= theWidth || toCol < 0 || toCol >= theWidth )
120 QgsDebugMsg(
"Row or column limits out of range" );
126 if ( tmpXRes > xRes )
133 if ( tmpYRes > yRes )
135 int row = floor((
extent().yMaximum() - tmpExtent.
yMaximum() ) / providerYRes );
137 row = ceil((
extent().yMaximum() - tmpExtent.
yMinimum() ) / providerYRes );
140 int tmpWidth = qRound( tmpExtent.
width() / tmpXRes );
141 int tmpHeight = qRound( tmpExtent.
height() / tmpYRes );
142 tmpXRes = tmpExtent.
width() / tmpWidth;
143 tmpYRes = tmpExtent.
height() / tmpHeight;
145 QgsDebugMsg( QString(
"Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ) );
158 readBlock( theBandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->
bits() );
164 double tmpXMin = tmpExtent.
xMinimum();
165 double tmpYMax = tmpExtent.
yMaximum();
167 for (
int row = fromRow; row <= toRow; row++ )
169 double y = yMax - ( row + 0.5 ) * yRes;
170 int tmpRow = floor(( tmpYMax - y ) / tmpYRes );
172 for (
int col = fromCol; col <= toCol; col++ )
174 double x = xMin + ( col + 0.5 ) * xRes;
175 int tmpCol = floor(( x - tmpXMin ) / tmpXRes );
177 if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
179 QgsDebugMsg(
"Source row or column limits out of range" );
185 qgssize tmpIndex = tmpRow * tmpWidth + tmpCol;
188 char *tmpBits = tmpBlock->
bits( tmpIndex );
189 char *bits = block->
bits( index );
192 QgsDebugMsg( QString(
"Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
200 memcpy( bits, tmpBits, pixelSize );
208 readBlock( theBandNo, theExtent, theWidth, theHeight, block->
bits() );
242 for (
qgssize i = 0; stringList[i]; ++i )
244 strings.append( stringList[i] );
253 return "<p>\n" + value +
"</p>\n";
261 for ( QStringList::const_iterator i = values.begin();
283 QMap<int, QVariant> results;
291 if ( !
extent().contains( thePoint ) )
294 for (
int bandNo = 1; bandNo <=
bandCount(); bandNo++ )
296 results.insert( bandNo, QVariant() );
308 if ( theHeight == 0 )
314 double xres = ( myExtent.
width() ) / theWidth;
315 double yres = ( myExtent.
height() ) / theHeight;
317 int col = ( int ) floor(( thePoint.
x() - myExtent.
xMinimum() ) / xres );
318 int row = ( int ) floor(( myExtent.
yMaximum() - thePoint.
y() ) / yres );
320 double xMin = myExtent.
xMinimum() + col * xres;
321 double xMax = xMin + xres;
322 double yMax = myExtent.
yMaximum() - row * yres;
323 double yMin = yMax - yres;
332 double value = myBlock->
value( 0 );
334 results.insert( i, value );
339 results.insert( i, QVariant() );
354 if ( pPyramidResamplingMethods )
356 QList<QPair<QString, QString> > *methods = pPyramidResamplingMethods();
359 QgsDebugMsg(
"provider pyramidResamplingMethods returned no methods" );
368 QgsDebugMsg(
"Could not resolve pyramidResamplingMethods provider library" );
370 return QList<QPair<QString, QString> >();
377 if ( myPyramidList.isEmpty() )
380 QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
381 for ( myRasterPyramidIterator = myPyramidList.begin();
382 myRasterPyramidIterator != myPyramidList.end();
383 ++myRasterPyramidIterator )
385 if ( myRasterPyramidIterator->exists )
402 QgsDebugMsg( QString(
"set %1 band %1 no data ranges" ).arg( noData.size() ) );
433 const QString& format,
int nBands,
435 int width,
int height,
double* geoTransform,
437 QStringList createOptions )
442 QgsDebugMsg(
"Cannot resolve 'create' function in " + providerKey +
" provider" );
447 return createFn( uri, format, nBands, type, width, height, geoTransform, crs, createOptions );
472 return tr(
"Value" );
478 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.
A rectangle specified with double values.
bool isEmpty() const
test if rectangle is empty.
void copyBaseSettings(const QgsRasterDataProvider &other)
Copy member variables from other raster data provider.
virtual QgsRasterBlock * block(int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight)
Read block of data using given extent and size.
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.
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
double yMaximum() const
Get the y maximum value (top side of rectangle)
void applyNoDataValues(const QgsRasterRangeList &rangeList)
virtual double bandOffset(int bandNo) const
Read band offset for raster value @note added in 2.3.
virtual void setUseSrcNoDataValue(int bandNo, bool use)
Set source nodata value usage.
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
static QString makeTableCell(const QString &value)
Capability
If you add to this, please also add to capabilitiesString()
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
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, QStringList createOptions=QStringList())
Creates a new dataset with mDataSourceURI.
Abstract base class for spatial data provider implementations.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
virtual int ySize() const
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
bool setIsNoData(int row, int column)
Set no data on pixel.
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
Raster identify results container.
virtual QgsRasterIdentifyResult identify(const QgsPoint &thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent=QgsRectangle(), int theWidth=0, int theHeight=0)
Identify raster value(s) found on the point position.
bool setIsNoDataExcept(const QRect &theExceptRect)
Set the whole block to no data except specified rectangle.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
virtual void setUserNoDataValue(int bandNo, QgsRasterRangeList noData)
double xMaximum() const
Get the x maximum value (right side of rectangle)
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
double value(int row, int column) const
Read a single value if type of block is numeric.
virtual QgsRectangle extent()=0
Get the extent of the data source.
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.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point geometry.
QgsRasterDataProvider * createFunction_t(const QString &, const QString &, int, QGis::DataType, int, int, double *, const QgsCoordinateReferenceSystem &, QStringList)
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...
bool userNoDataValuesContains(int bandNo, double value) const
Returns true if user no data contains value.
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
virtual double bandScale(int bandNo) const
Read band scale for raster value @note added in 2.3.
QList< QPair< QString, QString > > * pyramidResamplingMethods_t()
char * bits(int row, int column)
Get pointer to data.
QList< QgsRasterRange > QgsRasterRangeList
virtual int xSize() const
Get raster size.
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...
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
static QString makeTableCells(const QStringList &values)
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
int dataTypeSize(int bandNo)
void * function(const QString &providerKey, const QString &functionName)
Get pointer to provider function.
static QStringList cStringList2Q_(char **stringList)
static QgsRaster::IdentifyFormat identifyFormatFromName(QString formatName)
void(*)() cast_to_fptr(void *p)
static QList< QPair< QString, QString > > pyramidResamplingMethods(QString providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
virtual bool srcHasNoDataValue(int bandNo) const
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
static QRect subRect(const QgsRectangle &theExtent, int theWidth, int theHeight, const QgsRectangle &theSubExtent)
For theExtent and theWidht, theHeight find rectangle covered by subextent.
double width() const
Width of the rectangle.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double xMinimum() const
Get the x minimum value (left side of rectangle)
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
void setXMinimum(double x)
Set the minimum x value.
double height() const
Height of the rectangle.
bool isEmpty() const
Returns true if block is empty, i.e.
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.