~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/raster/qgsrasterlayer.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                        qgsrasterlayer.h  -  description
 
3
                              -------------------
 
4
 begin                : Fri Jun 28 2002
 
5
 copyright            : (C) 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
 
6
 email                : tim@linfiniti.com
 
7
***************************************************************************/
 
8
/*
 
9
 * Peter J. Ersts - contirbuted to the refactoring and maintenance of this class
 
10
 * B. Morley - added functions to convert this class to a data provider interface
 
11
 * Frank Warmerdam - contributed bug fixes and migrated class to use all GDAL_C_API calls
 
12
 */
 
13
/***************************************************************************
 
14
 *                                                                         *
 
15
 *   This program is free software; you can redistribute it and/or modify  *
 
16
 *   it under the terms of the GNU General Public License as published by  *
 
17
 *   the Free Software Foundation; either version 2 of the License, or     *
 
18
 *   (at your option) any later version.                                   *
 
19
 *                                                                         *
 
20
 ***************************************************************************/
 
21
/* $Id$ */
 
22
#ifndef QGSRASTERLAYER_H
 
23
#define QGSRASTERLAYER_H
 
24
 
 
25
//
 
26
// Includes
 
27
//
 
28
 
 
29
#include <QColor>
 
30
#include <QDateTime>
 
31
#include <QVector>
 
32
#include <QList>
 
33
#include <QMap>
 
34
 
 
35
#include "qgis.h"
 
36
#include "qgspoint.h"
 
37
#include "qgsmaplayer.h"
 
38
#include "qgsrasterviewport.h"
 
39
#include "qgscontrastenhancement.h"
 
40
#include "qgsrastertransparency.h"
 
41
#include "qgsrastershader.h"
 
42
#include "qgscolorrampshader.h"
 
43
#include "qgsrastershaderfunction.h"
 
44
#include "qgsrasterdataprovider.h"
 
45
 
 
46
#define CPL_SUPRESS_CPLUSPLUS
 
47
#include <gdal.h>
 
48
/** \ingroup core
 
49
 * A call back function for showing progress of gdal operations.
 
50
 */
 
51
int CPL_STDCALL progressCallback( double dfComplete,
 
52
                                  const char *pszMessage,
 
53
                                  void * pProgressArg );
 
54
 
 
55
//
 
56
// Forward declarations
 
57
//
 
58
class QgsMapToPixel;
 
59
class QgsRectangle;
 
60
class QgsRasterBandStats;
 
61
class QgsRasterPyramid;
 
62
class QgsRasterLayerProperties;
 
63
class QImage;
 
64
class QPixmap;
 
65
class QSlider;
 
66
class QLibrary;
 
67
 
 
68
/** \ingroup core
 
69
 *  This class provides qgis with the ability to render raster datasets
 
70
 *  onto the mapcanvas.
 
71
 *
 
72
 *  The qgsrasterlayer class makes use of gdal for data io, and thus supports
 
73
 *  any gdal supported format. The constructor attempts to infer what type of
 
74
 *  file (LayerType) is being opened - not in terms of the file format (tif, ascii grid etc.)
 
75
 *  but rather in terms of whether the image is a GRAYSCALE, PaletteD or Multiband,
 
76
 *
 
77
 *  Within the three allowable raster layer types, there are 8 permutations of
 
78
 *  how a layer can actually be rendered. These are defined in the DrawingStyle enum
 
79
 *  and consist of:
 
80
 *
 
81
 *  SingleBandGray -> a GRAYSCALE layer drawn as a range of gray colors (0-255)
 
82
 *  SingleBandPseudoColor -> a GRAYSCALE layer drawn using a pseudocolor algorithm
 
83
 *  PalettedSingleBandGray -> a PaletteD layer drawn in gray scale (using only one of the color components)
 
84
 *  PalettedSingleBandPseudoColor -> a PaletteD layer having only one of its color components rendered as psuedo color
 
85
 *  PalettedMultiBandColor -> a PaletteD image where the bands contains 24bit color info and 8 bits is pulled out per color
 
86
 *  MultiBandSingleGandGray -> a layer containing 2 or more bands, but using only one band to produce a grayscale image
 
87
 *  MultiBandSingleBandPseudoColor -> a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
 
88
 *  MultiBandColor -> 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
 
89
 *
 
90
 *  Each of the above mentioned drawing styles is implemented in its own draw* function.
 
91
 *  Some of the drawing styles listed above require statistics about the layer such
 
92
 *  as the min / max / mean / stddev etc. statistics for a band can be gathered using the
 
93
 *  bandStatistics function. Note that statistics gathering is a slow process and
 
94
 *  every effort should be made to call this function as few times as possible. For this
 
95
 *  reason, qgsraster has a vector class member to store stats for each band. The
 
96
 *  constructor initialises this vector on startup, but only populates the band name and
 
97
 *  number fields.
 
98
 *
 
99
 *  Note that where bands are of gdal 'undefined' type, their values may exceed the
 
100
 *  renderable range of 0-255. Because of this a linear scaling histogram enhanceContrast is
 
101
 *  applied to undefined layers to normalise the data into the 0-255 range.
 
102
 *
 
103
 *  A qgsrasterlayer band can be referred to either by name or by number (base=1). It
 
104
 *  should be noted that band names as stored in datafiles may not be unique, and
 
105
 *  so the rasterlayer class appends the band number in brackets behind each band name.
 
106
 *
 
107
 *  Sample usage of the QgsRasterLayer class:
 
108
 *
 
109
 * \code
 
110
 *     QString myFileNameQString = "/path/to/file";
 
111
 *     QFileInfo myFileInfo(myFileNameQString);
 
112
 *     QString myBaseNameQString = myFileInfo.baseName();
 
113
 *     QgsRasterLayer *myRasterLayer = new QgsRasterLayer(myFileNameQString, myBaseNameQString);
 
114
 *
 
115
 * \endcode
 
116
 *
 
117
 *  In order to automate redrawing of a raster layer, you should like it to a map canvas like this :
 
118
 *
 
119
 * \code
 
120
 *     QObject::connect( myRasterLayer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) );
 
121
 * \endcode
 
122
 *
 
123
 *  A raster layer can also export its legend as a pixmap:
 
124
 *
 
125
 * \code
 
126
 *     QPixmap myQPixmap = myRasterLayer->legendPixmap();
 
127
 * \endcode
 
128
 *
 
129
 * Once a layer has been created you can find out what type of layer it is (GrayOrUndefined, Palette or Multiband):
 
130
 *
 
131
 * \code
 
132
 *    if (rasterLayer->rasterType()==QgsRasterLayer::Multiband)
 
133
 *    {
 
134
 *      //do something
 
135
 *    }
 
136
 *    else if (rasterLayer->rasterType()==QgsRasterLayer::Palette)
 
137
 *    {
 
138
 *      //do something
 
139
 *    }
 
140
 *    else // QgsRasterLayer::GrayOrUndefined
 
141
 *    {
 
142
 *      //do something.
 
143
 *    }
 
144
 * \endcode
 
145
 *
 
146
 * You can combine layer type detection with the setDrawingStyle method to override the default drawing style assigned
 
147
 * when a layer is loaded:
 
148
 *
 
149
  * \code
 
150
 *    if (rasterLayer->rasterType()==QgsRasterLayer::Multiband)
 
151
 *    {
 
152
 *       myRasterLayer->setDrawingStyle(QgsRasterLayer::MultiBandSingleBandPseudoColor);
 
153
 *    }
 
154
 *    else if (rasterLayer->rasterType()==QgsRasterLayer::Palette)
 
155
 *    {
 
156
 *      myRasterLayer->setDrawingStyle(QgsRasterLayer::PalettedSingleBandPseudoColor);
 
157
 *    }
 
158
 *    else // QgsRasterLayer::GrayOrUndefined
 
159
 *    {
 
160
 *      myRasterLayer->setDrawingStyle(QgsRasterLayer::SingleBandPseudoColor);
 
161
 *    }
 
162
 * \endcode
 
163
 *
 
164
 *  Raster layers can also have an arbitrary level of transparency defined, and have their
 
165
 *  color palettes inverted using the setTransparency and setInvertHistogram methods.
 
166
 *
 
167
 *  Pseudocolor images can have their output adjusted to a given number of standard
 
168
 *  deviations using the setStandardDeviations method.
 
169
 *
 
170
 *  The final area of functionality you may be interested in is band mapping. Band mapping
 
171
 *  allows you to choose arbitrary band -> color mappings and is applicable only to Palette
 
172
 *  and Multiband rasters, There are four mappings that can be made: red, green, blue and gray.
 
173
 *  Mappings are non-exclusive. That is a given band can be assigned to no, some or all
 
174
 *  color mappings. The constructor sets sensible defaults for band mappings but these can be
 
175
 *  overridden at run time using the setRedBandName, setGreenBandName, setBlueBandName and setGrayBandName
 
176
 *  methods.
 
177
 */
 
178
 
 
179
class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
 
180
{
 
181
    Q_OBJECT
 
182
  public:
 
183
    /** \brief This is the constructor for the RasterLayer class.
 
184
     *
 
185
     * The main tasks carried out by the constructor are:
 
186
     *
 
187
     * -Load the rasters default style (.qml) file if it exists
 
188
     *
 
189
     * -Populate the RasterStatsVector with initial values for each band.
 
190
     *
 
191
     * -Calculate the layer extents
 
192
     *
 
193
     * -Determine whether the layer is gray, paletted or multiband.
 
194
     *
 
195
     * -Assign sensible defaults for the red, green, blue and gray bands.
 
196
     *
 
197
     * -
 
198
     * */
 
199
    QgsRasterLayer( const QString & path = QString::null,
 
200
                    const QString &  baseName = QString::null,
 
201
                    bool loadDefaultStyleFlag = true );
 
202
 
 
203
    /**  \brief [ data provider interface ] Constructor in provider mode */
 
204
    QgsRasterLayer( int dummy,
 
205
                    const QString & baseName = QString(),
 
206
                    const QString & path = QString(),
 
207
                    const QString & providerLib = QString(),
 
208
                    const QStringList & layers = QStringList(),
 
209
                    const QStringList & styles = QStringList(),
 
210
                    const QString & format = QString(),
 
211
                    const QString & crs = QString() );
 
212
 
 
213
 
 
214
    /** \brief The destructor */
 
215
    ~QgsRasterLayer();
 
216
 
 
217
 
 
218
    //
 
219
    // Enums, structs and typedefs
 
220
    //
 
221
    /** \brief This enumerator describes the types of shading that can be used */
 
222
    enum ColorShadingAlgorithm
 
223
    {
 
224
      UndefinedShader,
 
225
      PseudoColorShader,
 
226
      FreakOutShader,
 
227
      ColorRampShader,
 
228
      UserDefinedShader
 
229
    };
 
230
 
 
231
    /** \brief This enumerator describes the different kinds of drawing we can do */
 
232
    enum DrawingStyle
 
233
    {
 
234
      UndefinedDrawingStyle,
 
235
      SingleBandGray,                 // a single band image drawn as a range of gray colors
 
236
      SingleBandPseudoColor,          // a single band image drawn using a pseudocolor algorithm
 
237
      PalettedColor,                  //a "Palette" image drawn using color table
 
238
      PalettedSingleBandGray,        // a "Palette" layer drawn in gray scale
 
239
      PalettedSingleBandPseudoColor, // a "Palette" layerdrawn using a pseudocolor algorithm
 
240
      PalettedMultiBandColor,         // currently not supported
 
241
      MultiBandSingleGandGray,        // a layer containing 2 or more bands, but a single band drawn as a range of gray colors
 
242
      MultiBandSingleBandPseudoColor, //a layer containing 2 or more bands, but a single band drawn using a pseudocolor algorithm
 
243
      MultiBandColor                  //a layer containing 2 or more bands, mapped to RGB color space.
 
244
      //In the case of a multiband with only two bands, one band will be mapped to more than one color.
 
245
    };
 
246
 
 
247
    /** \brief This enumerator describes the type of raster layer */
 
248
    enum LayerType
 
249
    {
 
250
      GrayOrUndefined,
 
251
      Palette,
 
252
      Multiband
 
253
    } ;
 
254
 
 
255
    /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */
 
256
    typedef QList<QgsContrastEnhancement> ContrastEnhancementList;
 
257
 
 
258
    /** \brief  A list containing one RasterPyramid struct per raster band in this raster layer.
 
259
     * POTENTIAL pyramid layer. This works by dividing the height
 
260
     * and width of the raster by an incrementing number. As soon as the result
 
261
     * of the division is <=256 we stop allowing RasterPyramid structs
 
262
     * to be added to the list. Each time a RasterPyramid is created
 
263
     * we will check to see if a pyramid matching these dimensions already exists
 
264
     * in the raster layer, and if so mark the exists flag as true */
 
265
    typedef QList<QgsRasterPyramid> RasterPyramidList;
 
266
 
 
267
    /** \brief  A list containing one RasterBandStats struct per raster band in this raster layer.
 
268
     * Note that while every RasterBandStats element will have the name and number of its associated
 
269
     * band populated, any additional stats are calculated on a need to know basis.*/
 
270
    typedef QList<QgsRasterBandStats> RasterStatsList;
 
271
 
 
272
 
 
273
 
 
274
 
 
275
 
 
276
    //
 
277
    // Static methods:
 
278
    //
 
279
    static void buildSupportedRasterFileFilter( QString & fileFilters );
 
280
 
 
281
    /** This helper checks to see whether the file name appears to be a valid
 
282
     *  raster file name.  If the file name looks like it could be valid,
 
283
     *  but some sort of error occurs in processing the file, the error is
 
284
     *  returned in retError.
 
285
     */
 
286
    static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
 
287
 
 
288
    static bool isValidRasterFileName( const QString & theFileNameQString );
 
289
 
 
290
    /** Return time stamp for given file name */
 
291
    static QDateTime lastModified( const QString &  name );
 
292
 
 
293
    /** \brief ensures that GDAL drivers are registered, but only once */
 
294
    static void registerGdalDrivers();
 
295
 
 
296
 
 
297
 
 
298
 
 
299
    //
 
300
    // Non Static inline methods
 
301
    //
 
302
 
 
303
    /** \brief  Accessor for blue band name mapping */
 
304
    QString blueBandName() const { return mBlueBandName; }
 
305
 
 
306
    /** \brief Accessor for color shader algorithm */
 
307
    QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const { return mColorShadingAlgorithm; }
 
308
 
 
309
    /** \brief Accessor for contrast enhancement algorithm */
 
310
    QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() { return mContrastEnhancementAlgorithm; }
 
311
 
 
312
    /** \brief Returns contrast enhancement algorithm as a string */
 
313
    QString contrastEnhancementAlgorithmAsString() const;
 
314
 
 
315
    /** \brief Accessor for drawing style */
 
316
    DrawingStyle drawingStyle() { return mDrawingStyle; }
 
317
 
 
318
    /** \brief Accessor for gray band name mapping */
 
319
    QString grayBandName() const { return mGrayBandName; }
 
320
 
 
321
    /** \brief Accessor for green band name mapping */
 
322
    QString greenBandName() const { return mGreenBandName; }
 
323
 
 
324
    /** \brief Accessor for mHasPyramids (READ ONLY) */
 
325
    bool hasPyramids() { return mHasPyramids; }
 
326
 
 
327
    /** \brief Accessor for mUserDefinedGrayMinimumMaximum */
 
328
    bool hasUserDefinedGrayMinimumMaximum() const { return mUserDefinedGrayMinimumMaximum; }
 
329
 
 
330
    /** \brief Accessor for mUserDefinedRGBMinimumMaximum */
 
331
    bool hasUserDefinedRGBMinimumMaximum() const { return mUserDefinedRGBMinimumMaximum; }
 
332
 
 
333
    /** \brief Accessor that returns the height of the (unclipped) raster */
 
334
    int height() { return mHeight; }
 
335
 
 
336
    /** \brief Accessor to find out whether the histogram should be inverted  */
 
337
    bool invertHistogram() const { return mInvertColor; }
 
338
 
 
339
    /** \brief Is the NoDataValue Valid */
 
340
    bool isNoDataValueValid() const { return mValidNoDataValue; }
 
341
 
 
342
    /** \brief Accessor for mGrayMinimumMaximumEstimated */
 
343
    bool isGrayMinimumMaximumEstimated() const { return mGrayMinimumMaximumEstimated; }
 
344
 
 
345
    /** \brief Accessor for mRGBMinimumMaximumEstimated */
 
346
    bool isRGBMinimumMaximumEstimated() const { return mRGBMinimumMaximumEstimated; }
 
347
 
 
348
    /** \brief Accessor that returns the NO_DATA entry for this raster */
 
349
    double noDataValue( bool* isValid = 0 ) { if ( isValid ) { *isValid = mValidNoDataValue;} return mNoDataValue; }
 
350
 
 
351
    /** \brief Returns a pointer to the transparency object */
 
352
    QgsRasterTransparency* rasterTransparency() { return &mRasterTransparency; }
 
353
 
 
354
    /** \brief Accessor for raster shader */
 
355
    QgsRasterShader* rasterShader() { return mRasterShader; }
 
356
 
 
357
    /** \brief  Accessor for raster layer type (which is a read only property) */
 
358
    LayerType rasterType() { return mRasterType; }
 
359
 
 
360
    /** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red color) */
 
361
    QString redBandName() const { return mRedBandName; }
 
362
 
 
363
    /**  [ data provider interface ] Set the data provider */
 
364
    void setDataProvider( const QString & provider,
 
365
                          const QStringList & layers,
 
366
                          const QStringList & styles,
 
367
                          const QString & format,
 
368
                          const QString & crs );
 
369
 
 
370
    /** \brief Mutator for drawing style */
 
371
    void setDrawingStyle( const DrawingStyle &  theDrawingStyle ) { mDrawingStyle = theDrawingStyle; }
 
372
 
 
373
    /** \brief Mutator for mGrayMinimumMaximumEstimated */
 
374
    void setGrayMinimumMaximumEstimated( bool theBool ) { mGrayMinimumMaximumEstimated = theBool; }
 
375
 
 
376
    /** \brief Mutator to alter the state of the invert histogram flag  */
 
377
    void setInvertHistogram( bool theFlag ) { mInvertColor = theFlag; }
 
378
 
 
379
    /** \brief Mutator for mRGBMinimumMaximumEstimated */
 
380
    void setRGBMinimumMaximumEstimated( bool theBool ) { mRGBMinimumMaximumEstimated = theBool; }
 
381
 
 
382
    /** \brief Mutator to alter the number of standard deviations that should be plotted */
 
383
    void setStandardDeviations( double theStandardDeviations ) { mStandardDeviations = theStandardDeviations; }
 
384
 
 
385
    /** \brief Mutator for mUserDefinedGrayMinimumMaximum */
 
386
    void setUserDefinedGrayMinimumMaximum( bool theBool ) { mUserDefinedGrayMinimumMaximum = theBool; }
 
387
 
 
388
    /** \brief Mutator for mUserDefinedRGBMinimumMaximum */
 
389
    void setUserDefinedRGBMinimumMaximum( bool theBool ) { mUserDefinedRGBMinimumMaximum = theBool; }
 
390
 
 
391
    /** \brief Accessor to find out how many standard deviations are being plotted */
 
392
    double standardDeviations() const { return mStandardDeviations; }
 
393
 
 
394
    /** \brief  Accessor for transparent band name mapping */
 
395
    QString transparentBandName() const { return mTransparencyBandName; }
 
396
 
 
397
    /**  \brief [ data provider interface ] Does this layer use a provider for setting/retrieving data? */
 
398
    bool usesProvider();
 
399
 
 
400
    /** \brief Accessor that returns the width of the (unclipped) raster  */
 
401
    int width() { return mWidth; }
 
402
 
 
403
 
 
404
 
 
405
 
 
406
 
 
407
    //
 
408
    // Non Static methods
 
409
    //
 
410
    /** \brief Get the number of bands in this layer  */
 
411
    unsigned int bandCount();
 
412
 
 
413
    /** \brief Get the name of a band given its number  */
 
414
    const  QString bandName( int theBandNoInt );
 
415
 
 
416
    /** \brief Get the number of a band given its name. The name is the rewritten name set
 
417
    *   up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal!
 
418
    *   If no matching band is found zero will be returned! */
 
419
    int bandNumber( const QString & theBandName );
 
420
 
 
421
    /** \brief Get RasterBandStats for a band given its number (read only)  */
 
422
    const  QgsRasterBandStats bandStatistics( int );
 
423
 
 
424
    /** \brief Get RasterBandStats for a band given its name (read only)  */
 
425
    const  QgsRasterBandStats bandStatistics( const QString & );
 
426
 
 
427
    /** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
 
428
     * POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
 
429
     * ACTUALLY exists you need to look at the existsFlag member in each struct stored in the
 
430
     * list.
 
431
     */
 
432
    RasterPyramidList buildPyramidList();
 
433
 
 
434
    /** \brief Accessor for color shader algorithm */
 
435
    QString colorShadingAlgorithmAsString() const;
 
436
 
 
437
    /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
 
438
    void computeMinimumMaximumEstimates( int theBand, double* theMinMax );
 
439
 
 
440
    /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
 
441
    void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );
 
442
 
 
443
    /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
 
444
    void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );
 
445
 
 
446
    /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
 
447
    void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );
 
448
 
 
449
    /** \brief Get a pointer to the contrast enhancement for the selected band */
 
450
    QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );
 
451
 
 
452
    /**Copies the symbology settings from another layer. Returns true in case of success*/
 
453
    bool copySymbologySettings( const QgsMapLayer& theOther );
 
454
 
 
455
    /** \brief Get a pointer to the color table */
 
456
    QList<QgsColorRampShader::ColorRampItem>* colorTable( int theBandNoInt );
 
457
 
 
458
    /** Returns the data provider */
 
459
    QgsRasterDataProvider* dataProvider();
 
460
 
 
461
    /** Returns the data provider in a const-correct manner */
 
462
    const QgsRasterDataProvider* dataProvider() const;
 
463
 
 
464
    /** \brief This is called when the view on the raster layer needs to be redrawn */
 
465
    bool draw( QgsRenderContext& rendererContext );
 
466
 
 
467
    /** \brief This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap */
 
468
    void draw( QPainter * theQPainter,
 
469
               QgsRasterViewPort * myRasterViewPort,
 
470
               const QgsMapToPixel* theQgsMapToPixel = 0 );
 
471
 
 
472
    /** \brief Returns a string representation of drawing style
 
473
     *
 
474
     * Implemented mainly for serialisation / deserialisation of settings to xml.
 
475
     * NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead.
 
476
     * */
 
477
    QString drawingStyleAsString() const;
 
478
 
 
479
    /** \brief Checks if symbology is the same as another layers */
 
480
    bool hasCompatibleSymbology( const QgsMapLayer& theOther ) const;
 
481
 
 
482
    /** \brief  Check whether a given band number has stats associated with it */
 
483
    bool hasStatistics( int theBandNoInt );
 
484
 
 
485
    /** \brief Identify raster value(s) found on the point position */
 
486
    bool identify( const QgsPoint & point, QMap<QString, QString>& results );
 
487
 
 
488
    /** \brief Identify arbitrary details from the WMS server found on the point position */
 
489
    QString identifyAsText( const QgsPoint & point );
 
490
 
 
491
    /** \brief Currently returns always false */
 
492
    bool isEditable() const;
 
493
 
 
494
    /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure  */
 
495
    QString lastError();
 
496
 
 
497
    /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */
 
498
    QString lastErrorTitle();
 
499
 
 
500
    /** \brief Get a legend image for this layer */
 
501
    QPixmap legendAsPixmap();
 
502
 
 
503
    /** \brief  Overloaded version of above function that can print layer name onto legend */
 
504
    QPixmap legendAsPixmap( bool );
 
505
 
 
506
    /** \brief Use this method when you want an annotated legend suitable for print output etc */
 
507
    QPixmap legendAsPixmap( int theLabelCount );
 
508
 
 
509
    /** \brief Accessor for maximum value user for contrast enhancement */
 
510
    double maximumValue( unsigned int theBand );
 
511
 
 
512
    /** \brief Accessor for maximum value user for contrast enhancement */
 
513
    double maximumValue( QString theBand );
 
514
 
 
515
    /** \brief Obtain GDAL Metadata for this layer */
 
516
    QString metadata();
 
517
 
 
518
    /** \brief Accessor for minimum value user for contrast enhancement */
 
519
    double minimumValue( unsigned int theBand );
 
520
 
 
521
    /** \brief Accessor for minimum value user for contrast enhancement */
 
522
    double minimumValue( QString theBand );
 
523
 
 
524
    /** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */
 
525
    QPixmap paletteAsPixmap( int theBand = 1 );
 
526
 
 
527
    /**  \brief [ data provider interface ] Which provider is being used for this Raster Layer? */
 
528
    QString providerKey();
 
529
 
 
530
    /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
 
531
    double rasterUnitsPerPixel();
 
532
 
 
533
    /** \brief Read color table from GDAL raster band */
 
534
    bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );
 
535
 
 
536
    /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */
 
537
    void resetNoDataValue();
 
538
 
 
539
    /** \brief Mutator for blue band name mapping */
 
540
    void setBlueBandName( const QString & theBandName );
 
541
 
 
542
    /** \brief Mutator for color shader algorithm */
 
543
    void setColorShadingAlgorithm( QgsRasterLayer::ColorShadingAlgorithm theShaderAlgorithm );
 
544
 
 
545
    /** \brief Mutator for color shader algorithm */
 
546
    void setColorShadingAlgorithm( QString theShaderAlgorithm );
 
547
 
 
548
    /** \brief Mutator for contrast enhancement algorithm */
 
549
    void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
 
550
                                          bool theGenerateLookupTableFlag = true );
 
551
 
 
552
    /** \brief Mutator for contrast enhancement algorithm */
 
553
    void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true );
 
554
 
 
555
    /** \brief Mutator for contrast enhancement function */
 
556
    void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction );
 
557
 
 
558
    /** \brief Overloaded version of the above function for convenience when restoring from xml */
 
559
    void setDrawingStyle( const QString & theDrawingStyleQString );
 
560
 
 
561
    /** \brief Mutator for gray band name mapping  */
 
562
    void setGrayBandName( const QString & theBandName );
 
563
 
 
564
    /** \brief Mutator for green band name mapping  */
 
565
    void setGreenBandName( const QString & theBandName );
 
566
 
 
567
    /** \brief Mutator for setting the maximum value for contrast enhancement */
 
568
    void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
 
569
 
 
570
    /** \brief Mutator for setting the maximum value for contrast enhancement */
 
571
    void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );
 
572
 
 
573
    /** \brief Mutator for setting the minimum value for contrast enhancement */
 
574
    void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
 
575
 
 
576
    /** \brief Mutator for setting the minimum value for contrast enhancement */
 
577
    void setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );
 
578
 
 
579
    /** \brief Mutator that allows the  NO_DATA entry for this raster to be overridden */
 
580
    void setNoDataValue( double theNoData );
 
581
 
 
582
    /** \brief Set the raster shader function to a user defined function */
 
583
    void setRasterShaderFunction( QgsRasterShaderFunction* theFunction );
 
584
 
 
585
    /** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */
 
586
    void setRedBandName( const QString & theBandName );
 
587
 
 
588
    /** \brief Mutator for transparent band name mapping  */
 
589
    void setTransparentBandName( const QString & theBandName );
 
590
 
 
591
    /**  \brief [ data provider interface ] A wrapper function to emit a progress update signal */
 
592
    void showProgress( int theValue );
 
593
 
 
594
    /** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
 
595
    QStringList subLayers() const;
 
596
 
 
597
    /** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */
 
598
    void thumbnailAsPixmap( QPixmap * theQPixmap );
 
599
 
 
600
    /** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
 
601
    void triggerRepaint();
 
602
 
 
603
 
 
604
 
 
605
 
 
606
 
 
607
    //
 
608
    // Virtural methods
 
609
    //
 
610
    /**
 
611
     * Reorders the *previously selected* sublayers of this layer from bottom to top
 
612
     *
 
613
     * (Useful for providers that manage their own layers, such as WMS)
 
614
     *
 
615
     */
 
616
    virtual void setLayerOrder( const QStringList & layers );
 
617
 
 
618
    /**
 
619
     * Set the visibility of the given sublayer name
 
620
     */
 
621
    virtual void setSubLayerVisibility( const QString & name, bool vis );
 
622
 
 
623
 
 
624
 
 
625
 
 
626
 
 
627
  public slots:
 
628
    /** \brief Create GDAL pyramid overviews */
 
629
    QString buildPyramids( const RasterPyramidList &,
 
630
                           const QString &  theResamplingMethod = "NEAREST",
 
631
                           bool theTryInternalFlag = false );
 
632
 
 
633
    /** \brief Populate the histogram vector for a given band */
 
634
    void populateHistogram( int theBandNoInt,
 
635
                            int theBinCountInt = 256,
 
636
                            bool theIgnoreOutOfRangeFlag = true,
 
637
                            bool theThoroughBandScanFlag = false );
 
638
 
 
639
    void showStatusMessage( const QString & theMessage );
 
640
 
 
641
    /** \brief Propagate progress updates from GDAL up to the parent app */
 
642
    void updateProgress( int, int );
 
643
 
 
644
 
 
645
 
 
646
 
 
647
 
 
648
  signals:
 
649
    /** \brief Signal for notifying listeners of long running processes */
 
650
    void progressUpdate( int theValue );
 
651
 
 
652
 
 
653
 
 
654
 
 
655
  protected:
 
656
 
 
657
    /** \brief Read the symbology for the current layer from the Dom node supplied */
 
658
    bool readSymbology( const QDomNode& node, QString& errorMessage );
 
659
 
 
660
    /** \brief Reads layer specific state from project file Dom node */
 
661
    bool readXml( QDomNode & layer_node );
 
662
 
 
663
    /** \brief Write the symbology for the layer into the docment provided */
 
664
    bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
 
665
 
 
666
    /** \brief Write layer specific state to project file Dom node */
 
667
    bool writeXml( QDomNode & layer_node, QDomDocument & doc );
 
668
 
 
669
 
 
670
 
 
671
 
 
672
 
 
673
  private:
 
674
    //
 
675
    // Private methods
 
676
    //
 
677
 
 
678
    /** \brief Drawing routine for multiband image  */
 
679
    void drawMultiBandColor( QPainter * theQPainter,
 
680
                             QgsRasterViewPort * theRasterViewPort,
 
681
                             const QgsMapToPixel* theQgsMapToPixel );
 
682
 
 
683
    /** \brief Drawing routine for multiband image, rendered as a single band image in grayscale */
 
684
    void drawMultiBandSingleBandGray( QPainter * theQPainter,
 
685
                                      QgsRasterViewPort * theRasterViewPort,
 
686
                                      const QgsMapToPixel* theQgsMapToPixel,
 
687
                                      int theBandNoInt );
 
688
 
 
689
    /** \brief Drawing routine for multiband image, rendered as a single band image in pseudocolor */
 
690
    void drawMultiBandSingleBandPseudoColor( QPainter * theQPainter,
 
691
        QgsRasterViewPort * theRasterViewPort,
 
692
        const QgsMapToPixel* theQgsMapToPixel,
 
693
        int theBandNoInt );
 
694
 
 
695
    /** \brief Drawing routine for single band with a color map */
 
696
    void drawPalettedSingleBandColor( QPainter * theQPainter,
 
697
                                      QgsRasterViewPort * theRasterViewPort,
 
698
                                      const QgsMapToPixel* theQgsMapToPixel,
 
699
                                      int theBandNoInt );
 
700
 
 
701
    /** \brief Drawing routine for paletted image, rendered as a single band image in grayscale */
 
702
    void drawPalettedSingleBandGray( QPainter * theQPainter,
 
703
                                     QgsRasterViewPort * theRasterViewPort,
 
704
                                     const QgsMapToPixel* theQgsMapToPixel,
 
705
                                     int theBandNoInt );
 
706
 
 
707
    /** \brief Drawing routine for paletted image, rendered as a single band image in pseudocolor */
 
708
    void drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
 
709
                                            QgsRasterViewPort * theRasterViewPort,
 
710
                                            const QgsMapToPixel* theQgsMapToPixel,
 
711
                                            int theBandNoInt );
 
712
 
 
713
    /** \brief Drawing routine for paletted multiband image */
 
714
    void drawPalettedMultiBandColor( QPainter * theQPainter,
 
715
                                     QgsRasterViewPort * theRasterViewPort,
 
716
                                     const QgsMapToPixel* theQgsMapToPixel,
 
717
                                     int theBandNoInt );
 
718
 
 
719
    /** \brief Drawing routine for single band grayscale image */
 
720
    void drawSingleBandGray( QPainter * theQPainter,
 
721
                             QgsRasterViewPort * theRasterViewPort,
 
722
                             const QgsMapToPixel* theQgsMapToPixel,
 
723
                             int theBandNoInt );
 
724
 
 
725
    /** \brief Drawing routine for single band grayscale image, rendered in pseudocolor */
 
726
    void drawSingleBandPseudoColor( QPainter * theQPainter,
 
727
                                    QgsRasterViewPort * theRasterViewPort,
 
728
                                    const QgsMapToPixel* theQgsMapToPixel,
 
729
                                    int theBandNoInt );
 
730
 
 
731
    /** \brief Close data set and release related data */
 
732
    void closeDataset();
 
733
 
 
734
    /** \brief helper function to create zero padded band names */
 
735
    QString  generateBandName( int );
 
736
 
 
737
    /** \brief Find out whether a given band exists.    */
 
738
    bool hasBand( const QString &  theBandName );
 
739
 
 
740
    /** \brief Places the rendered image onto the canvas */
 
741
    void paintImageToCanvas( QPainter* theQPainter, QgsRasterViewPort * theRasterViewPort,
 
742
                             const QgsMapToPixel* theQgsMapToPixel, QImage* theImage );
 
743
 
 
744
    /** \brief Query GDAL to find out the Wkt projection string for this layer.*/
 
745
    QString projectionWkt();
 
746
 
 
747
    /** \brief Allocate memory and load data to that allocated memory */
 
748
    void* readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort );
 
749
 
 
750
    /** \brief Load the given raster file */
 
751
    bool readFile( const QString & fileName );
 
752
 
 
753
    /** \brief Read a raster value given position from memory block created by readData() */
 
754
    inline double readValue( void *data, GDALDataType type, int index );
 
755
 
 
756
    /** \brief Update the layer if it is outdated */
 
757
    bool update();
 
758
 
 
759
    /** \brief Verify and transform band name for internal consistency. Return 'Not Set' on any type of failure */
 
760
    QString validateBandName( const QString & theBandName );
 
761
 
 
762
 
 
763
 
 
764
 
 
765
    //
 
766
    // Private member vars
 
767
    //
 
768
    /** \brief  Constant defining flag for XML and a constant that signals property not used */
 
769
    const QString QSTRING_NOT_SET;
 
770
    const QString TRSTRING_NOT_SET;
 
771
 
 
772
    /** \brief The number of bands in the dataset */
 
773
    int mBandCount;
 
774
 
 
775
    /** \brief The band to be associated with the color blue - usually 3 */
 
776
    QString mBlueBandName;
 
777
 
 
778
    /** \brief The raster shading algorithm being used */
 
779
    ColorShadingAlgorithm mColorShadingAlgorithm;
 
780
 
 
781
    /** \brief The contrast enhancement algorithm being used */
 
782
    QgsContrastEnhancement::ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm;
 
783
 
 
784
    /** \brief List containing the contrast enhancements for each band */
 
785
    ContrastEnhancementList mContrastEnhancementList;
 
786
 
 
787
    /** \brief Number of stddev to plot (0) to ignore. Not applicable to all layer types */
 
788
    double mStandardDeviations;
 
789
 
 
790
    /**  [ data provider interface ] Pointer to data provider derived from the abstract base class QgsDataProvider */
 
791
    QgsRasterDataProvider* mDataProvider;
 
792
 
 
793
    DrawingStyle mDrawingStyle;
 
794
 
 
795
    /**  [ data provider interface ] Flag indicating whether the layer is in editing mode or not*/
 
796
    bool mEditable;
 
797
 
 
798
    /** [ data provider interface ]The error message associated with the last error */
 
799
    QString mError;
 
800
 
 
801
    /** [ data provider interface ] The error caption associated with the last error */
 
802
    QString mErrorCaption;
 
803
 
 
804
    /** \brief Pointer to the gdaldataset */
 
805
    GDALDatasetH mGdalBaseDataset;
 
806
 
 
807
    /** \brief Pointer to the gdaldataset (possibly warped vrt) */
 
808
    GDALDatasetH mGdalDataset;
 
809
 
 
810
    /** \brief Values for mapping pixel to world coordinates. Contents of this array are the same as the GDAL adfGeoTransform */
 
811
    double mGeoTransform[6];
 
812
 
 
813
    /** \brief The band to be associated with the grayscale only output - usually 1 */
 
814
    QString mGrayBandName;
 
815
 
 
816
    /** \brief Flag to indicate of the min max values are actual or estimates/user defined */
 
817
    bool mGrayMinimumMaximumEstimated;
 
818
 
 
819
    /** \brief The band to be associated with the color green - usually 2 */
 
820
    QString mGreenBandName;
 
821
 
 
822
    /** \brief Whether this raster has overviews / pyramids or not */
 
823
    bool mHasPyramids;
 
824
 
 
825
    /** \brief  Raster width */
 
826
    int mWidth;
 
827
 
 
828
    /** \brief  Raster height */
 
829
    int mHeight;
 
830
 
 
831
    /** \brief Flag indicating whether the color of pixels should be inverted or not */
 
832
    bool mInvertColor;
 
833
 
 
834
    /**  [ data provider interface ] Timestamp, the last modified time of the data source when the layer was created */
 
835
    QDateTime mLastModified;
 
836
 
 
837
    QgsRasterViewPort mLastViewPort;
 
838
 
 
839
    /**  [ data provider interface ] pointer for loading the provider library */
 
840
    QLibrary* mLib;
 
841
 
 
842
    /**  [ data provider interface ] Flag indicating whether the layer has been modified since the last commit*/
 
843
    bool mModified;
 
844
 
 
845
    /** \brief Cell value representing no data. e.g. -9999  */
 
846
    double mNoDataValue;
 
847
 
 
848
    /**  [ data provider interface ] Data provider key */
 
849
    QString mProviderKey;
 
850
 
 
851
    /** \brief This list holds a series of RasterPyramid structs which store information for each potential pyramid level */
 
852
    RasterPyramidList mPyramidList;
 
853
 
 
854
    /** \brief The raster shader for the layer */
 
855
    QgsRasterShader* mRasterShader;
 
856
 
 
857
    /** \brief A collection of stats - one for each band in the layer */
 
858
    RasterStatsList mRasterStatsList;
 
859
 
 
860
    /** \brief The transparency container */
 
861
    QgsRasterTransparency mRasterTransparency;
 
862
 
 
863
    LayerType mRasterType;
 
864
 
 
865
    /** \brief The band to be associated with the color red - usually 1 */
 
866
    QString mRedBandName;
 
867
 
 
868
    /** \brief Flag to indicate of the min max values are actual or estimates/user defined */
 
869
    bool mRGBMinimumMaximumEstimated;
 
870
 
 
871
    /** \brief The band to be associated with transparency */
 
872
    QString mTransparencyBandName;
 
873
 
 
874
    /** \brief Flag to indicate if the user entered custom min max values */
 
875
    bool mUserDefinedGrayMinimumMaximum;
 
876
 
 
877
    /** \brief Flag to indicate if the user entered custom min max values */
 
878
    bool mUserDefinedRGBMinimumMaximum;
 
879
 
 
880
    /** \brief Flag indicating if the nodatavalue is valid*/
 
881
    bool mValidNoDataValue;
 
882
};
 
883
 
 
884
#endif