1
/***************************************************************************
2
qgsrasterlayer.h - description
4
begin : Fri Jun 28 2002
5
copyright : (C) 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
6
email : tim@linfiniti.com
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
/* $Id: qgsrasterlayer.h,v 1.51 2004/11/15 21:52:57 mhugent Exp $ */
19
/** \file qgsrasterlayer.h
20
* \brief This class provides qgis with the ability to render raster datasets
21
* onto the mapcanvas..
23
* The qgsrasterlayer class makes use of gdal for data io, and thus supports
24
* any gdal supported format. The constructor attemtps to infer what type of
25
* file (RASTER_LAYER_TYPE) is being opened - not in terms of the file format (tif, ascii grid etc.)
26
* but rather in terms of whether the image is a GRAYSCALE, PALETTED or MULTIBAND,
28
* Within the three allowable raster layer types, there are 8 permutations of
29
* how a layer can actually be rendered. These are defined in the DRAWING_STYLE enum
32
* SINGLE_BAND_GRAY -> a GRAYSCALE layer drawn as a range of gray colors (0-255)
33
* SINGLE_BAND_PSEUDO_COLOR -> a GRAYSCALE layer drawn using a pseudocolor algorithm
34
* PALETTED_SINGLE_BAND_GRAY -> a PALLETED layer drawn in gray scale (using only one of the color components)
35
* PALETTED_SINGLE_BAND_PSEUDO_COLOR -> a PALLETED layer having only one of its color components rendered as psuedo color
36
* PALETTED_MULTI_BAND_COLOR -> a PALLETED image where the bands contains 24bit color info and 8 bits is pulled out per color
37
* MULTI_BAND_SINGLE_BAND_GRAY -> a layer containing 2 or more bands, but using only one band to produce a grayscale image
38
* MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR -> a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
39
* MULTI_BAND_COLOR -> a layer containing 2 or more bands, mapped to the three RGBcolors. In the case of a multiband with only two bands, one band will have to be mapped to more than one color
41
* Each of the above mentioned drawing styles is implemented in its own draw* function.
42
* Some of the drawing styles listed above require statistics about the layer such
43
* as the min / max / mean / stddev etc. Statics for a band can be gathered using the
44
* getRasterBandStats function. Note that statistics gathering is a slow process and
45
* evey effort should be made to call this function as few times as possible. For this
46
* reason, qgsraster has a vector class member to store stats for each band. The
47
* constructor initialises this vector on startup, but only populates the band name and
50
* Note that where bands are of gdal 'undefined' type, their values may exceed the
51
* renderable range of 0-255. Because of this a linear scaling histogram stretch is
52
* applied to undefined layers to normalise the data into the 0-255 range.
54
* A qgsrasterlayer band can be referred to either by name or by number (base=1). It
55
* should be noted that band names as stored in datafiles may not be uniqe, and
56
* so the rasterlayer class appends the band number in brackets behind each band name.
58
* Sample useage of the QgsRasterLayer class:
60
* QString myFileNameQString = "/path/to/file";
61
* QFileInfo myFileInfo(myFileNameQString);
62
* QString myBaseNameQString = myFileInfo.baseName();
63
* QgsRasterLayer *myRasterLayer = new QgsRasterLayer(myFileNameQString, myBaseNameQString);
64
* myRasterLayer->initContextMenu(this); //prepare the right click pop up menu
66
* In order to automate redrawing of a raster layer, you should like it to a map canvas like this :
68
* QObject::connect( myRasterLayer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) );
70
* A raster layer can also export its legend as a pixmap:
72
* QPixmap myQPixmap = myRasterLayer->legendPixmap();
74
* Once a layer has been created you can find out what type of layer it is (GRAY_OR_UNDEFINED, PALETTE or MULTIBAND):
76
* if (rasterLayer->getRasterLayerType()==QgsRasterLayer::MULTIBAND)
80
* else if (rasterLayer->getRasterLayerType()==QgsRasterLayer::PALETTE)
84
* else // QgsRasterLayer::GRAY_OR_UNDEFINED
89
* You can combine layer type detection with the setDrawingStyle method to override the default drawing style assigned
90
* when a layer is loaded.:
92
* if (rasterLayer->getRasterLayerType()==QgsRasterLayer::MULTIBAND)
94
* myRasterLayer->setDrawingStyle(QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR);
96
* else if (rasterLayer->getRasterLayerType()==QgsRasterLayer::PALETTE)
98
* myRasterLayer->setDrawingStyle(QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR);
100
* else // QgsRasterLayer::GRAY_OR_UNDEFINED
102
* myRasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
105
* Raster layers can also have an aribitary level of transparency defined, and have their
106
* colour palettes inverted using the setTransparency and setInvertHistogramFlag methods.
108
* Pseudocolour images can have their output adjusted to a given number of standard
109
* deviations using the setStdDevsToPlot method.
111
* The final area of functionality you may be interested in is band mapping. Band mapping
112
* allows you to choose arbitary band -> colour mappings and is applicable only to PALETTE
113
* and MULTIBAND rasters, There are four mappings that can be made : red, green, blue and gray.
114
* Mappings are non exclusive. That is a given band can be assigned to no, some or all
115
* colour mappings. The constructor sets sensible defaults for band mappings but these can be
116
* overridden at run time using the setRedBandName,setGreenBandName,setBlueBandName and setGrayBandName
125
Please observe the following variable naming guidelines when editing this class:
127
In my opinion, clarity of code is more important than brevity, so variables should be given clear,
128
unambiguous names. Variables names should be written in mixed case, with a lowercase first letter.
129
Each variable name should include a scope resolution indicator and a type indicator, in the form:
131
[scope]+[name]+[type]
133
Where scope resolution indicators are:
135
- global vars and class members : [none]
136
- variables passed as parameters to a function/method: the
137
- variables declared locally in a method or function: my
142
int fooInt; //class var has no prefix
144
public void FooClass::fooMethod (int theBarInt) //function parameter prefixed by 'the'
147
int myLocalInt=0; //function members prefixed by 'my'
148
myLocalInt=fooInt+theBarInt;
152
Using this scope resolution naming scheme makes the origin of each variable unambiguous and the
153
code easy to read (especially by people who did not write it!).
155
The [name] part of the variable should be short and descriptive, usually a noun.
157
The [type] part of the variable should be the type class of the variable written out in full.
162
#ifndef QGSRASTERLAYER_H
163
#define QGSRASTERLAYER_H
169
#include <qvaluevector.h>
170
#include <qvaluelist.h>
172
#include "qgspoint.h"
173
#include "qgsmaplayer.h"
174
#include "qgscolortable.h"
175
#include "qgsrasterlayer.h"
177
#include <gdal_priv.h>
179
// Forward declarations
182
class QgsRasterLayerProperties;
184
class GDALRasterBand;
191
/** \brief The RasterBandStats struct is a container for statistics about a single
194
struct RasterBandStats
196
/** \brief The name of the band that these stats belong to. */
198
/** \brief The gdal band number (starts at 1)*/
200
/** \brief A flag to indicate whether this RasterBandStats struct
201
* is completely populated */
202
bool statsGatheredFlag;
203
/** \brief The minimum cell value in the raster band. NO_DATA values
204
* are ignored. This does not use the gdal GetMinimum function. */
206
/** \brief The maximum cell value in the raster band. NO_DATA values
207
* are ignored. This does not use the gdal GetMaximmum function. */
209
/** \brief The range is the distance between min & max. */
211
/** \brief The mean cell value for the band. NO_DATA values are excluded. */
213
/** \brief The sum of the squares. Used to calculate standard deviation. */
214
double sumSqrDevDouble;
215
/** \brief The standard deviation of the cell values. */
217
/** \brief The sum of all cells in the band. NO_DATA values are excluded. */
219
/** \brief The number of cells in the band. Equivalent to height x width.
220
* TODO: check if NO_DATA are excluded!*/
222
/** \brief A histogram storing the distribution of values within the raster. */
225
QgsColorTable colorTable;
228
/** \brief A vector containing one RasterBandStats struct per raster band in this raster layer.
229
* Note that while very RasterBandStats element will have the name and number of its associated
230
* band populated, any additional stats are calculated on a need to know basis.*/
231
typedef QValueVector<RasterBandStats> RasterStatsVector;
233
/** \brief The RasterViewPort describes the area of the raster layer that will be
234
* rendered during a draw operation.
236
struct RasterViewPort
238
/** \brief The offset from the left hand edge of the raster for the rectangle that will be drawn to screen.
239
* TODO Check this explanation is correc!*/
241
/** \brief The offset from the bottom edge of the raster for the rectangle that will be drawn to screen.
242
* TODO Check this explanation is correc!*/
244
/** \brief Lower left X dimension of clipped raster image in raster pixel space.
245
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
246
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
247
* whatever the screen coordinates are (e.g. a 600x800 display window) */
248
double clippedXMinDouble;
249
/** \brief Top Right X dimension of clipped raster image in raster pixel space.
250
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
251
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
252
* whatever the screen coordinates are (e.g. a 600x800 display window) */
253
double clippedXMaxDouble;
254
/** \brief Lower left Y dimension of clipped raster image in raster pixel space.
255
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
256
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
257
* whatever the screen coordinates are (e.g. a 600x800 display window) */
258
double clippedYMinDouble;
259
/** \brief Top Right X dimension of clipped raster image in raster pixel space.
260
* RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
261
* be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
262
* whatever the screen coordinates are (e.g. a 600x800 display window) */
263
double clippedYMaxDouble;
264
/** \brief Distance in pixels from clippedXMinDouble to clippedXMaxDouble. */
266
/** \brief Distance in pixels from clippedYMinDouble to clippedYMaxDouble */
267
int clippedHeightInt;
268
/** \brief Coordinate (in geographic coordinate system) of top left corner of the part of the raster that
269
* is to be rendered.*/
270
QgsPoint topLeftPoint;
271
/** \brief Coordinate (in geographic coordinate system) of bottom right corner of the part of the raster that
272
* is to be rendered.*/
273
QgsPoint bottomRightPoint;
274
/** \brief Distance in map units from left edge to right edge for the part of the raster that
275
* is to be rendered.*/
276
int drawableAreaXDimInt;
277
/** \brief Distance in map units from bottom edge to top edge for the part of the raster that
278
* is to be rendered.*/
279
int drawableAreaYDimInt;
282
/** \brief This struct is used to store pyramid info for the raster layer. */
285
/** \brief The pyramid level as implemented in gdal (level 2 is half orignal raster size etc) */
287
/** \brief XDimension for this pyramid layer */
289
/** \brief YDimension for this pyramid layer */
291
/** \brief Whether the pyramid layer has been built yet */
296
/** \brief A list containing one RasterPyramid struct per
297
* POTENTIAL pyramid layer. How this works is we divide the height
298
* and width of the raster by an incrementing number. As soon as the result
299
* of the division is <=256 we stop allowing RasterPyramid stracuts
300
* to be added to the list. Each time a RasterPyramid is created
301
* we will check to see if a pyramid matching these dimensions already exists
302
* in the raster layer, and if so mark the exists flag as true. */
304
typedef QValueList<RasterPyramid> RasterPyramidList;
306
/** \brief This typedef is used when the showProgress function is passed to gdal as a function
308
// typedef int (QgsRasterLayer::*showTextProgress)( double theProgressDouble,
309
// const char *theMessageCharArray,
313
/*! \class QgsRasterLayer
314
* \brief This class provides qgis with the ability to render raster datasets
315
* onto the mapcanvas..
318
class QgsRasterLayer : public QgsMapLayer
326
static void buildSupportedRasterFileFilter(QString & fileFilters);
327
static bool isSupportedRasterDriver(QString const &driverName);
328
/** This helper checks to see whether the filename appears to be a valid raster file name */
329
static bool isValidRasterFileName(QString theFileNameQString);
330
/** Overloaded version of the above function provided for convenience that takes a qstring pointer */
331
static bool isValidRasterFileName(QString * theFileNameQString);
334
// Non Static methods:
337
/** \brief This is the constructor for the RasterLayer class.
339
* The main tasks carried out by the constructor are:
341
* -Populate the RasterStatsVector with initial values for each band.
343
* -Calculate the layer extents
345
* -Determine whether the layer is gray, paletted or multiband.
347
* -Assign sensible defaults for the red,green, blue and gray bands.
351
QgsRasterLayer(QString path = 0, QString baseName = 0);
353
/** \brief The destuctor. */
357
/** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
358
void drawThumbnail(QPixmap * theQPixmap);
360
/** \brief Get an 8x8 pixmap of the colour palette. If the layer has no palette a white pixmap will be returned. */
361
QPixmap getPaletteAsPixmap();
363
/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn). */
364
void draw(QPainter * theQPainter, QgsRect * theViewExtent, QgsCoordinateTransform * theQgsCoordinateTransform, QPaintDevice* dst);
366
/** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */
367
void draw (QPainter * theQPainter, RasterViewPort * myRasterViewPort);
370
// Accessors for image height and width
372
/** \brief Accessor that returns the width of the (unclipped) raster */
373
const int getRasterXDim() {return rasterXDimInt;};
375
/** \brief Accessor that returns the height of the (unclipped) raster */
376
const int getRasterYDim() {return rasterYDimInt;};
379
// Accessor and mutator for no data double
381
/** \brief Accessor that returns the NO_DATA entry for this raster. */
382
const double getNoDataValue() {return noDataValueDouble;}
384
/** \brief Mutator that allows the NO_DATA entry for this raster to be overridden. */
385
void setNoDataValue(double theNoDataDouble) { noDataValueDouble=theNoDataDouble; return;};
388
// Accessor and mutator for invertHistogramFlag
390
/** \brief Accessor to find out whether the histogram should be inverted. */
391
bool getInvertHistogramFlag()
393
return invertHistogramFlag;
395
/** \brief Mutator to alter the state of the invert histogram flag. */
396
void setInvertHistogramFlag(bool theFlag)
398
invertHistogramFlag=theFlag;
401
// Accessor and mutator for stdDevsToPlotDouble
403
/** \brief Accessor to find out how many standard deviations are being plotted. */
404
double getStdDevsToPlot()
406
return stdDevsToPlotDouble;
408
/** \brief Mutator to alter the number of standard deviations that should be plotted. */
409
void setStdDevsToPlot(double theDouble)
411
stdDevsToPlotDouble = theDouble;
413
/** \brief Get the number of bands in this layer */
414
const unsigned int getBandCount()
416
return rasterStatsVector.size();
418
/** \brief Get RasterBandStats for a band given its number (read only) */
419
const RasterBandStats getRasterBandStats(int);
420
/** \brief Check whether a given band number has stats associated with it */
421
const bool hasStats(int theBandNoInt);
422
/** \brief Overloaded method that also returns stats for a band, but uses the band colour name
423
* Note this approach is not recommeneded because it is possible for two gdal raster
424
* bands to have the same name!
426
const RasterBandStats getRasterBandStats(QString);
427
/** \brief Get the number of a band given its name. Note this will be the rewritten name set
428
* up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
429
* If no matching band is found zero will be returned! */
430
const int getRasterBandNumber (QString theBandNameQString);
431
/** \brief Get the name of a band given its number. */
432
const QString getRasterBandName(int theBandNoInt);
433
/** \brief Find out whether a given band exists. */
434
bool hasBand(QString theBandName);
435
/** \brief accessor for transparency level. */
436
unsigned int getTransparency();
437
/** \brief Mutator for transparency level. Should be between 0 and 255 */
438
void setTransparency(int); //
439
/** \brief Call any inline image manipulation filters */
440
void filterLayer(QImage * theQImage);
441
/** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red colour). */
442
QString getRedBandName()
444
return redBandNameQString;
446
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red colour). */
447
void setRedBandName(QString theBandNameQString);
449
// Accessor and mutator for green band name
451
/** \brief Accessor for green band name mapping. */
452
QString getGreenBandName()
454
return greenBandNameQString;
456
/** \brief Mutator for green band name mapping. */
457
void setGreenBandName(QString theBandNameQString);
459
// Accessor and mutator for blue band name
461
/** \brief Accessor for blue band name mapping. */
462
QString getBlueBandName()
464
return blueBandNameQString;
466
/** \brief Mutator for blue band name mapping. */
467
void setBlueBandName(QString theBandNameQString);
469
// Accessor and mutator for gray band name
471
/** \brief Accessor for gray band name mapping. */
472
QString getGrayBandName()
474
return grayBandNameQString;
476
/** \brief Mutator for gray band name mapping. */
477
void setGrayBandName(QString theBandNameQString);
479
// Accessor and mutator for showDebugOverlayFlag
481
/** \brief Accessor for a flag that determines whether to show some debug info on the image. */
482
bool getShowDebugOverlayFlag()
484
return showDebugOverlayFlag;
486
/** \brief Mutator for a flag that determines whether to show some debug info on the image. */
487
void setShowDebugOverlayFlag(bool theFlag)
489
showDebugOverlayFlag=theFlag;
492
// Accessor and mutator for min and max red
494
/** \brief Accessor for minimum clipping range for red.
496
* The clipping range can have different interpretations - it can either be used to perform
497
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
498
* that falls outside the clipping range.*/
499
double getMinRedDouble()
503
/** \brief Mutator for minimum clipping range for red.
505
* The clipping range can have different interpretations - it can either be used to perform
506
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
507
* that falls outside the clipping range.*/
508
void setMinRedDouble(double theDouble)
510
minRedDouble=theDouble;
512
/** \brief Accessor for maximum clipping range for red.
514
* The clipping range can have different interpretations - it can either be used to perform
515
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
516
* that falls outside the clipping range.*/
517
double getMaxRedDouble()
521
/** \brief Mutator for maximum clipping range for red.
523
* The clipping range can have different interpretations - it can either be used to perform
524
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
525
* that falls outside the clipping range.*/
526
void setMaxRedDouble(double theDouble)
528
maxRedDouble=theDouble;
531
// Accessor and mutator for min and max green
533
/** \brief Accessor for minimum clipping range for green.
535
* The clipping range can have different interpretations - it can either be used to perform
536
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
537
* that falls outside the clipping range.*/
538
double getMinGreenDouble()
540
return minGreenDouble;
542
/** \brief Mutator for minimum clipping range for green.
544
* The clipping range can have different interpretations - it can either be used to perform
545
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
546
* that falls outside the clipping range.*/
547
void setMinGreenDouble(double theDouble)
549
minGreenDouble=theDouble;
551
/** \brief Accessor for maximum clipping range for green.
553
* The clipping range can have different interpretations - it can either be used to perform
554
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
555
* that falls outside the clipping range.*/
556
double getMaxGreenDouble()
558
return maxGreenDouble;
560
/** \brief Mutator for maximum clipping range for green.
562
* The clipping range can have different interpretations - it can either be used to perform
563
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
564
* that falls outside the clipping range.*/
565
void setMaxGreenDouble(double theDouble)
567
maxGreenDouble=theDouble;
570
// Accessor and mutator for min and max blue
572
/** \brief Accessor for minimum clipping range for blue.
574
* The clipping range can have different interpretations - it can either be used to perform
575
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
576
* that falls outside the clipping range.*/
578
double getMinBlueDouble()
580
return minBlueDouble;
582
/** \brief Mutator for minimum clipping range for blue.
584
* The clipping range can have different interpretations - it can either be used to perform
585
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
586
* that falls outside the clipping range.*/
587
void setMinBlueDouble(double theDouble)
589
minBlueDouble=theDouble;
591
/** \brief Accessor for maximum clipping range for blue.
593
* The clipping range can have different interpretations - it can either be used to perform
594
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
595
* that falls outside the clipping range.*/
596
double getMaxBlueDouble()
598
return maxBlueDouble;
600
/** \brief Mutator for maximum clipping range for blue.
602
* The clipping range can have different interpretations - it can either be used to perform
603
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
604
* that falls outside the clipping range.*/
605
void setMaxBlueDouble(double theDouble)
607
maxBlueDouble=theDouble;
610
// Accessor and mutator for min and max gray
612
/** \brief Accessor for minimum clipping range for gray.
614
* The clipping range can have different interpretations - it can either be used to perform
615
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
616
* that falls outside the clipping range.*/
617
double getMinGrayDouble()
619
return minGrayDouble;
621
/** \brief Mutator for minimum clipping range for gray.
623
* The clipping range can have different interpretations - it can either be used to perform
624
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
625
* that falls outside the clipping range.*/
626
void setMinGrayDouble(double theDouble)
628
minGrayDouble=theDouble;
630
/** \brief Accessor for maximum clipping range for gray.
632
* The clipping range can have different interpretations - it can either be used to perform
633
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
634
* that falls outside the clipping range.*/
635
double getMaxGrayDouble()
637
return maxGrayDouble;
639
/** \brief Mutator for maximum clipping range for gray.
641
* The clipping range can have different interpretations - it can either be used to perform
642
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
643
* that falls outside the clipping range.*/
644
void setMaxGrayDouble(double theDouble)
646
maxGrayDouble=theDouble;
649
/** \brief This enumerator describes the types of histogram scaling algorithms that can be used. */
650
enum COLOR_SCALING_ALGORITHM
652
STRETCH_TO_MINMAX, //linear histogram stretch
653
STRETCH_AND_CLIP_TO_MINMAX,
655
} colorScalingAlgorithm;
657
// Accessor and mutator for the color scaling algorithm
659
/** \brief Accessor for colour scaling algorithm. */
660
COLOR_SCALING_ALGORITHM getColorScalingAlgorithm()
662
return colorScalingAlgorithm;
664
/** \brief Mutator for color scaling algorithm. */
665
void setColorScalingAlgorithm(COLOR_SCALING_ALGORITHM theAlgorithm)
667
colorScalingAlgorithm=theAlgorithm;
670
/** \brief This enumerator describes the types of histogram colour ramping that can be used. */
671
enum COLOR_RAMPING_TYPE
674
FREAK_OUT //it will scare your granny!
677
// Accessor and mutator for the color ramping type
679
/** \brief Accessor for colour ramping type. */
680
COLOR_RAMPING_TYPE getColorRampingType()
682
return colorRampingType;
684
/** \brief Mutator for color scaling algorithm. */
685
void setColorRampingType(COLOR_RAMPING_TYPE theRamping)
687
colorRampingType=theRamping;
690
/** \brief This enumerator describes the different kinds of drawing we can do. */
693
SINGLE_BAND_GRAY, // a "Gray" or "Undefined" layer drawn as a range of gray colors
694
SINGLE_BAND_PSEUDO_COLOR,// a "Gray" or "Undefined" layer drawn using a pseudocolor algorithm
695
PALETTED_COLOR, //a "Palette" image drawn using color table
696
PALETTED_SINGLE_BAND_GRAY,// a "Palette" layer drawn in gray scale (using only one of the color components)
697
PALETTED_SINGLE_BAND_PSEUDO_COLOR, // a "Palette" layer having only one of its color components rendered as psuedo color
698
PALETTED_MULTI_BAND_COLOR, // a "Palette" image is decomposed to 3 channels (RGB) and drawn
700
MULTI_BAND_SINGLE_BAND_GRAY, // a layer containing 2 or more bands, but using only one band to produce a grayscale image
701
MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR, //a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
702
MULTI_BAND_COLOR //a layer containing 2 or more bands, mapped to the three RGBcolors. In the case of a multiband with only two bands, one band will have to be mapped to more than one color
705
// Accessor and mutator for drawing style.
707
/** \brief Accessor for drawing style. */
708
DRAWING_STYLE getDrawingStyle() {return drawingStyle;};
709
/** \brief Returns a string representation of drawing style.
711
* Implementaed mainly for serialisation / deserialisation of settings to xml.
712
* NOTE: May be deprecated in the future!. Use alternate implementation above rather.
714
QString getDrawingStyleAsQString();
715
/** \brief Mutator for drawing style. */
716
void setDrawingStyle(DRAWING_STYLE theDrawingStyle) {drawingStyle=theDrawingStyle;};
717
/** \brief Overloaded version of the above function for convenience when restoring from xml.
719
* Implementaed mainly for serialisation / deserialisation of settings to xml.
720
* NOTE: May be deprecated in the future! Use alternate implementation above rather.
722
void setDrawingStyle(QString theDrawingStyleQString);
727
/** \brief This enumerator describes the type of raster layer. */
728
enum RASTER_LAYER_TYPE
735
//accessor and for raster layer type (READ ONLY)
737
/** \brief Accessor for raster layer type (which is a read only property) */
738
RASTER_LAYER_TYPE getRasterLayerType() { return rasterLayerType; };
739
/** \brief Accessor for hasPyramidsFlag (READ ONLY) */
740
bool getHasPyramidsFlag() {return hasPyramidsFlag;};
742
/** \brief Get a legend image for this layer. */
743
QPixmap getLegendQPixmap();
744
/** \brief Overloaded version of above function that can print layer name onto legend. */
745
QPixmap getLegendQPixmap(bool);
746
/** \brief Similar to above but returns a pointer. Implemented for qgsmaplayer interface.
747
* Always overlays legend name!*/
748
QPixmap * legendPixmap();
750
/** tailor the right-click context menu with raster layer only stuff
752
@note called by QgsMapLayer::initContextMenu();
754
void initContextMenu_(QgisApp *);
756
/** \brief Accessor for the superclass's popmenu var - implements the pure virtual funtion. */
757
QPopupMenu *contextMenu();
758
/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
759
void triggerRepaint();
760
/** \brief Obtain GDAL Metadata for this layer */
761
QString getMetadata();
762
/** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
763
* POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
764
* ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
766
RasterPyramidList buildRasterPyramidList();
767
/** \brief Helper method to retrieve the nth pyramid layer struct from the PyramidList.
768
* If the nth layer does not exist, NULL will be returned. */
769
// RasterPyramid getRasterPyramid(int thePyramidNo);
771
/**Currently returns always false*/
772
bool isEditable() const;
777
/** sets whether this is in overview or not */
778
void inOverview( bool );
780
/** \brief Slot called when the popup menu transparency slider has been moved.*/
781
void popupTransparencySliderMoved(int);
783
/** \brief Create gdal pyramid overviews for this layer.
784
* This will speed up performance at the expense of hard drive space.
785
* Also, write access to the file is required. If no paramter is passed in
786
* it will default to nearest neighbor resampling. */
787
void buildPyramids(RasterPyramidList,QString theResamplingMethod="NEAREST");
788
/** \brief Used at the moment by the above function but hopefully will later
789
be useable by any operation that needs to notify the user of its progress. */
791
int showTextProgress( double theProgressDouble,
792
const char *theMessageCharArray,
796
/** \brief This method is called when the properties for this layer needs to be modified.
797
* invokes an instance of the QgsRasterLayerProperties dialog box.*/
798
/* virtual */ void showLayerProperties();
803
/** reads vector layer specific state from project file DOM node.
807
Called by QgsMapLayer::readXML().
810
/* virtual */ bool readXML_( QDomNode & layer_node );
814
/** write vector layer specific state to project file DOM node.
818
Called by QgsMapLayer::writeXML().
821
/* virtual */ bool writeXML_( QDomNode & layer_node, QDomDocument & doc );
829
/** \brief Paint debug information onto the output image. */
830
void showDebugOverlay(QPainter * theQPainter, RasterViewPort * theRasterViewPort);
836
/** \brief Drawing routine for single band grayscale image. */
837
void drawSingleBandGray(QPainter * theQPainter, RasterViewPort * theRasterViewPort,int theBandNoInt);
839
/** \brief Drawing routine for single band grayscale image, rendered in pseudocolor. */
840
void drawSingleBandPseudoColor(QPainter * theQPainter, RasterViewPort * theRasterViewPort,int theBandNoInt);
847
/** \brief Drawing routine for paletted image, rendered as a single band image in color. */
848
void drawPalettedSingleBandColor(QPainter * theQPainter,
849
RasterViewPort * theRasterViewPort,
852
/** \brief Drawing routine for paletted image, rendered as a single band image in grayscale. */
853
void drawPalettedSingleBandGray(QPainter * theQPainter,
854
RasterViewPort * theRasterViewPort,
856
QString theColorQString);
858
/** \brief Drawing routine for paletted image, rendered as a single band image in pseudocolor. */
859
void drawPalettedSingleBandPseudoColor(QPainter * theQPainter,
860
RasterViewPort * theRasterViewPort,
862
QString theColorQString);
864
/** \brief Drawing routine for paletted multiband image. */
865
void drawPalettedMultiBandColor(QPainter * theQPainter,
866
RasterViewPort * theRasterViewPort,
873
/** \brief Drawing routine for multiband image, rendered as a single band image in grayscale. */
874
void drawMultiBandSingleBandGray(QPainter * theQPainter,
875
RasterViewPort * theRasterViewPort,
878
/** \brief Drawing routine for multiband image, rendered as a single band image in pseudocolor. */
879
void drawMultiBandSingleBandPseudoColor(QPainter * theQPainter,
880
RasterViewPort * theRasterViewPort,
883
/** \brief Drawing routine for multiband image */
884
void drawMultiBandColor(QPainter * theQPainter, RasterViewPort * theRasterViewPort);
886
/** \brief Read color table from GDAL raster band */
887
void readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *theColorTable );
889
/** \brief Allocate memory and load data to that allocated memory, data type is the same
890
* as raster band. The memory must be released later!
891
* \return pointer to the memory
893
void *readData ( GDALRasterBand *gdalBand, RasterViewPort *viewPort );
895
/** \brief Read a raster value on given position from memory block created by readData()
896
* \param index index in memory block
898
inline double readValue ( void *data, GDALDataType type, int index );
900
/** \brief Color table
902
* \return pointer to color table
904
QgsColorTable *colorTable ( int theBandNoInt );
907
Load the given raster file
909
@returns true if successfully read file
913
Called from ctor if a raster image given there
915
bool readFile( QString const & fileName );
918
// Private member vars
920
/** \brief Raster width. */
922
/** \brief Raster Height. */
924
/** \brief Cell value representing no data. e.g. -9999 */
925
double noDataValueDouble;
926
/** \brief Flag to indicate whether debug infor overlay should be rendered onto the raster. */
927
bool showDebugOverlayFlag;
928
/** \brief Pointer to the gdaldataset. */
929
GDALDataset * gdalDataset;
930
/** \brief Values for mapping pixel to world coordinates. */
931
double adfGeoTransform[6];
932
/** \brief Flag indicating whether the histogram should be inverted or not. */
933
bool invertHistogramFlag;
934
/** \brief Number of stddev to plot (0) to ignore. Not applicable to all layer types. */
935
double stdDevsToPlotDouble;
936
/** \brief A collection of stats - one for each band in the layer.
937
* The typedef for this is defined above before class declaration
939
RasterStatsVector rasterStatsVector;
940
/** \brief Transparency level for this layer should be 0-255. */
941
unsigned int transparencyLevelInt;
942
/** \brief The band to be associated with the color red - usually 1. */
943
QString redBandNameQString;
944
/** \brief The band to be associated with the color green - usually 2. */
945
QString greenBandNameQString;
946
/** \brief The band to be associated with the color blue - usually 3. */
947
QString blueBandNameQString;
948
/** \brief The band to be associated with the grayscale only ouput - usually 1. */
949
QString grayBandNameQString;
950
/** \brief Minimum red value - used in scaling procedure. */
952
/** \brief Maximum red value - used in scaling procedure. */
954
/** \brief Minimum green value - used in scaling procedure. */
955
double minGreenDouble;
956
/** \brief Maximum green value - used in scaling procedure. */
957
double maxGreenDouble;
958
/** \brief Minimum blue value - used in scaling procedure. */
959
double minBlueDouble;
960
/** \brief Maximum blue value - used in scaling procedure. */
961
double maxBlueDouble;
962
/** \brief Minimum gray value - used in scaling procedure. */
963
double minGrayDouble;
964
/** \brief Maximum gray value - used in scaling procedure. */
965
double maxGrayDouble;
966
/** \brief Whether this raster has overviews / pyramids or not */
967
bool hasPyramidsFlag;
968
/** \brief These are two little icons used to indicate whether a
969
* layer has pyramds bult or not. */
970
QPixmap mPyramidPixmap, mNoPyramidPixmap;
971
/** \brief This list holds a series of RasterPyramid structs
972
* which store infomation for each potential pyramid level for this raster.*/
973
RasterPyramidList mPyramidList;
974
//Transparency slider for popup menu
975
QSlider * mTransparencySlider;
976
//we need to do the tr() stuff outside of the main drawing loops becauses tr() is a
977
//time consuming operation nd we dont want to do it in the loop!
978
QString redTranslatedQString;
979
QString greenTranslatedQString;
980
QString blueTranslatedQString;
982
/* raster properties dialog
984
@todo XXX should consider generalizing this
986
QgsRasterLayerProperties * mLayerProperties;