Skip to content

Commit 8b18577

Browse files
committedApr 19, 2013
raster cleanup
1 parent 1f872ce commit 8b18577

14 files changed

+194
-1774
lines changed
 

‎python/core/raster/qgsrasterlayer.sip

Lines changed: 2 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ class QgsRasterLayer : QgsMapLayer
9999
ContrastEnhancementCumulativeCut
100100
};
101101

102-
/** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */
103-
typedef QList<QgsContrastEnhancement> ContrastEnhancementList;
104-
105-
/** \brief A list containing one RasterPyramid struct per raster band in this raster layer.
106-
* POTENTIAL pyramid layer. This works by dividing the height
107-
* and width of the raster by an incrementing number. As soon as the result
108-
* of the division is <=256 we stop allowing RasterPyramid structs
109-
* to be added to the list. Each time a RasterPyramid is created
110-
* we will check to see if a pyramid matching these dimensions already exists
111-
* in the raster layer, and if so mark the exists flag as true */
112-
/* typedef QList<QgsRasterPyramid> RasterPyramidList; */
113-
114-
/** \brief A list containing one RasterBandStats struct per raster band in this raster layer.
115-
* Note that while every RasterBandStats element will have the name and number of its associated
116-
* band populated, any additional stats are calculated on a need to know basis.*/
117-
/* typedef QList<QgsRasterBandStats> RasterStatsList; */
118-
119102
//
120103
// Static methods:
121104
//
@@ -128,69 +111,30 @@ class QgsRasterLayer : QgsMapLayer
128111
*/
129112
static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
130113
static bool isValidRasterFileName( const QString & theFileNameQString );
131-
//static QStringList subLayers( GDALDatasetH dataset );
132114

133115
/** Return time stamp for given file name */
134116
static QDateTime lastModified( const QString & name );
135117

136-
// Keep this for now, it is used by Python interface!!!
137-
/** \brief ensures that GDAL drivers are registered, but only once */
138-
static void registerGdalDrivers();
139-
140118
//
141119
// Non Static inline methods
142120
//
143-
144-
/** \brief Initialize default values */
145-
void init();
146-
147121
/** [ data provider interface ] Set the data provider */
148122
void setDataProvider( const QString & provider );
149123

150-
/** \brief Accessor for blue band name mapping */
151-
QString blueBandName() const;
152-
153-
/** \brief Accessor for color shader algorithm */
154-
QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const;
155-
156-
/** \brief Accessor for contrast enhancement algorithm */
157-
QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm();
158-
159-
/** \brief Returns contrast enhancement algorithm as a string */
160-
QString contrastEnhancementAlgorithmAsString() const;
161-
162124
/** \brief Accessor for drawing style */
163125
DrawingStyle drawingStyle();
164126

165-
/** \brief Accessor for mHasPyramids (READ ONLY) */
166-
/* bool hasPyramids(); */
167-
168-
/** \brief Accessor for mUserDefinedGrayMinimumMaximum */
169-
bool hasUserDefinedGrayMinimumMaximum() const;
170-
171-
/** \brief Accessor for mUserDefinedRGBMinimumMaximum */
172-
bool hasUserDefinedRGBMinimumMaximum() const;
127+
/** \brief Accessor that returns the width of the (unclipped) raster */
128+
int width();
173129

174130
/** \brief Accessor that returns the height of the (unclipped) raster */
175131
int height();
176132

177133
/** \brief Accessor for raster layer type (which is a read only property) */
178134
LayerType rasterType();
179135

180-
181136
/** \brief Mutator for drawing style */
182137
void setDrawingStyle( const DrawingStyle & theDrawingStyle );
183-
/**Sets corresponding renderer for style*/
184-
void setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle );
185-
186-
/** \brief Mutator to alter the number of standard deviations that should be plotted */
187-
void setStandardDeviations( double theStandardDeviations );
188-
189-
/** \brief Mutator for mUserDefinedGrayMinimumMaximum */
190-
void setUserDefinedGrayMinimumMaximum( bool theBool );
191-
192-
/** \brief Mutator for mUserDefinedRGBMinimumMaximum */
193-
void setUserDefinedRGBMinimumMaximum( bool theBool );
194138

195139
/**Set raster renderer. Takes ownership of the renderer object*/
196140
void setRenderer( QgsRasterRenderer* theRenderer /Transfer/ );
@@ -203,12 +147,6 @@ class QgsRasterLayer : QgsMapLayer
203147
/** Get raster pipe */
204148
QgsRasterPipe * pipe();
205149

206-
/** \brief Accessor to find out how many standard deviations are being plotted */
207-
double standardDeviations() const;
208-
209-
/** \brief Accessor that returns the width of the (unclipped) raster */
210-
int width();
211-
212150
//
213151
// Non Static methods
214152
//
@@ -218,33 +156,6 @@ class QgsRasterLayer : QgsMapLayer
218156
/** \brief Get the name of a band given its number */
219157
const QString bandName( int theBandNoInt );
220158

221-
/** \brief Get the number of a band given its name. The name is the rewritten name set
222-
* up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
223-
* If no matching band is found zero will be returned! */
224-
int bandNumber( const QString & theBandName ) const;
225-
226-
/** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
227-
* POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
228-
* ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
229-
* list.
230-
*/
231-
// RasterPyramidList buildPyramidList();
232-
233-
/** \brief Accessor for color shader algorithm */
234-
QString colorShadingAlgorithmAsString() const;
235-
236-
/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent
237-
\note added in v1.6 */
238-
//void computeMinimumMaximumFromLastExtent( int theBand, double& theMin /Out/, double& theMax /Out/ );
239-
240-
/** \brief Get a pointer to the contrast enhancement for the selected band */
241-
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );
242-
243-
const QgsContrastEnhancement* constContrastEnhancement( unsigned int theBand ) const;
244-
245-
/** \brief Get a pointer to the color table */
246-
QList<QgsColorRampShader::ColorRampItem> colorTable( int theBandNoInt );
247-
248159
/** Returns the data provider */
249160
QgsRasterDataProvider* dataProvider();
250161

@@ -266,33 +177,6 @@ class QgsRasterLayer : QgsMapLayer
266177
QgsRasterViewPort * myRasterViewPort,
267178
const QgsMapToPixel* theQgsMapToPixel = 0 );
268179

269-
/** \brief Returns a string representation of drawing style
270-
*
271-
* Implemented mainly for serialisation / deserialisation of settings to xml.
272-
* NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead.
273-
* */
274-
QString drawingStyleAsString() const;
275-
276-
/** \brief Identify raster value(s) found on the point position */
277-
//bool identify( const QgsPoint & point, QMap<QString, QString>& results /Out/ );
278-
279-
/** \brief Identify raster value(s) found on the point position */
280-
// bool identifyMap( const QgsPoint & point, QMap<int, QString>& results /Out/ );
281-
//%MethodCode
282-
// sipRes = sipCpp->identify( *a0, *a1 );
283-
//%End
284-
285-
/** \brief Identify arbitrary details from the WMS server found on the point position */
286-
//QString identifyAsText( const QgsPoint & point );
287-
288-
/** \brief Identify arbitrary details from the WMS server found on the point position
289-
* @note added in 1.5
290-
*/
291-
//QString identifyAsHtml( const QgsPoint & point );
292-
293-
/** \brief Currently returns always false */
294-
bool isEditable() const;
295-
296180
/** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */
297181
QString lastError();
298182

@@ -303,21 +187,9 @@ class QgsRasterLayer : QgsMapLayer
303187
@note this method was added in version 1.8*/
304188
QList< QPair< QString, QColor > > legendSymbologyItems() const;
305189

306-
/** \brief Accessor for maximum value user for contrast enhancement */
307-
double maximumValue( unsigned int theBand );
308-
309-
/** \brief Accessor for maximum value user for contrast enhancement */
310-
double maximumValue( QString theBand );
311-
312190
/** \brief Obtain GDAL Metadata for this layer */
313191
QString metadata();
314192

315-
/** \brief Accessor for minimum value user for contrast enhancement */
316-
double minimumValue( unsigned int theBand );
317-
318-
/** \brief Accessor for minimum value user for contrast enhancement */
319-
double minimumValue( QString theBand );
320-
321193
/** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */
322194
QPixmap paletteAsPixmap( int theBandNumber = 1 );
323195

@@ -329,20 +201,9 @@ class QgsRasterLayer : QgsMapLayer
329201
/** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
330202
double rasterUnitsPerPixel();
331203

332-
/** \brief Read color table from GDAL raster band */
333-
// bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );
334-
335-
/** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */
336-
//void resetNoDataValue();
337-
338204
static QString contrastEnhancementLimitsAsString( QgsRasterLayer::ContrastEnhancementLimits theLimits );
339205
static ContrastEnhancementLimits contrastEnhancementLimitsFromString( QString theLimits );
340206

341-
/** \brief Mutator for contrast enhancement algorithm using min/max */
342-
// TODO: remove in 2.0, replaced by following
343-
// void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
344-
// bool theGenerateLookupTableFlag = true );
345-
346207
/** \brief Mutator for contrast enhancement algorithm
347208
* @param theAlgorithm Contrast enhancement algorithm
348209
* @param theLimits Limits
@@ -357,30 +218,12 @@ class QgsRasterLayer : QgsMapLayer
357218
int theSampleSize = QgsRasterLayer::SAMPLE_SIZE,
358219
bool theGenerateLookupTableFlag = true );
359220

360-
/** \brief Mutator for contrast enhancement algorithm */
361-
void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true );
362-
363-
/** \brief Mutator for contrast enhancement function */
364-
void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction );
365-
366221
/** \brief Set default contrast enhancement */
367222
void setDefaultContrastEnhancement();
368223

369224
/** \brief Overloaded version of the above function for convenience when restoring from xml */
370225
void setDrawingStyle( const QString & theDrawingStyleQString );
371226

372-
/** \brief Mutator for setting the maximum value for contrast enhancement */
373-
void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
374-
375-
/** \brief Sets the minimum and maximum values for the band(s) currently
376-
* being displayed using the only pixel values from the last/current extent
377-
* */
378-
void setMinimumMaximumUsingLastExtent();
379-
380-
/** \brief Sets the minimum and maximum values for the band(s) currently
381-
* being displayed using the only pixel values from the dataset min/max */
382-
void setMinimumMaximumUsingDataset();
383-
384227
/** \brief [ data provider interface ] A wrapper function to emit a progress update signal */
385228
void showProgress( int theValue );
386229

@@ -413,11 +256,6 @@ class QgsRasterLayer : QgsMapLayer
413256
virtual QDateTime timestamp() const;
414257

415258
public slots:
416-
/** \brief Create GDAL pyramid overviews */
417-
// QString buildPyramids( const RasterPyramidList &,
418-
// const QString & theResamplingMethod = "NEAREST",
419-
// bool theTryInternalFlag = false );
420-
421259
void showStatusMessage( const QString & theMessage );
422260

423261
/** \brief Propagate progress updates from GDAL up to the parent app */

‎src/app/legend/qgslegend.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,25 +2753,11 @@ void QgsLegend::legendLayerStretchUsingCurrentExtent()
27532753
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( currentLayer->layer() );
27542754
if ( layer )
27552755
{
2756-
// Note: Do we really want to do these next clauses? The user will get a surprise when the
2757-
// drawing style they are using suddenly changes....! TS
2758-
if ( layer->drawingStyle() == QgsRasterLayer::SingleBandPseudoColor )
2759-
{
2760-
layer->setDrawingStyle( QgsRasterLayer::SingleBandGray );
2761-
}
2762-
else if ( layer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandPseudoColor )
2763-
{
2764-
layer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandGray );
2765-
}
2766-
2767-
if ( layer->contrastEnhancementAlgorithmAsString() == "NoEnhancement" )
2768-
{
2769-
layer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
2770-
}
2756+
QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm = QgsContrastEnhancement::StretchToMinimumMaximum;
27712757

27722758
QgsRectangle myRectangle;
27732759
myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( layer, mMapCanvas->extent() );
2774-
layer->setContrastEnhancementAlgorithm( layer->contrastEnhancementAlgorithm(), QgsRasterLayer::ContrastEnhancementMinMax, myRectangle );
2760+
layer->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm, QgsRasterLayer::ContrastEnhancementMinMax, myRectangle );
27752761

27762762
layer->setCacheImage( NULL );
27772763
refreshLayerSymbology( layer->id() );

‎src/app/qgsrastercalcdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void QgsRasterCalcDialog::insertAvailableRasterBands()
125125
firstLayer = false;
126126
}
127127
//get number of bands
128-
for ( unsigned int i = 0; i < rlayer->bandCount(); ++i )
128+
for ( int i = 0; i < rlayer->bandCount(); ++i )
129129
{
130130
QgsRasterCalculatorEntry entry;
131131
entry.raster = rlayer;

‎src/core/qgsprojectfiletransform.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,13 @@ int QgsProjectFileTransform::rasterBandNumber( const QDomElement& rasterProperti
816816
QDomElement rasterBandElem = rasterPropertiesElem.firstChildElement( bandName );
817817
if ( !rasterBandElem.isNull() )
818818
{
819-
band = rlayer->bandNumber( rasterBandElem.text() );
820-
if ( band == 0 )
819+
for ( int i = 1; i <= rlayer->bandCount(); i++ )
821820
{
822-
band = -1;
821+
if ( rlayer->bandName( i ) == rasterBandElem.text() )
822+
{
823+
band = i;
824+
break;
825+
}
823826
}
824827
}
825828
return band;

‎src/core/raster/qgscontrastenhancement.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void QgsContrastEnhancement::writeXML( QDomDocument& doc, QDomElement& parentEle
395395

396396
//algorithm
397397
QDomElement algorithmElem = doc.createElement( "algorithm" );
398-
QDomText algorithmText = doc.createTextNode( QString::number( mContrastEnhancementAlgorithm ) );
398+
QDomText algorithmText = doc.createTextNode( contrastEnhancementAlgorithmString( mContrastEnhancementAlgorithm ) );
399399
algorithmElem.appendChild( algorithmText );
400400
parentElem.appendChild( algorithmElem );
401401
}
@@ -415,8 +415,54 @@ void QgsContrastEnhancement::readXML( const QDomElement& elem )
415415
QDomElement algorithmElem = elem.firstChildElement( "algorithm" );
416416
if ( !algorithmElem.isNull() )
417417
{
418-
setContrastEnhancementAlgorithm(( ContrastEnhancementAlgorithm )( algorithmElem.text().toInt() ) );
418+
QString algorithmString = algorithmElem.text();
419+
ContrastEnhancementAlgorithm algorithm = NoEnhancement;
420+
// old version ( < 19 Apr 2013) was using enum directly -> for backward compatibility
421+
if ( algorithmString == "0" )
422+
{
423+
algorithm = NoEnhancement;
424+
}
425+
else if ( algorithmString == "1" )
426+
{
427+
algorithm = StretchToMinimumMaximum;
428+
}
429+
else if ( algorithmString == "2" )
430+
{
431+
algorithm = StretchAndClipToMinimumMaximum;
432+
}
433+
else if ( algorithmString == "3" )
434+
{
435+
algorithm = ClipToMinimumMaximum;
436+
}
437+
else if ( algorithmString == "4" )
438+
{
439+
algorithm = UserDefinedEnhancement;
440+
}
441+
else
442+
{
443+
algorithm = contrastEnhancementAlgorithmFromString( algorithmString );
444+
}
445+
446+
setContrastEnhancementAlgorithm( algorithm );
447+
}
448+
}
449+
450+
QString QgsContrastEnhancement::contrastEnhancementAlgorithmString( ContrastEnhancementAlgorithm algorithm )
451+
{
452+
switch ( algorithm )
453+
{
454+
case NoEnhancement:
455+
return "NoEnhancement";
456+
case StretchToMinimumMaximum:
457+
return "StretchToMinimumMaximum";
458+
case StretchAndClipToMinimumMaximum:
459+
return "StretchAndClipToMinimumMaximum";
460+
case ClipToMinimumMaximum:
461+
return "ClipToMinimumMaximum";
462+
case UserDefinedEnhancement:
463+
return "UserDefinedEnhancement";
419464
}
465+
return "NoEnhancement";
420466
}
421467

422468
QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsContrastEnhancement::contrastEnhancementAlgorithmFromString( const QString& contrastEnhancementString )
@@ -433,6 +479,10 @@ QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsContrastEnhancement::con
433479
{
434480
return ClipToMinimumMaximum;
435481
}
482+
else if ( contrastEnhancementString == "UserDefinedEnhancement" )
483+
{
484+
return UserDefinedEnhancement;
485+
}
436486
else
437487
{
438488
return NoEnhancement;

0 commit comments

Comments
 (0)
Please sign in to comment.