Skip to content

Commit

Permalink
QgsRasterBlock::Range to QgsRasterRange
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 10, 2013
1 parent a7e1d40 commit 094a5d8
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 89 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
%Include raster/qgsrasterpipe.sip
%Include raster/qgsrasterprojector.sip
%Include raster/qgsrasterpyramid.sip
%Include raster/qgsrasterrange.sip
%Include raster/qgsrasterrenderer.sip
%Include raster/qgsrasterresamplefilter.sip
%Include raster/qgsrasterresampler.sip
Expand Down
10 changes: 0 additions & 10 deletions python/core/raster/qgsrasterblock.sip
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ class QgsRasterBlock
%End

public:
struct Range
{
double min;
double max;
bool operator==( const QgsRasterBlock::Range &o ) const;
};

QgsRasterBlock();

QgsRasterBlock( QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue );
Expand Down Expand Up @@ -65,8 +58,5 @@ class QgsRasterBlock
bool convert( QGis::DataType destDataType );
QImage image() const;
bool setImage( const QImage * image );

static bool valueInRange( double value, const QList<QgsRasterBlock::Range> &rangeList );

};

4 changes: 2 additions & 2 deletions python/core/raster/qgsrasterdataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** Value representing no data value. */
virtual double srcNoDataValue( int bandNo ) const;

virtual void setUserNoDataValue( int bandNo, QList<QgsRasterBlock::Range> noData );
virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );

/** Get list of user no data value ranges */
virtual QList<QgsRasterBlock::Range> userNoDataValue( int bandNo ) const;
virtual QgsRasterRangeList userNoDataValue( int bandNo ) const;

virtual double minimumValue( int bandNo ) const;
virtual double maximumValue( int bandNo ) const;
Expand Down
3 changes: 0 additions & 3 deletions python/core/raster/qgsrasteridentifyresult.sip
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ class QgsRasterIdentifyResult
QgsError error() const;

void setError( const QgsError & theError );

void appendError( const QgsErrorMessage & theMessage );

};

25 changes: 25 additions & 0 deletions python/core/raster/qgsrasterrange.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
typedef QList<QgsRasterRange> QgsRasterRangeList;

class QgsRasterRange
{
%TypeHeaderCode
#include <qgsrasterrange.h>
%End

public:
QgsRasterRange();

QgsRasterRange( double theMin, double theMax );

~QgsRasterRange();

double min() const;
double max() const;

double setMin( double theMin );
double setMax( double theMax );

bool operator==( const QgsRasterRange &o ) const;

bool contains( double value, const QgsRasterRangeList &rangeList );
};
13 changes: 5 additions & 8 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h"
#include "qgsrasterpyramid.h"
#include "qgsrasterrange.h"
#include "qgsrasterrenderer.h"
#include "qgsrasterrendererregistry.h"
#include "qgsrastertransparency.h"
Expand Down Expand Up @@ -624,11 +625,11 @@ void QgsRasterLayerProperties::sync()
mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
lblSrcNoDataValue->setEnabled( enableSrcNoData );

QList<QgsRasterBlock::Range> noDataRangeList = mRasterLayer->dataProvider()->userNoDataValue( 1 );
QgsRasterRangeList noDataRangeList = mRasterLayer->dataProvider()->userNoDataValue( 1 );
QgsDebugMsg( QString( "noDataRangeList.size = %1" ).arg( noDataRangeList.size() ) );
if ( noDataRangeList.size() > 0 )
{
leNoDataValue->insert( QgsRasterBlock::printValue( noDataRangeList.value( 0 ).min ) );
leNoDataValue->insert( QgsRasterBlock::printValue( noDataRangeList.value( 0 ).min() ) );
}
else
{
Expand Down Expand Up @@ -736,18 +737,14 @@ void QgsRasterLayerProperties::apply()
*/

//set NoDataValue
QList<QgsRasterBlock::Range> myNoDataRangeList;
QgsRasterRangeList myNoDataRangeList;
if ( "" != leNoDataValue->text() )
{
bool myDoubleOk = false;
double myNoDataValue = leNoDataValue->text().toDouble( &myDoubleOk );
if ( myDoubleOk )
{
//mRasterLayer->setNoDataValue( myNoDataValue );
QgsRasterBlock::Range myNoDataRange;
myNoDataRange.min = myNoDataValue;
myNoDataRange.max = myNoDataValue;

QgsRasterRange myNoDataRange( myNoDataValue, myNoDataValue );
myNoDataRangeList << myNoDataRange;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ SET(QGIS_CORE_SRCS
raster/qgsrasternuller.cpp
raster/qgsrastertransparency.cpp
raster/qgsrasterpipe.cpp
raster/qgsrasterrange.cpp
raster/qgsrastershader.cpp
raster/qgsrastershaderfunction.cpp

Expand Down Expand Up @@ -477,6 +478,7 @@ SET(QGIS_CORE_HDRS
raster/qgsrastertransparency.h
raster/qgsrasterpipe.h
raster/qgsrasterprojector.h
raster/qgsrasterrange.h
raster/qgsrastershader.h
raster/qgsrastershaderfunction.h
raster/qgsrasterviewport.h
Expand Down
16 changes: 8 additions & 8 deletions src/core/raster/qgsrasterblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "cpl_conv.h"

QgsRasterBlock::QgsRasterBlock()
//mValid (false)
: mDataType( QGis::UnknownDataType )
: mValid( true )
, mDataType( QGis::UnknownDataType )
, mTypeSize( 0 )
, mWidth( 0 )
, mHeight( 0 )
Expand All @@ -39,8 +39,8 @@ QgsRasterBlock::QgsRasterBlock()
}

QgsRasterBlock::QgsRasterBlock( QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue )
//mValid(true)
: mDataType( theDataType )
: mValid( true )
, mDataType( theDataType )
, mTypeSize( 0 )
, mWidth( theWidth )
, mHeight( theHeight )
Expand Down Expand Up @@ -70,7 +70,7 @@ bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHei
mWidth = 0;
mHeight = 0;
mNoDataValue = std::numeric_limits<double>::quiet_NaN();
//mValid = false;
mValid = false;

if ( typeIsNumeric( theDataType ) )
{
Expand All @@ -96,7 +96,7 @@ bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHei
return false;
}

//mValid = true;
mValid = true;
mDataType = theDataType;
mTypeSize = QgsRasterBlock::typeSize( mDataType );
mWidth = theWidth;
Expand Down Expand Up @@ -410,7 +410,7 @@ bool QgsRasterBlock::convert( QGis::DataType destDataType )
return true;
}

void QgsRasterBlock::applyNodataValues( const QList<Range>& rangeList )
void QgsRasterBlock::applyNodataValues( const QgsRasterRangeList & rangeList )
{
if ( rangeList.isEmpty() )
{
Expand All @@ -421,7 +421,7 @@ void QgsRasterBlock::applyNodataValues( const QList<Range>& rangeList )
for ( size_t i = 0; i < size; ++i )
{
double val = value( i );
if ( valueInRange( val, rangeList ) )
if ( QgsRasterRange::contains( val, rangeList ) )
{
setValue( i, mNoDataValue );
}
Expand Down
62 changes: 26 additions & 36 deletions src/core/raster/qgsrasterblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,17 @@
#include <limits>
#include <QImage>
#include "qgis.h"
#include "qgserror.h"
#include "qgslogger.h"
#include "qgsrasterrange.h"
#include "qgsrectangle.h"

/** \ingroup core
* Raster data container.
*/
// TODO: inherit from QObject?
class CORE_EXPORT QgsRasterBlock
{
public:
struct Range
{
double min;
double max;
inline bool operator==( const Range &o ) const
{
return min == o.min && max == o.max;
}
};

QgsRasterBlock();

/** \brief Constructor which allocates data block in memory
Expand All @@ -64,7 +55,19 @@ class CORE_EXPORT QgsRasterBlock

// TODO: consider if use isValid() at all, isEmpty() should be sufficient
// and works also if block is valid but empty - difference between valid and empty?
//bool isValid() const { return mValid; }
/** \brief 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.
*/
bool isValid() const { return mValid; }

/** \brief Mark block as valid or invalid */
void setValid( bool valid ) { mValid = valid; }

/** Returns true if block is empty, i.e. its size is 0 (zero rows or cols).
* This method does not return true if size is not zero and all values are
* 'no data' (null).
*/
bool isEmpty() const;

// Return data type size in bytes
Expand Down Expand Up @@ -247,14 +250,6 @@ class CORE_EXPORT QgsRasterBlock
QImage image() const;
bool setImage( const QImage * image );

/** \brief Test if value is within the list of ranges
* @param value value
* @param rangeList list of ranges
* @return true if value is in at least one of ranges
* @note not available in python bindings
*/
inline static bool valueInRange( double value, const QList<QgsRasterBlock::Range> &rangeList );

/** Create a new image with extraneous data, such data may be used
* after the image is destroyed. The memory is not initialized.
*/
Expand All @@ -279,15 +274,21 @@ class CORE_EXPORT QgsRasterBlock

inline static void writeValue( void *data, QGis::DataType type, size_t index, double value );

void applyNodataValues( const QList<Range>& rangeList );
void applyNodataValues( const QgsRasterRangeList & rangeList );

/** \brief Get error */
QgsError error() const { return mError; }

/** \brief Set error */
void setError( const QgsError & theError ) { mError = theError;}

private:

static QImage::Format imageFormat( QGis::DataType theDataType );
static QGis::DataType dataType( QImage::Format theFormat );

// Valid
//bool isValid;
bool mValid;

// Data type
QGis::DataType mDataType;
Expand All @@ -310,6 +311,9 @@ class CORE_EXPORT QgsRasterBlock

// Image for image data types, not used with numerical data types
QImage *mImage;

// Error
QgsError mError;
};

inline double QgsRasterBlock::readValue( void *data, QGis::DataType type, size_t index )
Expand Down Expand Up @@ -393,20 +397,6 @@ inline void QgsRasterBlock::writeValue( void *data, QGis::DataType type, size_t
}
}

inline bool QgsRasterBlock::valueInRange( double value, const QList<QgsRasterBlock::Range> &rangeList )
{
foreach ( QgsRasterBlock::Range range, rangeList )
{
if (( value >= range.min && value <= range.max ) ||
doubleNear( value, range.min ) ||
doubleNear( value, range.max ) )
{
return true;
}
}
return false;
}

inline double QgsRasterBlock::value( size_t index ) const
{
/*if ( index >= ( size_t )mWidth*mHeight )
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterdataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ double QgsRasterDataProvider::readValue( void *data, int type, int index )
}
#endif

void QgsRasterDataProvider::setUserNoDataValue( int bandNo, QList<QgsRasterBlock::Range> noData )
void QgsRasterDataProvider::setUserNoDataValue( int bandNo, QgsRasterRangeList noData )
{
//if ( bandNo > bandCount() ) return;
if ( bandNo >= mUserNoDataValue.size() )
{
for ( int i = mUserNoDataValue.size(); i < bandNo; i++ )
{
mUserNoDataValue.append( QList<QgsRasterBlock::Range>() );
mUserNoDataValue.append( QgsRasterRangeList() );
}
}
QgsDebugMsg( QString( "set %1 band %1 no data ranges" ).arg( noData.size() ) );
Expand Down
7 changes: 4 additions & 3 deletions src/core/raster/qgsrasterdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsrasterbandstats.h"
#include "qgsrasterhistogram.h"
#include "qgsrasterrange.h"

#include "cpl_conv.h"
#include <cmath>
Expand Down Expand Up @@ -276,10 +277,10 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
/** Value representing no data value. */
virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }

virtual void setUserNoDataValue( int bandNo, QList<QgsRasterBlock::Range> noData );
virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );

/** Get list of user no data value ranges */
virtual QList<QgsRasterBlock::Range> userNoDataValue( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
virtual QgsRasterRangeList userNoDataValue( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }

virtual double minimumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
virtual double maximumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
Expand Down Expand Up @@ -514,7 +515,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast

/** \brief List of lists of user defined additional no data values
* for each band, indexed from 0 */
QList< QList<QgsRasterBlock::Range> > mUserNoDataValue;
QList< QgsRasterRangeList > mUserNoDataValue;

QgsRectangle mExtent;

Expand Down
7 changes: 2 additions & 5 deletions src/core/raster/qgsrasteridentifyresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class CORE_EXPORT QgsRasterIdentifyResult
/** \brief Get results. Results are different for each format:
* IdentifyFormatValue: map of values for each band, keys are band numbers (from 1).
* IdentifyFormatFeature: map of QgsRasterFeatureList for each sublayer (WMS)
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
*/
QMap<int, QVariant> results() const { return mResults; }
QMap<int, QVariant> results() const { return mResults; }

/** Set map of optional parameters */
void setParams( const QMap<QString, QVariant> & theParams ) { mParams = theParams; }
Expand All @@ -67,9 +67,6 @@ class CORE_EXPORT QgsRasterIdentifyResult
/** \brief Set error */
void setError( const QgsError & theError ) { mError = theError;}

/** \brief Add error message */
void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}

private:
/** \brief Is valid */
bool mValid;
Expand Down
Loading

0 comments on commit 094a5d8

Please sign in to comment.