QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
QgsRasterBlock Class Reference

Raster data container. More...

#include <qgsrasterblock.h>

Collaboration diagram for QgsRasterBlock:
Collaboration graph
[legend]

Public Member Functions

 QgsRasterBlock ()
 QgsRasterBlock (QGis::DataType theDataType, int theWidth, int theHeight)
 Constructor which allocates data block in memory.
 QgsRasterBlock (QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue)
 Constructor which allocates data block in memory.
virtual ~QgsRasterBlock ()
bool reset (QGis::DataType theDataType, int theWidth, int theHeight)
 Reset block.
bool reset (QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue)
 Reset block.
bool isValid () const
 Returns true if the block is valid (correctly filled with data).
void setValid (bool valid)
 Mark block as valid or invalid.
bool isEmpty () const
 Returns true if block is empty, i.e.
int dataTypeSize () const
QGis::DataType dataType () const
 Returns data type.
bool hasNoDataValue () const
 True if the block has no data value.
bool hasNoData () const
 Returns true if the block may contain no data.
double noDataValue () const
 Return no data value.
double value (int row, int column) const
 Read a single value if type of block is numeric.
double value (qgssize index) const
 Read a single value if type of block is numeric.
QRgb color (int row, int column) const
 Read a single color.
QRgb color (qgssize index) const
 Read a single value.
bool isNoData (int row, int column)
 Check if value at position is no data.
bool isNoData (qgssize index)
 Check if value at position is no data.
bool setValue (int row, int column, double value)
 Set value on position.
bool setValue (qgssize index, double value)
 Set value on index (indexed line by line)
bool setColor (int row, int column, QRgb color)
 Set color on position.
bool setColor (qgssize index, QRgb color)
 Set color on index (indexed line by line)
bool setIsNoData (int row, int column)
 Set no data on pixel.
bool setIsNoData (qgssize index)
 Set no data on pixel.
bool setIsNoData ()
 Set the whole block to no data.
bool setIsNoDataExcept (const QRect &theExceptRect)
 Set the whole block to no data except specified rectangle.
char * bits (int row, int column)
 Get pointer to data.
char * bits (qgssize index)
 Get pointer to data.
char * bits ()
 Get pointer to data.
bool convert (QGis::DataType destDataType)
 Convert data to different type.
QImage image () const
 Get image if type is color.
bool setImage (const QImage *image)
 set image.
void applyNoDataValues (const QgsRasterRangeList &rangeList)
QgsError error () const
 Get error.
void setError (const QgsError &theError)
 Set error.

Static Public Member Functions

static int typeSize (int dataType)
static bool typeIsNumeric (QGis::DataType type)
 Returns true if data type is numeric.
static bool typeIsColor (QGis::DataType type)
 Returns true if data type is color.
static QGis::DataType typeWithNoDataValue (QGis::DataType dataType, double *noDataValue)
 For given data type returns wider type and sets no data value.
static QByteArray valueBytes (QGis::DataType theDataType, double theValue)
 Get byte array representing a value.
static QString printValue (double value)
 Print double value with all necessary significant digits.
static double readValue (void *data, QGis::DataType type, qgssize index)
static void writeValue (void *data, QGis::DataType type, qgssize index, double value)
static QRect subRect (const QgsRectangle &theExtent, int theWidth, int theHeight, const QgsRectangle &theSubExtent)
 For theExtent and theWidht, theHeight find rectangle covered by subextent.

Private Member Functions

bool isNoDataValue (double value) const
 Test if value is nodata for specific band.
bool createNoDataBitmap ()
 Allocate no data bitmap.

Static Private Member Functions

static QImage::Format imageFormat (QGis::DataType theDataType)
static QGis::DataType dataType (QImage::Format theFormat)
static bool isNoDataValue (double value, double noDataValue)
 Test if value is nodata comparing to noDataValue.
static void * convert (void *srcData, QGis::DataType srcDataType, QGis::DataType destDataType, qgssize size)
 Convert block of data from one type to another.

Private Attributes

bool mValid
QGis::DataType mDataType
int mTypeSize
int mWidth
int mHeight
bool mHasNoDataValue
double mNoDataValue
void * mData
QImage * mImage
char * mNoDataBitmap
int mNoDataBitmapWidth
qgssize mNoDataBitmapSize
QgsError mError

Static Private Attributes

static const QRgb mNoDataColor = qRgba( 0, 0, 0, 0 )

Detailed Description

Raster data container.

Definition at line 32 of file qgsrasterblock.h.

Constructor & Destructor Documentation

QgsRasterBlock::QgsRasterBlock ( )

Definition at line 29 of file qgsrasterblock.cpp.

QgsRasterBlock::QgsRasterBlock ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight 
)

Constructor which allocates data block in memory.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
Note
not available in python bindings (use variant with theNoDataValue)

Definition at line 45 of file qgsrasterblock.cpp.

References mDataType, mHeight, mWidth, and reset().

QgsRasterBlock::QgsRasterBlock ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight,
double  theNoDataValue 
)

Constructor which allocates data block in memory.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
theNoDataValuethe value representing no data (NULL)

Definition at line 62 of file qgsrasterblock.cpp.

References mDataType, mHeight, mNoDataValue, mWidth, and reset().

QgsRasterBlock::~QgsRasterBlock ( )
virtual

Definition at line 79 of file qgsrasterblock.cpp.

References mData, mImage, mNoDataBitmap, QgsDebugMsg, and qgsFree().

Member Function Documentation

void QgsRasterBlock::applyNoDataValues ( const QgsRasterRangeList rangeList)
char * QgsRasterBlock::bits ( int  row,
int  column 
)

Get pointer to data.

Parameters
rowrow index
columncolumn index
Returns
pointer to data
Note
not available in python bindings

Definition at line 655 of file qgsrasterblock.cpp.

References bits(), and mWidth.

Referenced by QgsPalettedRasterRenderer::block(), QgsRasterProjector::block(), and QgsRasterDataProvider::block().

char * QgsRasterBlock::bits ( qgssize  index)

Get pointer to data.

Parameters
indexdata matrix index (long type in Python)
Returns
pointer to data
Note
not available in python bindings

Definition at line 635 of file qgsrasterblock.cpp.

References mData, mHeight, mImage, mTypeSize, mWidth, and QgsDebugMsg.

char * QgsRasterBlock::bits ( )

Get pointer to data.

Returns
pointer to data
Note
not available in python bindings

Definition at line 660 of file qgsrasterblock.cpp.

References mData, and mImage.

Referenced by bits(), and setColor().

QRgb QgsRasterBlock::color ( int  row,
int  column 
) const

Read a single color.

Parameters
rowrow index
columncolumn index
Returns
color

Definition at line 303 of file qgsrasterblock.cpp.

References mImage, and mNoDataColor.

Referenced by QgsSingleBandColorDataRenderer::block(), QgsBrightnessContrastFilter::block(), QgsHueSaturationFilter::block(), color(), setColor(), and QgsRasterFileWriter::writeImageRaster().

QRgb QgsRasterBlock::color ( qgssize  index) const

Read a single value.

Parameters
indexdata matrix index (long type in Python)
Returns
color

Definition at line 296 of file qgsrasterblock.cpp.

References color(), and mWidth.

bool QgsRasterBlock::convert ( QGis::DataType  destDataType)

Convert data to different type.

Parameters
destDataTypedest data type
Returns
true on success

Definition at line 674 of file qgsrasterblock.cpp.

References image(), imageFormat(), isEmpty(), mData, mDataType, mHeight, mImage, mTypeSize, mWidth, QgsDebugMsg, qgsFree(), typeIsColor(), typeIsNumeric(), and typeSize().

Referenced by QgsSingleBandColorDataRenderer::block().

void * QgsRasterBlock::convert ( void *  srcData,
QGis::DataType  srcDataType,
QGis::DataType  destDataType,
qgssize  size 
)
staticprivate

Convert block of data from one type to another.

Original block memory is not release.

Parameters
srcDatasource data
srcDataTypesource data type
destDataTypedest data type
sizeblock size (width * height)
Returns
block of data in destDataType

Definition at line 791 of file qgsrasterblock.cpp.

References qgsMalloc(), readValue(), size, typeSize(), value(), and writeValue().

bool QgsRasterBlock::createNoDataBitmap ( )
private

Allocate no data bitmap.

Returns
true on success

Definition at line 854 of file qgsrasterblock.cpp.

References mHeight, mNoDataBitmap, mNoDataBitmapSize, mNoDataBitmapWidth, mWidth, QgsDebugMsg, and qgsMalloc().

Referenced by setIsNoData(), and setIsNoDataExcept().

QGis::DataType QgsRasterBlock::dataType ( ) const
inline

Returns data type.

Definition at line 139 of file qgsrasterblock.h.

Referenced by QgsRasterNuller::block(), QgsRasterProjector::block(), and setImage().

QGis::DataType QgsRasterBlock::dataType ( QImage::Format  theFormat)
staticprivate
int QgsRasterBlock::dataTypeSize ( ) const
inline

Definition at line 127 of file qgsrasterblock.h.

Referenced by setIsNoData(), and setIsNoDataExcept().

QgsError QgsRasterBlock::error ( ) const
inline

Get error.

Definition at line 295 of file qgsrasterblock.h.

bool QgsRasterBlock::hasNoData ( ) const

Returns true if the block may contain no data.

It does not guarantee that it really contains any no data. It can be used to speed up processing. Not the difference between this method and hasNoDataValue().

Returns
true if the block may contain no data

Definition at line 273 of file qgsrasterblock.cpp.

References mHasNoDataValue, and mNoDataBitmap.

Referenced by QgsRasterProjector::block().

bool QgsRasterBlock::hasNoDataValue ( ) const
inline

True if the block has no data value.

Returns
true if the block has no data value

Definition at line 146 of file qgsrasterblock.h.

Referenced by QgsRasterNuller::block(), and QgsRasterProjector::block().

QImage QgsRasterBlock::image ( ) const

Get image if type is color.

Returns
image

Definition at line 728 of file qgsrasterblock.cpp.

References mImage.

Referenced by QgsRasterResampleFilter::block(), convert(), and QgsRasterDrawer::draw().

QImage::Format QgsRasterBlock::imageFormat ( QGis::DataType  theDataType)
staticprivate

Definition at line 152 of file qgsrasterblock.cpp.

References QGis::ARGB32, and QGis::ARGB32_Premultiplied.

Referenced by convert(), and reset().

bool QgsRasterBlock::isEmpty ( ) const
bool QgsRasterBlock::isNoData ( int  row,
int  column 
)

Check if value at position is no data.

Parameters
rowrow index
columncolumn index
Returns
true if value is no data

Definition at line 340 of file qgsrasterblock.cpp.

References mWidth.

Referenced by QgsRasterInterface::bandStatistics(), QgsSingleBandPseudoColorRenderer::block(), QgsMultiBandColorRenderer::block(), QgsPalettedRasterRenderer::block(), QgsSingleBandGrayRenderer::block(), QgsRasterNuller::block(), QgsRasterProjector::block(), and QgsRasterInterface::histogram().

bool QgsRasterBlock::isNoData ( qgssize  index)

Check if value at position is no data.

Parameters
indexdata matrix index (long type in Python)
Returns
true if value is no data

Definition at line 310 of file qgsrasterblock.cpp.

References isNoDataValue(), mData, mDataType, mHasNoDataValue, mHeight, mNoDataBitmap, mNoDataBitmapWidth, mWidth, QgsDebugMsg, readValue(), and value().

bool QgsRasterBlock::isNoDataValue ( double  value,
double  noDataValue 
)
staticprivate

Test if value is nodata comparing to noDataValue.

Parameters
valuetested value
noDataValueno data value
Returns
true if value is nodata

Definition at line 278 of file qgsrasterblock.cpp.

References qgsDoubleNear().

Referenced by isNoData().

bool QgsRasterBlock::isNoDataValue ( double  value) const
inlineprivate

Test if value is nodata for specific band.

Parameters
valuetested value
Returns
true if value is nodata

Definition at line 465 of file qgsrasterblock.h.

References mNoDataValue, and qgsDoubleNear().

bool QgsRasterBlock::isValid ( ) const
inline

Returns true if the block is valid (correctly filled with data).

An empty block may still be valid (if zero size block was requested). If the block is not valid, error may be retrieved by error() method.

Definition at line 79 of file qgsrasterblock.h.

Referenced by QgsRasterChecker::runTest().

double QgsRasterBlock::noDataValue ( ) const
inline

Return no data value.

If the block does not have a no data value the returned value is undefined.

Returns
No data value

Definition at line 157 of file qgsrasterblock.h.

Referenced by QgsRasterNuller::block(), and QgsRasterProjector::block().

QString QgsRasterBlock::printValue ( double  value)
static

Print double value with all necessary significant digits.

   It is ensured that conversion back to double gives the same number.
Parameters
valuethe value to be printed
Returns
string representing the value

Definition at line 752 of file qgsrasterblock.cpp.

References QgsDebugMsg, and value().

Referenced by QgsRasterLayerSaveAsDialog::addNoDataRow(), QgsMapToolIdentify::identifyRasterLayer(), QgsRasterLayerSaveAsDialog::setOutputExtent(), and QgsRasterTransparency::writeXML().

double QgsRasterBlock::readValue ( void *  data,
QGis::DataType  type,
qgssize  index 
)
inlinestatic
bool QgsRasterBlock::reset ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight 
)

Reset block.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
Returns
true on success
Note
not available in python bindings (use variant with theNoDataValue)

Definition at line 87 of file qgsrasterblock.cpp.

References mHasNoDataValue, and QgsDebugMsg.

Referenced by QgsSingleBandColorDataRenderer::block(), QgsSingleBandPseudoColorRenderer::block(), QgsMultiBandColorRenderer::block(), QgsPalettedRasterRenderer::block(), QgsBrightnessContrastFilter::block(), QgsSingleBandGrayRenderer::block(), QgsRasterResampleFilter::block(), QgsHueSaturationFilter::block(), and QgsRasterBlock().

bool QgsRasterBlock::reset ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight,
double  theNoDataValue 
)

Reset block.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
theNoDataValuethe value representing no data (NULL)
Returns
true on success

Definition at line 99 of file qgsrasterblock.cpp.

References imageFormat(), mData, mDataType, mHasNoDataValue, mHeight, mImage, mNoDataBitmap, mNoDataValue, mTypeSize, mValid, mWidth, QgsDebugMsg, qgsFree(), qgsMalloc(), typeIsColor(), typeIsNumeric(), typeSize(), and QGis::UnknownDataType.

bool QgsRasterBlock::setColor ( int  row,
int  column,
QRgb  color 
)

Set color on position.

Parameters
rowrow index
columncolumn index
colorthe color to be set, QRgb value
Returns
true on success

Definition at line 366 of file qgsrasterblock.cpp.

References mWidth.

Referenced by QgsSingleBandColorDataRenderer::block(), QgsSingleBandPseudoColorRenderer::block(), QgsMultiBandColorRenderer::block(), QgsBrightnessContrastFilter::block(), QgsSingleBandGrayRenderer::block(), and QgsHueSaturationFilter::block().

bool QgsRasterBlock::setColor ( qgssize  index,
QRgb  color 
)

Set color on index (indexed line by line)

Parameters
indexdata matrix index (long type in Python)
colorthe color to be set, QRgb value
Returns
true on success

Definition at line 371 of file qgsrasterblock.cpp.

References bits(), color(), index, mImage, and QgsDebugMsg.

void QgsRasterBlock::setError ( const QgsError theError)
inline

Set error.

Definition at line 298 of file qgsrasterblock.h.

bool QgsRasterBlock::setImage ( const QImage *  image)

set image.

Parameters
imageimage
Returns
true on success

Definition at line 737 of file qgsrasterblock.cpp.

References dataType(), mData, mDataType, mHeight, mImage, mNoDataValue, mTypeSize, mWidth, qgsFree(), and typeSize().

Referenced by QgsRasterResampleFilter::block().

bool QgsRasterBlock::setIsNoData ( int  row,
int  column 
)

Set no data on pixel.

Parameters
rowrow index
columncolumn index
Returns
true on success

Definition at line 391 of file qgsrasterblock.cpp.

References mWidth, and setIsNoData().

Referenced by QgsRasterNuller::block(), QgsRasterProjector::block(), and QgsRasterDataProvider::block().

bool QgsRasterBlock::setIsNoData ( qgssize  index)

Set no data on pixel.

Parameters
indexdata matrix index (long type in Python)
Returns
true on success

Definition at line 396 of file qgsrasterblock.cpp.

References createNoDataBitmap(), mHasNoDataValue, mNoDataBitmap, mNoDataBitmapWidth, mNoDataValue, mWidth, and setValue().

bool QgsRasterBlock::setIsNoData ( )
bool QgsRasterBlock::setIsNoDataExcept ( const QRect &  theExceptRect)

Set the whole block to no data except specified rectangle.

Returns
true on success

Definition at line 475 of file qgsrasterblock.cpp.

References createNoDataBitmap(), dataTypeSize(), mData, mDataType, mHasNoDataValue, mHeight, mImage, mNoDataBitmap, mNoDataBitmapWidth, mNoDataColor, mNoDataValue, mWidth, QgsDebugMsg, typeIsNumeric(), typeSize(), and valueBytes().

Referenced by QgsRasterDataProvider::block().

void QgsRasterBlock::setValid ( bool  valid)
inline

Mark block as valid or invalid.

Definition at line 82 of file qgsrasterblock.h.

bool QgsRasterBlock::setValue ( int  row,
int  column,
double  value 
)

Set value on position.

Parameters
rowrow index
columncolumn index
valuethe value to be set
Returns
true on success

Definition at line 361 of file qgsrasterblock.cpp.

References mWidth.

Referenced by QgsRasterNuller::block(), setIsNoData(), and QgsRasterFileWriter::writeImageRaster().

bool QgsRasterBlock::setValue ( qgssize  index,
double  value 
)

Set value on index (indexed line by line)

Parameters
indexdata matrix index (long type in Python)
valuethe value to be set
Returns
true on success

Definition at line 345 of file qgsrasterblock.cpp.

References mData, mDataType, mHeight, mWidth, QgsDebugMsg, and writeValue().

QRect QgsRasterBlock::subRect ( const QgsRectangle theExtent,
int  theWidth,
int  theHeight,
const QgsRectangle theSubExtent 
)
static

For theExtent and theWidht, theHeight find rectangle covered by subextent.

The output rect has x oriented from left to right and y from top to bottom (upper-left to lower-right orientation).

Parameters
theExtentextent, usually the larger
theWidthnumbers of columns in theExtent
theHeightnumbers of rows in theExtent
theSubExtentextent, usually smaller than theExtent
Returns
the rectangle covered by sub extent

Definition at line 869 of file qgsrasterblock.cpp.

References QgsRectangle::height(), QgsDebugMsg, QgsRectangle::toString(), QgsRectangle::width(), QgsRectangle::xMaximum(), QgsRectangle::xMinimum(), QgsRectangle::yMaximum(), and QgsRectangle::yMinimum().

Referenced by QgsRasterDataProvider::block().

bool QgsRasterBlock::typeIsColor ( QGis::DataType  type)
static
bool QgsRasterBlock::typeIsNumeric ( QGis::DataType  type)
static
static int QgsRasterBlock::typeSize ( int  dataType)
inlinestatic
QGis::DataType QgsRasterBlock::typeWithNoDataValue ( QGis::DataType  dataType,
double *  noDataValue 
)
static

For given data type returns wider type and sets no data value.

Definition at line 240 of file qgsrasterblock.cpp.

References QGis::Byte, QGis::Float32, QGis::Float64, QGis::Int16, QGis::Int32, MathUtils::max(), QgsDebugMsg, QGis::UInt16, QGis::UInt32, and QGis::UnknownDataType.

Referenced by QgsRasterFileWriter::writeDataRaster().

double QgsRasterBlock::value ( int  row,
int  column 
) const
double QgsRasterBlock::value ( qgssize  index) const
inline

Read a single value if type of block is numeric.

If type is color, returned value is undefined.

Parameters
indexdata matrix index (long type in Python)
Returns
value

Definition at line 455 of file qgsrasterblock.h.

References mData, mDataType, QgsDebugMsg, and readValue().

QByteArray QgsRasterBlock::valueBytes ( QGis::DataType  theDataType,
double  theValue 
)
static

Get byte array representing a value.

Parameters
theDataTypedata type
theValuevalue
Returns
byte array representing the value

Definition at line 805 of file qgsrasterblock.cpp.

References QGis::Byte, QGis::Float32, QGis::Float64, QGis::Int16, QGis::Int32, QgsDebugMsg, size, typeSize(), QGis::UInt16, and QGis::UInt32.

Referenced by setIsNoData(), and setIsNoDataExcept().

void QgsRasterBlock::writeValue ( void *  data,
QGis::DataType  type,
qgssize  index,
double  value 
)
inlinestatic

Member Data Documentation

void* QgsRasterBlock::mData
private
QGis::DataType QgsRasterBlock::mDataType
private
QgsError QgsRasterBlock::mError
private

Definition at line 381 of file qgsrasterblock.h.

bool QgsRasterBlock::mHasNoDataValue
private

Definition at line 355 of file qgsrasterblock.h.

Referenced by hasNoData(), isNoData(), reset(), setIsNoData(), and setIsNoDataExcept().

int QgsRasterBlock::mHeight
private
QImage* QgsRasterBlock::mImage
private
char* QgsRasterBlock::mNoDataBitmap
private
qgssize QgsRasterBlock::mNoDataBitmapSize
private

Definition at line 378 of file qgsrasterblock.h.

Referenced by createNoDataBitmap(), and setIsNoData().

int QgsRasterBlock::mNoDataBitmapWidth
private

Definition at line 375 of file qgsrasterblock.h.

Referenced by createNoDataBitmap(), isNoData(), setIsNoData(), and setIsNoDataExcept().

const QRgb QgsRasterBlock::mNoDataColor = qRgba( 0, 0, 0, 0 )
staticprivate

Definition at line 360 of file qgsrasterblock.h.

Referenced by color(), setIsNoData(), and setIsNoDataExcept().

double QgsRasterBlock::mNoDataValue
private
int QgsRasterBlock::mTypeSize
private

Definition at line 346 of file qgsrasterblock.h.

Referenced by bits(), convert(), reset(), and setImage().

bool QgsRasterBlock::mValid
private

Definition at line 340 of file qgsrasterblock.h.

Referenced by reset().

int QgsRasterBlock::mWidth
private

The documentation for this class was generated from the following files: