Skip to content
Permalink
Browse files

-ensuring revisions 10172,10173, 10271,10278,10279 are merged into ve…

…rsion 1 branch

git-svn-id: http://svn.osgeo.org/qgis/branches/Version-1_0@10549 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts
ersts committed Apr 13, 2009
1 parent c9743b5 commit c2e13e7a89f8dfd6e071ae21147a11116377f67c
@@ -1396,6 +1396,11 @@ void QgsRasterLayerProperties::apply()
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_pbnDefaultValues_clicked()

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 @@ void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
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_pbtnAddColorMapEntry_clicked()

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 @@ void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked()
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 @@ void QgsRasterLayerProperties::on_pbtnSortColorMap_clicked()
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 );
@@ -17,11 +17,14 @@ originally part of the larger QgsRasterLayer class
* (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 @@ bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue,
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 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in
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,26 +140,27 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in

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;
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 ( 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;
@@ -104,6 +104,7 @@ QgsRasterLayer::QgsRasterLayer(
mColorShadingAlgorithm = QgsRasterLayer::UndefinedShader;
mRasterShader = new QgsRasterShader();

mBandCount = 0;
mHasPyramids = false;
mNoDataValue = -9999;
mValidNoDataValue = false;
@@ -638,7 +639,7 @@ int CPL_STDCALL progressCallback( double dfComplete,

unsigned int QgsRasterLayer::bandCount()
{
return mRasterStatsList.size();
return mBandCount;
}

const QString QgsRasterLayer::bandName( int theBandNo )
@@ -1838,7 +1839,7 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
// 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,7 +1883,8 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
{
v.setNum( value );
}
theResults[tr( "Band%1" ).arg( i )] = v;

theResults[ generateBandName( i ) ] = v;

CPLFree( data );
}
@@ -4888,6 +4890,11 @@ void QgsRasterLayer::closeDataset()
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 @@ bool QgsRasterLayer::readFile( QString const &theFilename )
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 @@ QString QgsRasterLayer::validateBandName( QString const & theBandName )
}
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();
@@ -668,6 +668,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
//
// Private methods
//

/** \brief Drawing routine for multiband image */
void drawMultiBandColor( QPainter * theQPainter,
QgsRasterViewPort * theRasterViewPort,
@@ -724,6 +725,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \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 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
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;

0 comments on commit c2e13e7

Please sign in to comment.