Skip to content

Commit c2e13e7

Browse files
author
ersts
committed
-ensuring revisions 10172,10173, 10271,10278,10279 are merged into version 1 branch
git-svn-id: http://svn.osgeo.org/qgis/branches/Version-1_0@10549 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c9743b5 commit c2e13e7

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

src/app/qgsrasterlayerproperties.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,11 @@ void QgsRasterLayerProperties::apply()
13961396
myColorRampItems.push_back( myNewColorRampItem );
13971397
inserted = true;
13981398
}
1399+
else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
1400+
{
1401+
myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
1402+
inserted = true;
1403+
}
13991404
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
14001405
{
14011406
myColorRampItems.push_back( myNewColorRampItem );
@@ -1808,7 +1813,9 @@ void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
18081813

18091814
void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
18101815
{
1811-
QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
1816+
QSettings myQSettings;
1817+
QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
1818+
QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), myLastDir, tr( "Textfile (*.txt)" ) );
18121819
if ( !myFileName.isEmpty() )
18131820
{
18141821
if ( !myFileName.endsWith( ".txt", Qt::CaseInsensitive ) )
@@ -2266,7 +2273,9 @@ void QgsRasterLayerProperties::on_pbnImportTransparentPixelValues_clicked()
22662273
int myLineCounter = 0;
22672274
bool myImportError = false;
22682275
QString myBadLines;
2269-
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), "/", tr( "Textfile (*.txt)" ) );
2276+
QSettings myQSettings;
2277+
QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
2278+
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), myLastDir, tr( "Textfile (*.txt)" ) );
22702279
QFile myInputFile( myFileName );
22712280
if ( myInputFile.open( QFile::ReadOnly ) )
22722281
{
@@ -2677,7 +2686,9 @@ void QgsRasterLayerProperties::on_pbtnAddColorMapEntry_clicked()
26772686

26782687
void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
26792688
{
2680-
QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
2689+
QSettings myQSettings;
2690+
QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
2691+
QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), myLastDir, tr( "Textfile (*.txt)" ) );
26812692
if ( !myFileName.isEmpty() )
26822693
{
26832694
if ( !myFileName.endsWith( ".txt", Qt::CaseInsensitive ) )
@@ -2757,7 +2768,9 @@ void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked()
27572768
int myLineCounter = 0;
27582769
bool myImportError = false;
27592770
QString myBadLines;
2760-
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), "/", tr( "Textfile (*.txt)" ) );
2771+
QSettings myQSettings;
2772+
QString myLastDir = myQSettings.value( "lastRasterFileFilterDir", "" ).toString();
2773+
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), myLastDir, tr( "Textfile (*.txt)" ) );
27612774
QFile myInputFile( myFileName );
27622775
if ( myInputFile.open( QFile::ReadOnly ) )
27632776
{
@@ -2968,6 +2981,11 @@ void QgsRasterLayerProperties::on_pbtnSortColorMap_clicked()
29682981
myColorRampItems.push_back( myNewColorRampItem );
29692982
inserted = true;
29702983
}
2984+
else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
2985+
{
2986+
myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
2987+
inserted = true;
2988+
}
29712989
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
29722990
{
29732991
myColorRampItems.push_back( myNewColorRampItem );

src/core/raster/qgscolorrampshader.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ originally part of the larger QgsRasterLayer class
1717
* (at your option) any later version. *
1818
* *
1919
***************************************************************************/
20+
#define DOUBLE_DIFF_THRESHOLD 0.0000001
2021

2122
#include "qgslogger.h"
2223

2324
#include "qgscolorrampshader.h"
2425

26+
#include <math.h>
27+
2528
QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
2629
{
2730
QgsDebugMsg( "called." );
@@ -54,17 +57,19 @@ bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue,
5457
return false;
5558
}
5659

60+
double myTinyDiff = 0.0;
5761
QgsColorRampShader::ColorRampItem myColorRampItem;
5862
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
5963
{
6064
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
6165
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
66+
myTinyDiff = fabs( theValue - myColorRampItem.value );
6267
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
6368
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
6469
{
6570
mCurrentColorRampItemIndex--;
6671
}
67-
else if ( theValue <= myColorRampItem.value )
72+
else if ( theValue <= myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
6873
{
6974
*theReturnRedValue = myColorRampItem.color.red();
7075
*theReturnGreenValue = myColorRampItem.color.green();
@@ -94,12 +99,14 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in
9499
return false;
95100
}
96101

102+
double myTinyDiff = 0.0;
97103
QgsColorRampShader::ColorRampItem myColorRampItem;
98104
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
99105
{
100106
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
101107
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
102-
if ( theValue == myColorRampItem.value )
108+
myTinyDiff = fabs( theValue - myColorRampItem.value );
109+
if ( theValue == myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD )
103110
{
104111
*theReturnRedValue = myColorRampItem.color.red();
105112
*theReturnGreenValue = myColorRampItem.color.green();
@@ -133,26 +140,27 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in
133140

134141
bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
135142
{
136-
137143
int myColorRampItemCount = mColorRampItemList.count();
138144
if ( myColorRampItemCount <= 0 )
139145
{
140146
return false;
141147
}
142148

149+
double myTinyDiff = 0.0;
143150
double myCurrentRampRange; //difference between two consecutive entry values
144151
double myOffsetInRange; //difference between the previous entry value and value
145152
QgsColorRampShader::ColorRampItem myColorRampItem;
146153
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
147154
{
148155
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
149156
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
157+
myTinyDiff = fabs( theValue - myColorRampItem.value );
150158
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
151159
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
152160
{
153161
mCurrentColorRampItemIndex--;
154162
}
155-
else if ( mCurrentColorRampItemIndex != 0 && theValue <= myColorRampItem.value )
163+
else if ( mCurrentColorRampItemIndex != 0 && ( theValue <= myColorRampItem.value || myTinyDiff <= DOUBLE_DIFF_THRESHOLD ) )
156164
{
157165
QgsColorRampShader::ColorRampItem myPreviousColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex - 1 );
158166
myCurrentRampRange = myColorRampItem.value - myPreviousColorRampItem.value;

src/core/raster/qgsrasterlayer.cpp

+37-9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ QgsRasterLayer::QgsRasterLayer(
104104
mColorShadingAlgorithm = QgsRasterLayer::UndefinedShader;
105105
mRasterShader = new QgsRasterShader();
106106

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

639640
unsigned int QgsRasterLayer::bandCount()
640641
{
641-
return mRasterStatsList.size();
642+
return mBandCount;
642643
}
643644

644645
const QString QgsRasterLayer::bandName( int theBandNo )
@@ -1838,7 +1839,7 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
18381839
// Outside the raster
18391840
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
18401841
{
1841-
theResults[ tr( "Band%1" ).arg( i )] = tr( "out of extent" );
1842+
theResults[ generateBandName( i ) ] = tr( "out of extent" );
18421843
}
18431844
}
18441845
else
@@ -1882,7 +1883,8 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
18821883
{
18831884
v.setNum( value );
18841885
}
1885-
theResults[tr( "Band%1" ).arg( i )] = v;
1886+
1887+
theResults[ generateBandName( i ) ] = v;
18861888

18871889
CPLFree( data );
18881890
}
@@ -4888,6 +4890,11 @@ void QgsRasterLayer::closeDataset()
48884890
mRasterStatsList.clear();
48894891
}
48904892

4893+
QString QgsRasterLayer::generateBandName( int theBandNumber )
4894+
{
4895+
return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10( ( float ) bandCount() ), 10, QChar( '0' ) );
4896+
}
4897+
48914898
/**
48924899
* This method looks to see if a given band name exists.
48934900
*@note This function is no longer really needed and about to be removed
@@ -5166,13 +5173,12 @@ bool QgsRasterLayer::readFile( QString const &theFilename )
51665173
mRasterTransparency.initializeTransparentPixelList( mNoDataValue );
51675174
}
51685175

5169-
//initialise the raster band stats and contrast enhancement vector
5170-
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
5176+
mBandCount = GDALGetRasterCount( mGdalDataset );
5177+
for ( int i = 1; i <= mBandCount; i++ )
51715178
{
51725179
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
51735180
QgsRasterBandStats myRasterBandStats;
5174-
//myRasterBandStats.bandName = myColorQString ;
5175-
myRasterBandStats.bandName = "Band " + QString::number( i );
5181+
myRasterBandStats.bandName = generateBandName( i );
51765182
myRasterBandStats.bandNumber = i;
51775183
myRasterBandStats.statsGathered = false;
51785184
myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
@@ -5347,12 +5353,34 @@ QString QgsRasterLayer::validateBandName( QString const & theBandName )
53475353
}
53485354
QgsDebugMsg( "No matching band name found in raster band stats" );
53495355

5356+
QgsDebugMsg( "Testing for non zero-buffered names" );
5357+
//TODO Remove test in v2.0 or earlier
5358+
QStringList myBandNameComponents = theBandName.split( " " );
5359+
if ( myBandNameComponents.size() == 2 )
5360+
{
5361+
int myBandNumber = myBandNameComponents.at( 1 ).toInt();
5362+
if ( myBandNumber > 0 )
5363+
{
5364+
QString myBandName = generateBandName( myBandNumber );
5365+
for ( int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator )
5366+
{
5367+
//find out the name of this band
5368+
if ( mRasterStatsList[myIterator].bandName == myBandName )
5369+
{
5370+
QgsDebugMsg( "Matching band name found" );
5371+
return myBandName;
5372+
}
5373+
}
5374+
}
5375+
}
5376+
53505377
QgsDebugMsg( "Testing older naming format" );
53515378
//See of the band in an older format #:something.
5352-
//TODO Remove test in v2.0
5379+
//TODO Remove test in v2.0 or earlier
5380+
myBandNameComponents.clear();
53535381
if ( theBandName.contains( ':' ) )
53545382
{
5355-
QStringList myBandNameComponents = theBandName.split( ":" );
5383+
myBandNameComponents = theBandName.split( ":" );
53565384
if ( myBandNameComponents.size() == 2 )
53575385
{
53585386
int myBandNumber = myBandNameComponents.at( 0 ).toInt();

src/core/raster/qgsrasterlayer.h

+7
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
668668
//
669669
// Private methods
670670
//
671+
671672
/** \brief Drawing routine for multiband image */
672673
void drawMultiBandColor( QPainter * theQPainter,
673674
QgsRasterViewPort * theRasterViewPort,
@@ -724,6 +725,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
724725
/** \brief Close data set and release related data */
725726
void closeDataset();
726727

728+
/** \brief helper function to create zero padded band names */
729+
QString generateBandName( int );
730+
727731
/** \brief Find out whether a given band exists. */
728732
bool hasBand( const QString & theBandName );
729733

@@ -759,6 +763,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
759763
const QString QSTRING_NOT_SET;
760764
const QString TRSTRING_NOT_SET;
761765

766+
/** \brief The number of bands in the dataset */
767+
int mBandCount;
768+
762769
/** \brief The band to be associated with the color blue - usually 3 */
763770
QString mBlueBandName;
764771

0 commit comments

Comments
 (0)