Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Sep 20, 2012
2 parents 8fd7805 + 5243423 commit 05ae00d
Show file tree
Hide file tree
Showing 38 changed files with 1,202 additions and 496 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsrasterinterface.sip
Expand Up @@ -82,7 +82,7 @@ class QgsRasterInterface

virtual int bandCount() const;

virtual double noDataValue() const;
virtual double noDataValue( int bandNo ) const;

virtual void * block( int bandNo, const QgsRectangle & extent, int width, int height );

Expand Down
8 changes: 4 additions & 4 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -172,7 +172,7 @@ public:
int height();

/** \brief Is the NoDataValue Valid */
bool isNoDataValueValid() const;
//bool isNoDataValueValid() const;

/** \brief Accessor for mGrayMinimumMaximumEstimated */
//bool isGrayMinimumMaximumEstimated() const; //removed with raster redesign
Expand All @@ -181,7 +181,7 @@ public:
//bool isRGBMinimumMaximumEstimated() const; //removed with raster redesign

/** \brief Accessor that returns the NO_DATA entry for this raster */
double noDataValue( bool* isValid = 0 );
//double noDataValue( bool* isValid = 0 );

/** \brief Returns a pointer to the transparency object */
//QgsRasterTransparency* rasterTransparency(); //removed with raster redesign
Expand Down Expand Up @@ -385,7 +385,7 @@ public:
//bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );

/** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */
void resetNoDataValue();
//void resetNoDataValue();

/** \brief Mutator for blue band name mapping */
void setBlueBandName( const QString & theBandName );
Expand Down Expand Up @@ -431,7 +431,7 @@ public:
void setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );

/** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */
void setNoDataValue( double theNoData );
//void setNoDataValue( double theNoData );

/** \brief Set the raster shader function to a user defined function
\note ownership of the shader function is transfered to raster shader */
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgsrasterformatsaveoptionswidget.sip
Expand Up @@ -29,7 +29,7 @@ class QgsRasterFormatSaveOptionsWidget : QWidget

void apply();
void helpOptions();
bool validateOptions( bool gui = true );
QString validateOptions( bool gui = true, bool reportOk = true );

private slots:

Expand Down
25 changes: 16 additions & 9 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -546,13 +546,20 @@ void QgsRasterLayerProperties::sync()
// TODO: no data ranges
if ( mRasterLayer->dataProvider()->srcHasNoDataValue( 1 ) )
{
lblSrcNoDataValue->setText( QgsRasterInterface::printValue( mRasterLayer->dataProvider()->noDataValue( 1 ) ) );
lblSrcNoDataValue->setText( QgsRasterInterface::printValue( mRasterLayer->dataProvider()->srcNoDataValue( 1 ) ) );
}
else
{
lblSrcNoDataValue->setText( tr( "not defined" ) );
}

mSrcNoDataValueCheckBox->setChecked( mRasterLayer->dataProvider()->useSrcNoDataValue( 1 ) );

bool enableSrcNoData = mRasterLayer->dataProvider()->srcHasNoDataValue( 1 ) && !qIsNaN( mRasterLayer->dataProvider()->srcNoDataValue( 1 ) );

mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
lblSrcNoDataValue->setEnabled( enableSrcNoData );

QList<QgsRasterInterface::Range> noDataRangeList = mRasterLayer->dataProvider()->userNoDataValue( 1 );
QgsDebugMsg( QString( "noDataRangeList.size = %1" ).arg( noDataRangeList.size() ) );
if ( noDataRangeList.size() > 0 )
Expand Down Expand Up @@ -600,13 +607,14 @@ void QgsRasterLayerProperties::sync()
}
else
{
if ( mRasterLayer->isNoDataValueValid() )
// TODO: all bands
if ( mRasterLayer->dataProvider()->srcHasNoDataValue( 1 ) )
{
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->noDataValue() ) );
lblNoData->setText( tr( "No-Data Value: %1" ).arg( mRasterLayer->dataProvider()->noDataValue( 1 ) ) );
}
else
{
lblNoData->setText( tr( "No-Data Value: Not Set" ) );
lblNoData->setText( tr( "No-Data Value: " ) + tr( "n/a" ) );
}
}

Expand Down Expand Up @@ -678,6 +686,7 @@ void QgsRasterLayerProperties::apply()
for ( int bandNo = 1; bandNo <= mRasterLayer->dataProvider()->bandCount(); bandNo++ )
{
mRasterLayer->dataProvider()->setUserNoDataValue( bandNo, myNoDataRangeList );
mRasterLayer->dataProvider()->setUseSrcNoDataValue( bandNo, mSrcNoDataValueCheckBox->isChecked() );
}

//set renderer from widget
Expand Down Expand Up @@ -992,32 +1001,30 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()

setupTransparencyTable( nBands );

// I don't think that noDataValue should be added to transparency list
#if 0
if ( nBands == 3 )
{
if ( mRasterLayer->isNoDataValueValid() )
{
// I don't think that noDataValue should be added to transparency list
#if 0
tableTransparency->insertRow( tableTransparency->rowCount() );
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 2, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, 100 );
#endif
}
}
else //1 band
{
if ( mRasterLayer->isNoDataValueValid() )
{
#if 0
tableTransparency->insertRow( tableTransparency->rowCount() );
setTransparencyCell( 0, 0, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, mRasterLayer->noDataValue() );
setTransparencyCell( 0, 1, 100 );
#endif
}
}
#endif

tableTransparency->resizeColumnsToContents(); // works only with values
tableTransparency->resizeRowsToContents();
Expand Down
24 changes: 12 additions & 12 deletions src/core/qgsgeometry.cpp
Expand Up @@ -4226,10 +4226,10 @@ QString QgsGeometry::exportToGeoJSON()
{
mWkt += "{ \"type\": \"Point\", \"coordinates\": [";
x = ( double * )( mGeometry + 5 );
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
mWkt += ", ";
y = ( double * )( mGeometry + 5 + sizeof( double ) );
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
mWkt += "] }";
return mWkt;
}
Expand All @@ -4256,11 +4256,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
ptr += sizeof( double );
if ( hasZValue )
{
Expand Down Expand Up @@ -4313,11 +4313,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
ptr += sizeof( double );
if ( hasZValue )
{
Expand Down Expand Up @@ -4353,11 +4353,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * )( ptr );
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
mWkt += ", ";
ptr += sizeof( double );
y = ( double * )( ptr );
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
ptr += sizeof( double );
if ( hasZValue )
{
Expand Down Expand Up @@ -4399,11 +4399,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
ptr += sizeof( double );
if ( hasZValue )
{
Expand Down Expand Up @@ -4457,11 +4457,11 @@ QString QgsGeometry::exportToGeoJSON()
}
mWkt += "[";
x = ( double * ) ptr;
mWkt += QString::number( *x, 'f', 6 );
mWkt += QString::number( *x, 'f' );
ptr += sizeof( double );
mWkt += ", ";
y = ( double * ) ptr;
mWkt += QString::number( *y, 'f', 6 );
mWkt += QString::number( *y, 'f' );
ptr += sizeof( double );
if ( hasZValue )
{
Expand Down
36 changes: 28 additions & 8 deletions src/core/qgsrasterdataprovider.cpp
Expand Up @@ -25,6 +25,27 @@

#include <qmath.h>

void QgsRasterDataProvider::setUseSrcNoDataValue( int bandNo, bool use )
{
if ( mUseSrcNoDataValue.size() < bandNo )
{
for ( int i = mUseSrcNoDataValue.size(); i < bandNo; i++ )
{
mUseSrcNoDataValue.append( false );
}
}
mUseSrcNoDataValue[bandNo-1] = use;
}

double QgsRasterDataProvider::noDataValue( int bandNo ) const
{
if ( mSrcHasNoDataValue.value( bandNo - 1 ) && mUseSrcNoDataValue.value( bandNo - 1 ) )
{
return mSrcNoDataValue.value( bandNo -1 );
}
return mInternalNoDataValue.value( bandNo -1 );
}

void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle
const & viewExtent, int width,
int height,
Expand Down Expand Up @@ -289,7 +310,7 @@ QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
QByteArray ba;
ba.resize(( int )size );
char * data = ba.data();
double noval = mNoDataValue[theBandNo-1];
double noval = noDataValue( theBandNo - 1 );
unsigned char uc;
unsigned short us;
short s;
Expand Down Expand Up @@ -616,7 +637,6 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
int myWidth = myRasterBandStats.width;
int myHeight = myRasterBandStats.height;

double myNoDataValue = noDataValue();
int myDataType = dataType( theBandNo );

int myXBlockSize = xBlockSize();
Expand Down Expand Up @@ -669,7 +689,8 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
double myValue = readValue( myData, myDataType, myX + ( myY * myBlockWidth ) );
//QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );

if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
// TODO: user nodata
if ( isNoDataValue( theBandNo, myValue ) )
{
continue; // NULL
}
Expand Down Expand Up @@ -718,7 +739,6 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
myRasterBandStats.stdDev = sqrt( mySumOfSquares / ( myRasterBandStats.elementCount - 1 ) );

QgsDebugMsg( "************ STATS **************" );
QgsDebugMsg( QString( "VALID NODATA %1" ).arg( mValidNoDataValue ) );
QgsDebugMsg( QString( "MIN %1" ).arg( myRasterBandStats.minimumValue ) );
QgsDebugMsg( QString( "MAX %1" ).arg( myRasterBandStats.maximumValue ) );
QgsDebugMsg( QString( "RANGE %1" ).arg( myRasterBandStats.range ) );
Expand Down Expand Up @@ -893,7 +913,6 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
QgsRectangle myExtent = myHistogram.extent;
myHistogram.histogramVector.resize( myBinCount );

double myNoDataValue = noDataValue();
int myDataType = dataType( theBandNo );

int myXBlockSize = xBlockSize();
Expand Down Expand Up @@ -953,7 +972,8 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
double myValue = readValue( myData, myDataType, myX + ( myY * myBlockWidth ) );
//QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (myX).arg(myY).arg( myValue ) );

if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
// TODO: user defined nodata values
if ( isNoDataValue( theBandNo, myValue ) )
{
continue; // NULL
}
Expand Down Expand Up @@ -1034,7 +1054,7 @@ void QgsRasterDataProvider::cumulativeCut( int theBandNo,
double QgsRasterDataProvider::readValue( void *data, int type, int index )
{
if ( !data )
return mValidNoDataValue ? noDataValue() : 0.0;
return std::numeric_limits<double>::quiet_NaN();

switch ( type )
{
Expand Down Expand Up @@ -1063,7 +1083,7 @@ double QgsRasterDataProvider::readValue( void *data, int type, int index )
QgsLogger::warning( "GDAL data type is not supported" );
}

return mValidNoDataValue ? noDataValue() : 0.0;
return std::numeric_limits<double>::quiet_NaN();
}

void QgsRasterDataProvider::setUserNoDataValue( int bandNo, QList<QgsRasterInterface::Range> noData )
Expand Down

0 comments on commit 05ae00d

Please sign in to comment.