[QGIS Commit] r10549 - in branches/Version-1_0/src: app core/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Apr 12 20:42:05 EDT 2009
Author: ersts
Date: 2009-04-12 20:42:05 -0400 (Sun, 12 Apr 2009)
New Revision: 10549
Modified:
branches/Version-1_0/src/app/qgsrasterlayerproperties.cpp
branches/Version-1_0/src/core/raster/qgscolorrampshader.cpp
branches/Version-1_0/src/core/raster/qgsrasterlayer.cpp
branches/Version-1_0/src/core/raster/qgsrasterlayer.h
Log:
-ensuring revisions 10172,10173, 10271,10278,10279 are merged into version 1 branch
Modified: branches/Version-1_0/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- branches/Version-1_0/src/app/qgsrasterlayerproperties.cpp 2009-04-12 22:01:13 UTC (rev 10548)
+++ branches/Version-1_0/src/app/qgsrasterlayerproperties.cpp 2009-04-13 00:42:05 UTC (rev 10549)
@@ -1396,6 +1396,11 @@
myColorRampItems.push_back( myNewColorRampItem );
inserted = true;
}
+ else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
+ {
+ myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
+ inserted = true;
+ }
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
{
myColorRampItems.push_back( myNewColorRampItem );
@@ -1808,7 +1813,9 @@
void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
{
- QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
+ QSettings myQSettings;
+ QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
+ QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), myLastDir, tr( "Textfile (*.txt)" ) );
if ( !myFileName.isEmpty() )
{
if ( !myFileName.endsWith( ".txt", Qt::CaseInsensitive ) )
@@ -2266,7 +2273,9 @@
int myLineCounter = 0;
bool myImportError = false;
QString myBadLines;
- QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), "/", tr( "Textfile (*.txt)" ) );
+ QSettings myQSettings;
+ QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
+ QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), myLastDir, tr( "Textfile (*.txt)" ) );
QFile myInputFile( myFileName );
if ( myInputFile.open( QFile::ReadOnly ) )
{
@@ -2677,7 +2686,9 @@
void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
{
- QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
+ QSettings myQSettings;
+ QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
+ QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), myLastDir, tr( "Textfile (*.txt)" ) );
if ( !myFileName.isEmpty() )
{
if ( !myFileName.endsWith( ".txt", Qt::CaseInsensitive ) )
@@ -2757,7 +2768,9 @@
int myLineCounter = 0;
bool myImportError = false;
QString myBadLines;
- QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), "/", tr( "Textfile (*.txt)" ) );
+ QSettings myQSettings;
+ QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
+ QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), myLastDir, tr( "Textfile (*.txt)" ) );
QFile myInputFile( myFileName );
if ( myInputFile.open( QFile::ReadOnly ) )
{
@@ -2968,6 +2981,11 @@
myColorRampItems.push_back( myNewColorRampItem );
inserted = true;
}
+ else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
+ {
+ myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
+ inserted = true;
+ }
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
{
myColorRampItems.push_back( myNewColorRampItem );
Modified: branches/Version-1_0/src/core/raster/qgscolorrampshader.cpp
===================================================================
--- branches/Version-1_0/src/core/raster/qgscolorrampshader.cpp 2009-04-12 22:01:13 UTC (rev 10548)
+++ branches/Version-1_0/src/core/raster/qgscolorrampshader.cpp 2009-04-13 00:42:05 UTC (rev 10549)
@@ -17,11 +17,14 @@
* (at your option) any later version. *
* *
***************************************************************************/
+#define DOUBLE_DIFF_THRESHOLD 0.0000001
#include "qgslogger.h"
#include "qgscolorrampshader.h"
+#include <math.h>
+
QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
{
QgsDebugMsg( "called." );
@@ -54,17 +57,19 @@
return false;
}
+ double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
- else if ( theValue <= myColorRampItem.value )
+ else if ( theValue <= myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
@@ -94,12 +99,14 @@
return false;
}
+ double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
- if ( theValue == myColorRampItem.value )
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
+ if ( theValue == myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
@@ -133,13 +140,13 @@
bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
-
int myColorRampItemCount = mColorRampItemList.count();
if ( myColorRampItemCount <= 0 )
{
return false;
}
+ double myTinyDiff = 0.0;
double myCurrentRampRange; //difference between two consecutive entry values
double myOffsetInRange; //difference between the previous entry value and value
QgsColorRampShader::ColorRampItem myColorRampItem;
@@ -147,12 +154,13 @@
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
- else if ( mCurrentColorRampItemIndex != 0 && theValue <= myColorRampItem.value )
+ else if ( mCurrentColorRampItemIndex != 0 && ( theValue <= myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD ) )
{
QgsColorRampShader::ColorRampItem myPreviousColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex - 1 );
myCurrentRampRange = myColorRampItem.value - myPreviousColorRampItem.value;
Modified: branches/Version-1_0/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/Version-1_0/src/core/raster/qgsrasterlayer.cpp 2009-04-12 22:01:13 UTC (rev 10548)
+++ branches/Version-1_0/src/core/raster/qgsrasterlayer.cpp 2009-04-13 00:42:05 UTC (rev 10549)
@@ -104,6 +104,7 @@
mColorShadingAlgorithm = QgsRasterLayer::UndefinedShader;
mRasterShader = new QgsRasterShader();
+ mBandCount = 0;
mHasPyramids = false;
mNoDataValue = -9999;
mValidNoDataValue = false;
@@ -638,7 +639,7 @@
unsigned int QgsRasterLayer::bandCount()
{
- return mRasterStatsList.size();
+ return mBandCount;
}
const QString QgsRasterLayer::bandName( int theBandNo )
@@ -1838,7 +1839,7 @@
// Outside the raster
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
{
- theResults[ tr( "Band%1" ).arg( i )] = tr( "out of extent" );
+ theResults[ generateBandName( i ) ] = tr( "out of extent" );
}
}
else
@@ -1882,8 +1883,9 @@
{
v.setNum( value );
}
- theResults[tr( "Band%1" ).arg( i )] = v;
+ theResults[ generateBandName( i ) ] = v;
+
CPLFree( data );
}
}
@@ -4888,6 +4890,11 @@
mRasterStatsList.clear();
}
+QString QgsRasterLayer::generateBandName( int theBandNumber )
+{
+ return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10( ( float ) bandCount() ), 10, QChar( '0' ) );
+}
+
/**
* This method looks to see if a given band name exists.
*@note This function is no longer really needed and about to be removed
@@ -5166,13 +5173,12 @@
mRasterTransparency.initializeTransparentPixelList( mNoDataValue );
}
- //initialise the raster band stats and contrast enhancement vector
- for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
+ mBandCount = GDALGetRasterCount( mGdalDataset );
+ for ( int i = 1; i <= mBandCount; i++ )
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
QgsRasterBandStats myRasterBandStats;
- //myRasterBandStats.bandName = myColorQString ;
- myRasterBandStats.bandName = "Band " + QString::number( i );
+ myRasterBandStats.bandName = generateBandName( i );
myRasterBandStats.bandNumber = i;
myRasterBandStats.statsGathered = false;
myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
@@ -5347,12 +5353,34 @@
}
QgsDebugMsg( "No matching band name found in raster band stats" );
+ QgsDebugMsg( "Testing for non zero-buffered names" );
+ //TODO Remove test in v2.0 or earlier
+ QStringList myBandNameComponents = theBandName.split( " " );
+ if ( myBandNameComponents.size() == 2 )
+ {
+ int myBandNumber = myBandNameComponents.at( 1 ).toInt();
+ if ( myBandNumber > 0 )
+ {
+ QString myBandName = generateBandName( myBandNumber );
+ for ( int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator )
+ {
+ //find out the name of this band
+ if ( mRasterStatsList[myIterator].bandName == myBandName )
+ {
+ QgsDebugMsg( "Matching band name found" );
+ return myBandName;
+ }
+ }
+ }
+ }
+
QgsDebugMsg( "Testing older naming format" );
//See of the band in an older format #:something.
- //TODO Remove test in v2.0
+ //TODO Remove test in v2.0 or earlier
+ myBandNameComponents.clear();
if ( theBandName.contains( ':' ) )
{
- QStringList myBandNameComponents = theBandName.split( ":" );
+ myBandNameComponents = theBandName.split( ":" );
if ( myBandNameComponents.size() == 2 )
{
int myBandNumber = myBandNameComponents.at( 0 ).toInt();
Modified: branches/Version-1_0/src/core/raster/qgsrasterlayer.h
===================================================================
--- branches/Version-1_0/src/core/raster/qgsrasterlayer.h 2009-04-12 22:01:13 UTC (rev 10548)
+++ branches/Version-1_0/src/core/raster/qgsrasterlayer.h 2009-04-13 00:42:05 UTC (rev 10549)
@@ -668,6 +668,7 @@
//
// Private methods
//
+
/** \brief Drawing routine for multiband image */
void drawMultiBandColor( QPainter * theQPainter,
QgsRasterViewPort * theRasterViewPort,
@@ -724,6 +725,9 @@
/** \brief Close data set and release related data */
void closeDataset();
+ /** \brief helper function to create zero padded band names */
+ QString generateBandName( int );
+
/** \brief Find out whether a given band exists. */
bool hasBand( const QString & theBandName );
@@ -759,6 +763,9 @@
const QString QSTRING_NOT_SET;
const QString TRSTRING_NOT_SET;
+ /** \brief The number of bands in the dataset */
+ int mBandCount;
+
/** \brief The band to be associated with the color blue - usually 3 */
QString mBlueBandName;
More information about the QGIS-commit
mailing list