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 6393 2007-01-04 08:13:13Z g_j_m $ */
19
/** \file qgsrasterlayer.h
20
* \brief This class provides qgis with the ability to render raster datasets
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
173
#include "qgspoint.h"
174
#include "qgsmaplayer.h"
175
#include "qgscolortable.h"
176
#include "qgsrasterlayer.h"
177
#include "qgsrasterbandstats.h"
178
#include "qgsrasterpyramid.h"
182
* New includes that will convert this class to a data provider interface
187
#include "qgsrasterdataprovider.h"
194
#include <gdal_priv.h>
196
// Forward declarations
199
class QgsRasterLayerProperties;
201
class GDALRasterBand;
212
/*! \class QgsRasterLayer
213
* \brief This class provides qgis with the ability to render raster datasets
214
* onto the mapcanvas..
217
class QgsRasterLayer : public QgsMapLayer
225
static void buildSupportedRasterFileFilter(QString & fileFilters);
226
static bool isSupportedRasterDriver(QString const &driverName);
228
/** This helper checks to see whether the filename appears to be a valid
230
static bool isValidRasterFileName(QString const & theFileNameQString);
233
// Non Static methods:
236
/** \brief This is the constructor for the RasterLayer class.
238
* The main tasks carried out by the constructor are:
240
* -Populate the RasterStatsVector with initial values for each band.
242
* -Calculate the layer extents
244
* -Determine whether the layer is gray, paletted or multiband.
246
* -Assign sensible defaults for the red,green, blue and gray bands.
250
QgsRasterLayer(QString const & path = QString::null,
251
QString const & baseName = QString::null);
253
/** \brief The destuctor. */
256
/** \brief A vector containing one RasterBandStats struct per raster band in this raster layer.
257
* Note that while very RasterBandStats element will have the name and number of its associated
258
* band populated, any additional stats are calculated on a need to know basis.*/
259
typedef QVector<QgsRasterBandStats> RasterStatsVector;
262
/** \brief A list containing one RasterPyramid struct per
263
* POTENTIAL pyramid layer. How this works is we divide the height
264
* and width of the raster by an incrementing number. As soon as the result
265
* of the division is <=256 we stop allowing RasterPyramid stracuts
266
* to be added to the list. Each time a RasterPyramid is created
267
* we will check to see if a pyramid matching these dimensions already exists
268
* in the raster layer, and if so mark the exists flag as true. */
270
typedef QList<QgsRasterPyramid> RasterPyramidList;
272
/** \brief This typedef is used when the showProgress function is passed to gdal as a function
274
// typedef int (QgsRasterLayer::*showTextProgress)( double theProgressDouble,
275
// const char *theMessageCharArray,
278
/** \brief Identify raster value(s) found on the point position
280
* \param point[in] a coordinate in the CRS of this layer.
282
void identify(const QgsPoint& point, std::map<QString,QString>& results);
284
/** \brief Identify arbitrary details from the WMS server found on the point position
286
* \param point[in] an image pixel coordinate in the last requested extent of layer.
288
* \return A text document containing the return from the WMS server
290
* \note The arbitraryness of the returned document is enforced by WMS standards
291
* up to at least v1.3.0
293
QString identifyAsText(const QgsPoint& point);
295
/** \brief Query gdal to find out the WKT projection string for this layer. This implements the virtual method of the same name defined in QgsMapLayer*/
296
QString getProjectionWKT();
298
/** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
299
void drawThumbnail(QPixmap * theQPixmap);
301
/** \brief Get an 8x8 pixmap of the colour palette. If the layer has no palette a white pixmap will be returned. */
302
QPixmap getPaletteAsPixmap();
304
/** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn).
306
\param drawingToEditingCanvas Are we drawing to an editable canvas?
307
currently not used, but retain to be similar to
308
the QgsVectorLayer interface
310
bool draw(QPainter * theQPainter,
311
QgsRect * theViewExtent,
312
QgsMapToPixel * theQgsMapToPixel,
313
bool drawingToEditingCanvas);
315
/** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */
316
void draw(QPainter * theQPainter,
317
QgsRasterViewPort * myRasterViewPort,
318
QgsMapToPixel * theQgsMapToPixel = 0);
321
// Accessors for image height and width
323
/** \brief Accessor that returns the width of the (unclipped) raster */
324
const int getRasterXDim() {return rasterXDimInt;};
326
/** \brief Accessor that returns the height of the (unclipped) raster */
327
const int getRasterYDim() {return rasterYDimInt;};
330
// Accessor and mutator for no data double
332
/** \brief Accessor that returns the NO_DATA entry for this raster. */
333
const double getNoDataValue() {return noDataValueDouble;}
335
/** \brief Mutator that allows the NO_DATA entry for this raster to be overridden. */
336
void setNoDataValue(double theNoDataDouble) { noDataValueDouble=theNoDataDouble; return;};
339
// Accessor and mutator for invertHistogramFlag
341
/** \brief Accessor to find out whether the histogram should be inverted. */
342
bool getInvertHistogramFlag()
344
return invertHistogramFlag;
346
/** \brief Mutator to alter the state of the invert histogram flag. */
347
void setInvertHistogramFlag(bool theFlag)
349
invertHistogramFlag=theFlag;
352
// Accessor and mutator for stdDevsToPlotDouble
354
/** \brief Accessor to find out how many standard deviations are being plotted. */
355
double getStdDevsToPlot()
357
return stdDevsToPlotDouble;
359
/** \brief Mutator to alter the number of standard deviations that should be plotted. */
360
void setStdDevsToPlot(double theDouble)
362
stdDevsToPlotDouble = theDouble;
364
/** \brief Get the number of bands in this layer */
365
const unsigned int getBandCount()
367
return rasterStatsVector.size();
369
/** \brief Get RasterBandStats for a band given its number (read only) */
370
const QgsRasterBandStats getRasterBandStats(int);
371
/** \brief Check whether a given band number has stats associated with it */
372
const bool hasStats(int theBandNoInt);
373
/** \brief Overloaded method that also returns stats for a band, but uses the band colour name
374
* Note this approach is not recommeneded because it is possible for two gdal raster
375
* bands to have the same name!
377
const QgsRasterBandStats getRasterBandStats(QString const &);
378
/** \brief Get the number of a band given its name. Note this will be the rewritten name set
379
* up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
380
* If no matching band is found zero will be returned! */
381
const int getRasterBandNumber (QString const & theBandNameQString);
382
/** \brief Get the name of a band given its number. */
383
const QString getRasterBandName(int theBandNoInt);
384
/** \brief Find out whether a given band exists. */
385
bool hasBand(QString const & theBandName);
386
/** \brief accessor for transparency level. */
387
unsigned int getTransparency();
388
/** \brief Call any inline image manipulation filters */
389
void filterLayer(QImage * theQImage);
390
/** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red colour). */
391
QString getRedBandName()
393
return redBandNameQString;
395
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red colour). */
396
void setRedBandName(QString const & theBandNameQString);
398
// Accessor and mutator for green band name
400
/** \brief Accessor for green band name mapping. */
401
QString getGreenBandName()
403
return greenBandNameQString;
405
/** \brief Mutator for green band name mapping. */
406
void setGreenBandName(QString const & theBandNameQString);
408
// Accessor and mutator for blue band name
410
/** \brief Accessor for blue band name mapping. */
411
QString getBlueBandName()
413
return blueBandNameQString;
415
/** \brief Mutator for blue band name mapping. */
416
void setBlueBandName(QString const & theBandNameQString);
418
// Accessor and mutator for transparent band name
420
/** \brief Accessor for transparent band name mapping. */
421
QString getTransparentBandName()
423
return transparentBandNameQString;
425
/** \brief Mutator for transparent band name mapping. */
426
void setTransparentBandName(QString const & theBandNameQString);
428
// Accessor and mutator for gray band name
430
/** \brief Accessor for gray band name mapping. */
431
QString getGrayBandName()
433
return grayBandNameQString;
435
/** \brief Mutator for gray band name mapping. */
436
void setGrayBandName(QString const & theBandNameQString);
438
// Accessor and mutator for showDebugOverlayFlag
440
/** \brief Accessor for a flag that determines whether to show some debug info on the image. */
441
bool getShowDebugOverlayFlag()
443
return showDebugOverlayFlag;
445
/** \brief Mutator for a flag that determines whether to show some debug info on the image. */
446
void setShowDebugOverlayFlag(bool theFlag)
448
showDebugOverlayFlag=theFlag;
451
// Accessor and mutator for min and max red
453
/** \brief Accessor for minimum clipping range for red.
455
* The clipping range can have different interpretations - it can either be used to perform
456
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
457
* that falls outside the clipping range.*/
458
double getMinRedDouble()
462
/** \brief Mutator for minimum clipping range for red.
464
* The clipping range can have different interpretations - it can either be used to perform
465
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
466
* that falls outside the clipping range.*/
467
void setMinRedDouble(double theDouble)
469
minRedDouble=theDouble;
471
/** \brief Accessor for maximum clipping range for red.
473
* The clipping range can have different interpretations - it can either be used to perform
474
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
475
* that falls outside the clipping range.*/
476
double getMaxRedDouble()
480
/** \brief Mutator for maximum clipping range for red.
482
* The clipping range can have different interpretations - it can either be used to perform
483
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
484
* that falls outside the clipping range.*/
485
void setMaxRedDouble(double theDouble)
487
maxRedDouble=theDouble;
490
// Accessor and mutator for min and max green
492
/** \brief Accessor for minimum clipping range for green.
494
* The clipping range can have different interpretations - it can either be used to perform
495
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
496
* that falls outside the clipping range.*/
497
double getMinGreenDouble()
499
return minGreenDouble;
501
/** \brief Mutator for minimum clipping range for green.
503
* The clipping range can have different interpretations - it can either be used to perform
504
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
505
* that falls outside the clipping range.*/
506
void setMinGreenDouble(double theDouble)
508
minGreenDouble=theDouble;
510
/** \brief Accessor for maximum clipping range for green.
512
* The clipping range can have different interpretations - it can either be used to perform
513
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
514
* that falls outside the clipping range.*/
515
double getMaxGreenDouble()
517
return maxGreenDouble;
519
/** \brief Mutator for maximum clipping range for green.
521
* The clipping range can have different interpretations - it can either be used to perform
522
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
523
* that falls outside the clipping range.*/
524
void setMaxGreenDouble(double theDouble)
526
maxGreenDouble=theDouble;
529
// Accessor and mutator for min and max blue
531
/** \brief Accessor for minimum clipping range for blue.
533
* The clipping range can have different interpretations - it can either be used to perform
534
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
535
* that falls outside the clipping range.*/
537
double getMinBlueDouble()
539
return minBlueDouble;
541
/** \brief Mutator for minimum clipping range for blue.
543
* The clipping range can have different interpretations - it can either be used to perform
544
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
545
* that falls outside the clipping range.*/
546
void setMinBlueDouble(double theDouble)
548
minBlueDouble=theDouble;
550
/** \brief Accessor for maximum clipping range for blue.
552
* The clipping range can have different interpretations - it can either be used to perform
553
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
554
* that falls outside the clipping range.*/
555
double getMaxBlueDouble()
557
return maxBlueDouble;
559
/** \brief Mutator for maximum clipping range for blue.
561
* The clipping range can have different interpretations - it can either be used to perform
562
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
563
* that falls outside the clipping range.*/
564
void setMaxBlueDouble(double theDouble)
566
maxBlueDouble=theDouble;
569
// Accessor and mutator for min and max gray
571
/** \brief Accessor for minimum clipping range for gray.
573
* The clipping range can have different interpretations - it can either be used to perform
574
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
575
* that falls outside the clipping range.*/
576
double getMinGrayDouble()
578
return minGrayDouble;
580
/** \brief Mutator for minimum clipping range for gray.
582
* The clipping range can have different interpretations - it can either be used to perform
583
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
584
* that falls outside the clipping range.*/
585
void setMinGrayDouble(double theDouble)
587
minGrayDouble=theDouble;
589
/** \brief Accessor for maximum clipping range for gray.
591
* The clipping range can have different interpretations - it can either be used to perform
592
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
593
* that falls outside the clipping range.*/
594
double getMaxGrayDouble()
596
return maxGrayDouble;
598
/** \brief Mutator for maximum clipping range for gray.
600
* The clipping range can have different interpretations - it can either be used to perform
601
* a histogram stretch between the minimum and maximum clipping values, or to exclude data
602
* that falls outside the clipping range.*/
603
void setMaxGrayDouble(double theDouble)
605
maxGrayDouble=theDouble;
608
/** \brief This enumerator describes the types of histogram scaling algorithms that can be used. */
609
enum COLOR_SCALING_ALGORITHM
611
STRETCH_TO_MINMAX, //linear histogram stretch
612
STRETCH_AND_CLIP_TO_MINMAX,
614
} colorScalingAlgorithm;
616
// Accessor and mutator for the color scaling algorithm
618
/** \brief Accessor for colour scaling algorithm. */
619
COLOR_SCALING_ALGORITHM getColorScalingAlgorithm()
621
return colorScalingAlgorithm;
623
/** \brief Mutator for color scaling algorithm. */
624
void setColorScalingAlgorithm(COLOR_SCALING_ALGORITHM theAlgorithm)
626
colorScalingAlgorithm=theAlgorithm;
629
/** \brief This enumerator describes the types of histogram colour ramping that can be used. */
630
enum COLOR_RAMPING_TYPE
633
FREAK_OUT //it will scare your granny!
636
// Accessor and mutator for the color ramping type
638
/** \brief Accessor for colour ramping type. */
639
COLOR_RAMPING_TYPE getColorRampingType()
641
return colorRampingType;
643
/** \brief Mutator for color scaling algorithm. */
644
void setColorRampingType(COLOR_RAMPING_TYPE theRamping)
646
colorRampingType=theRamping;
649
/** \brief This enumerator describes the different kinds of drawing we can do. */
652
SINGLE_BAND_GRAY, // a "Gray" or "Undefined" layer drawn as a range of gray colors
653
SINGLE_BAND_PSEUDO_COLOR,// a "Gray" or "Undefined" layer drawn using a pseudocolor algorithm
654
PALETTED_COLOR, //a "Palette" image drawn using color table
655
PALETTED_SINGLE_BAND_GRAY,// a "Palette" layer drawn in gray scale (using only one of the color components)
656
PALETTED_SINGLE_BAND_PSEUDO_COLOR, // a "Palette" layer having only one of its color components rendered as psuedo color
657
PALETTED_MULTI_BAND_COLOR, // a "Palette" image is decomposed to 3 channels (RGB) and drawn
659
MULTI_BAND_SINGLE_BAND_GRAY, // a layer containing 2 or more bands, but using only one band to produce a grayscale image
660
MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR, //a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
661
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
664
// Accessor and mutator for drawing style.
666
/** \brief Accessor for drawing style. */
667
DRAWING_STYLE getDrawingStyle() {return drawingStyle;};
668
/** \brief Returns a string representation of drawing style.
670
* Implementaed mainly for serialisation / deserialisation of settings to xml.
671
* NOTE: May be deprecated in the future!. Use alternate implementation above rather.
673
QString getDrawingStyleAsQString();
674
/** \brief Mutator for drawing style. */
675
void setDrawingStyle(DRAWING_STYLE const & theDrawingStyle) {drawingStyle=theDrawingStyle;};
676
/** \brief Overloaded version of the above function for convenience when restoring from xml.
678
* Implementaed mainly for serialisation / deserialisation of settings to xml.
679
* NOTE: May be deprecated in the future! Use alternate implementation above rather.
681
void setDrawingStyle(QString const & theDrawingStyleQString);
686
/** \brief This enumerator describes the type of raster layer. */
687
enum RASTER_LAYER_TYPE
694
//accessor and for raster layer type (READ ONLY)
696
/** \brief Accessor for raster layer type (which is a read only property) */
697
RASTER_LAYER_TYPE getRasterLayerType() { return rasterLayerType; };
698
/** \brief Accessor for hasPyramidsFlag (READ ONLY) */
699
bool getHasPyramidsFlag() {return hasPyramidsFlag;};
701
/** \brief Get a legend image for this layer. */
702
QPixmap getLegendQPixmap();
703
/** \brief Overloaded version of above function that can print layer name onto legend. */
704
QPixmap getLegendQPixmap(bool);
706
/** \brief Use this method when you want an annotated legend suitable for print output etc.
707
* @param int theLabelCountInt Number of vertical labels to display (defaults to 3)
709
QPixmap getDetailedLegendQPixmap(int theLabelCount);
712
* Returns the sublayers of this layer
714
* (Useful for providers that manage their own layers, such as WMS)
717
QStringList subLayers() const;
720
* Reorders the *previously selected* sublayers of this layer from bottom to top
722
* (Useful for providers that manage their own layers, such as WMS)
725
virtual void setLayerOrder(QStringList const & layers);
728
* Set the visibility of the given sublayer name
730
virtual void setSubLayerVisibility(QString const & name, bool vis);
732
/** tailor the right-click context menu with raster layer only stuff
734
@note called by QgsMapLayer::initContextMenu();
736
void initContextMenu_(QgisApp *);
738
/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
739
void triggerRepaint();
740
/** \brief Obtain GDAL Metadata for this layer */
741
QString getMetadata();
742
/** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
743
* POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
744
* ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
746
RasterPyramidList buildRasterPyramidList();
747
/** \brief Helper method to retrieve the nth pyramid layer struct from the PyramidList.
748
* If the nth layer does not exist, NULL will be returned. */
749
// RasterPyramid getRasterPyramid(int thePyramidNo);
751
/**Currently returns always false*/
752
bool isEditable() const;
754
/** Return time stamp for given file name */
755
static QDateTime lastModified ( QString const & name );
757
/**Returns the path to an icon which characterises the type of layer*/
758
QString layerTypeIconPath();
760
/**Refresh the symbology part of the legend
761
by adding a child item to mLegendSymbologyGroupParent*/
762
void refreshLegend();
764
/**Copies the symbology settings from another layer. Returns true in case of success*/
765
bool copySymbologySettings(const QgsMapLayer& other) {return false;} //todo
767
bool isSymbologyCompatible(const QgsMapLayer& other) const {return false;} //todo
770
* If an operation returns 0 (e.g. draw()), this function
771
* returns the text of the error associated with the failure.
772
* Interactive users of this provider can then, for example,
773
* call a QMessageBox to display the contents.
775
QString errorCaptionString();
778
* If an operation returns 0 (e.g. draw()), this function
779
* returns the text of the error associated with the failure.
780
* Interactive users of this provider can then, for example,
781
* call a QMessageBox to display the contents.
783
QString errorString();
785
/** Returns the data provider
787
* \retval 0 if not using the data provider model (i.e. directly using GDAL)
789
QgsRasterDataProvider* getDataProvider();
791
/** Returns the data provider in a const-correct manner
793
* \retval 0 if not using the data provider model (i.e. directly using GDAL)
795
const QgsRasterDataProvider* getDataProvider() const;
800
/** \brief Mutator for transparency level. Should be between 0 and 255 */
801
void setTransparency(unsigned int);
803
* Convert this raster to another format
805
//void const convertTo();
807
* Mainly inteded for use in propogating progress updates from gdal up to the parent app.
809
void updateProgress(int,int);
811
/** sets whether this is in overview or not */
812
void inOverview( bool );
814
/** \brief Slot called when the popup menu transparency slider has been moved.*/
815
void popupTransparencySliderMoved(int);
817
/** \brief Create gdal pyramid overviews for this layer.
818
* This will speed up performance at the expense of hard drive space.
819
* Also, write access to the file is required. If no paramter is passed in
820
* it will default to nearest neighbor resampling. */
821
void buildPyramids(RasterPyramidList const &,
822
QString const & theResamplingMethod="NEAREST");
823
/** \brief Used at the moment by the above function but hopefully will later
824
be useable by any operation that needs to notify the user of its progress. */
826
int showTextProgress( double theProgressDouble,
827
const char *theMessageCharArray,
831
/** \brief This method is called when the properties for this layer needs to be modified.
832
* invokes an instance of the QgsRasterLayerProperties dialog box.*/
833
/* virtual */ void showLayerProperties();
835
/** Populate the histogram vector for a given layer
836
* @param theBandNoInt - which band to compute the histogram for
837
* @param theBinCountInt - how many 'bins' to categorise the data into
838
* @param theIgnoreOutOfRangeFlag - whether to ignore values that are out of range (default=true)
839
* @param theThoroughBandScanFlag - whether to visit each cell when computing the histogram (default=false)
841
void populateHistogram(int theBandNoInt,
842
int theBinCountInt=256,
843
bool theIgnoreOutOfRangeFlag=true,
844
bool theThoroughBandScanFlag=false);
846
/** \brief Color table
848
* \return pointer to color table
850
QgsColorTable *colorTable ( int theBandNoInt );
853
/** reads vector layer specific state from project file DOM node.
857
Called by QgsMapLayer::readXML().
860
/* virtual */ bool readXML_( QDomNode & layer_node );
864
/** write vector layer specific state to project file DOM node.
868
Called by QgsMapLayer::writeXML().
871
/* virtual */ bool writeXML_( QDomNode & layer_node, QDomDocument & doc );
878
/** \brief Paint debug information onto the output image. */
879
void showDebugOverlay(QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort);
885
/** \brief Drawing routine for single band grayscale image. */
886
void drawSingleBandGray(QPainter * theQPainter,
887
QgsRasterViewPort * theRasterViewPort,
888
QgsMapToPixel * theQgsMapToPixel,
891
/** \brief Drawing routine for single band grayscale image, rendered in pseudocolor. */
892
void drawSingleBandPseudoColor(QPainter * theQPainter,
893
QgsRasterViewPort * theRasterViewPort,
894
QgsMapToPixel * theQgsMapToPixel,
902
/** \brief Drawing routine for paletted image, rendered as a single band image in color. */
903
void drawPalettedSingleBandColor(QPainter * theQPainter,
904
QgsRasterViewPort * theRasterViewPort,
905
QgsMapToPixel * theQgsMapToPixel,
908
/** \brief Drawing routine for paletted image, rendered as a single band image in grayscale. */
909
void drawPalettedSingleBandGray(QPainter * theQPainter,
910
QgsRasterViewPort * theRasterViewPort,
911
QgsMapToPixel * theQgsMapToPixel,
913
QString const & theColorQString);
915
/** \brief Drawing routine for paletted image, rendered as a single band image in pseudocolor. */
916
void drawPalettedSingleBandPseudoColor(QPainter * theQPainter,
917
QgsRasterViewPort * theRasterViewPort,
918
QgsMapToPixel * theQgsMapToPixel,
920
QString const & theColorQString);
922
/** \brief Drawing routine for paletted multiband image. */
923
void drawPalettedMultiBandColor(QPainter * theQPainter,
924
QgsRasterViewPort * theRasterViewPort,
925
QgsMapToPixel * theQgsMapToPixel,
932
/** \brief Drawing routine for multiband image, rendered as a single band image in grayscale. */
933
void drawMultiBandSingleBandGray(QPainter * theQPainter,
934
QgsRasterViewPort * theRasterViewPort,
935
QgsMapToPixel * theQgsMapToPixel,
938
/** \brief Drawing routine for multiband image, rendered as a single band image in pseudocolor. */
939
void drawMultiBandSingleBandPseudoColor(QPainter * theQPainter,
940
QgsRasterViewPort * theRasterViewPort,
941
QgsMapToPixel * theQgsMapToPixel,
944
/** \brief Drawing routine for multiband image */
945
void drawMultiBandColor(QPainter * theQPainter,
946
QgsRasterViewPort * theRasterViewPort,
947
QgsMapToPixel * theQgsMapToPixel);
949
/** \brief Read color table from GDAL raster band */
950
void readColorTable ( GDALRasterBand *gdalBand, QgsColorTable *theColorTable );
952
/** \brief Allocate memory and load data to that allocated memory, data type is the same
953
* as raster band. The memory must be released later!
954
* \return pointer to the memory
956
void *readData ( GDALRasterBand *gdalBand, QgsRasterViewPort *viewPort );
958
/** \brief Read a raster value on given position from memory block created by readData()
959
* \param index index in memory block
961
inline double readValue ( void *data, GDALDataType type, int index );
965
Load the given raster file
967
@returns true if successfully read file
971
Called from ctor if a raster image given there
973
bool readFile( QString const & fileName );
975
/** \brief Close data set and release related data */
976
void closeDataset ();
978
/** \brief Update the layer if it is outdated */
982
set up the coordinate transform - in the case of raster this is mainly used to convert
983
the inverese projection of the map extents of the canvas when zooming in etc. so
984
that they match the coordinate system of this layer
985
if no other layers exist, set the output projection to be
986
the same as the input projection, otherwise set the output to the
992
// Private member vars
994
/** \brief Raster width. */
996
/** \brief Raster Height. */
998
/** \brief Cell value representing no data. e.g. -9999 */
999
double noDataValueDouble;
1000
/** \brief Flag to indicate whether debug infor overlay should be rendered onto the raster. */
1001
bool showDebugOverlayFlag;
1002
/** \brief Pointer to the gdaldataset. */
1003
GDALDataset * gdalDataset;
1004
/** \brief Values for mapping pixel to world coordinates. */
1005
double adfGeoTransform[6];
1006
/** \brief Flag indicating whether the histogram should be inverted or not. */
1007
bool invertHistogramFlag;
1008
/** \brief Number of stddev to plot (0) to ignore. Not applicable to all layer types. */
1009
double stdDevsToPlotDouble;
1010
/** \brief A collection of stats - one for each band in the layer.
1011
* The typedef for this is defined above before class declaration
1013
RasterStatsVector rasterStatsVector;
1014
/** \brief The band to be associated with the color red - usually 1. */
1015
QString redBandNameQString;
1016
/** \brief The band to be associated with the color green - usually 2. */
1017
QString greenBandNameQString;
1018
/** \brief The band to be associated with the color blue - usually 3. */
1019
QString blueBandNameQString;
1020
/** \brief The band to be associated with transparency. */
1021
QString transparentBandNameQString;
1022
/** \brief The band to be associated with the grayscale only ouput - usually 1. */
1023
QString grayBandNameQString;
1024
/** \brief Minimum red value - used in scaling procedure. */
1025
double minRedDouble;
1026
/** \brief Maximum red value - used in scaling procedure. */
1027
double maxRedDouble;
1028
/** \brief Minimum green value - used in scaling procedure. */
1029
double minGreenDouble;
1030
/** \brief Maximum green value - used in scaling procedure. */
1031
double maxGreenDouble;
1032
/** \brief Minimum blue value - used in scaling procedure. */
1033
double minBlueDouble;
1034
/** \brief Maximum blue value - used in scaling procedure. */
1035
double maxBlueDouble;
1036
/** \brief Minimum gray value - used in scaling procedure. */
1037
double minGrayDouble;
1038
/** \brief Maximum gray value - used in scaling procedure. */
1039
double maxGrayDouble;
1040
/** \brief Whether this raster has overviews / pyramids or not */
1041
bool hasPyramidsFlag;
1042
/** \brief These are two little icons used to indicate whether a
1043
* layer has pyramds bult or not. */
1044
QPixmap mPyramidPixmap, mNoPyramidPixmap;
1045
/** \brief This list holds a series of RasterPyramid structs
1046
* which store infomation for each potential pyramid level for this raster.*/
1047
RasterPyramidList mPyramidList;
1048
//Transparency slider for popup menu
1049
QSlider * mTransparencySlider;
1051
/* raster properties dialog
1053
@todo XXX should consider generalizing this
1055
QgsRasterLayerProperties * mLayerProperties;
1059
* New functions that will convert this class to a data provider interface
1066
//! Constructor in provider mode
1067
// TODO Rename into a general constructor when the old raster interface is retired
1068
// \param dummy is just there to distinguish this function signature from the old non-provider one.
1069
QgsRasterLayer(int dummy,
1070
QString const & baseName = QString(),
1071
QString const & path = QString(),
1072
QString const & providerLib = QString(),
1073
QStringList const & layers = QStringList(),
1074
QStringList const & styles = QStringList(),
1075
QString const & format = QString(),
1076
QString const & crs = QString(),
1077
QString const & proxyHost = QString(),
1079
QString const & proxyUser = QString(),
1080
QString const & proxyPass = QString());
1082
void setDataProvider( QString const & provider,
1083
QStringList const & layers,
1084
QStringList const & styles,
1085
QString const & format,
1086
QString const & crs,
1087
QString const & proxyHost,
1089
QString const & proxyUser,
1090
QString const & proxyPass );
1092
//! Does this layer use a provider for setting/retrieving data?
1093
bool usesProvider();
1096
* Sets a proxy for the path given in the constructor
1098
* \retval TRUE if proxy setting is successful (if indeed it is supported)
1100
bool setProxy(QString const & host = 0,
1102
QString const & user = 0,
1103
QString const & pass = 0);
1105
//! Which provider is being used for this Raster Layer?
1106
QString providerKey();
1110
void showStatusMessage(QString const & theMessage);
1115
//! Data provider key
1116
QString mProviderKey;
1118
//! pointer for loading the provider library
1121
//! Pointer to data provider derived from the abstract base class QgsDataProvider
1122
QgsRasterDataProvider *dataProvider;
1124
/**Flag indicating wheter the layer is in editing mode or not*/
1127
/**Flag indicating wheter the layer has been modified since the last commit*/
1130
//! Timestamp, the last modified time of the data source when the layer was created
1131
QDateTime mLastModified;
1134
* The error caption associated with the last error.
1136
QString mErrorCaption;
1139
* The error message associated with the last error.