Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsrasterdataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterdataprovider.h - DataProvider Interface for raster layers
3  --------------------------------------
4  Date : Mar 11, 2005
5  Copyright : (C) 2005 by Brendan Morley
6  email : morb at ozemail dot com dot au
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
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. *
15  * *
16  ***************************************************************************/
17 
18 /* Thank you to Marco Hugentobler for the original vector DataProvider */
19 
20 #ifndef QGSRASTERDATAPROVIDER_H
21 #define QGSRASTERDATAPROVIDER_H
22 
23 #include <QDateTime>
24 
25 #include "qgslogger.h"
26 #include "qgsrectangle.h"
27 #include "qgsdataprovider.h"
28 #include "qgscolorrampshader.h"
29 #include "qgsrasterpyramid.h"
31 #include "qgsrasterbandstats.h"
32 #include "cpl_conv.h"
33 #include <cmath>
34 
35 class QImage;
36 class QgsPoint;
37 class QByteArray;
38 
39 #define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
40 
41 
49 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
50 {
51 
52  Q_OBJECT
53 
54  public:
55 
58  {
59  NoCapabilities = 0,
60  Identify = 1,
61  ExactMinimumMaximum = 1 << 1,
62  ExactResolution = 1 << 2,
63  EstimatedMinimumMaximum = 1 << 3,
64  BuildPyramids = 1 << 4,
65  Histogram = 1 << 5,
66  Size = 1 << 6 // has fixed source type
67  };
68 
69  // This is modified copy of GDALDataType
70  enum DataType
71  { UnknownDataType = 0, Byte = 1, UInt16 = 2, Int16 = 3, UInt32 = 4, Int32 = 5, Float32 = 6, Float64 = 7, CInt16 = 8, CInt32 = 9, CFloat32 = 10, CFloat64 = 11, ARGBDataType = 12,
85  TypeCount = 13 /* maximum type # + 1 */
86  };
87 
88  // This is modified copy of GDALColorInterp
90  {
91  UndefinedColorInterpretation = 0, GrayIndex = 1, PaletteIndex = 2, RedBand = 3, GreenBand = 4, BlueBand = 5, AlphaBand = 6, HueBand = 7, SaturationBand = 8, LightnessBand = 9, CyanBand = 10, MagentaBand = 11, YellowBand = 12, BlackBand = 13, YCbCr_YBand = 14, YCbCr_CbBand = 15, YCbCr_CrBand = 16, ColorInterpretationMax = 16
109  };
110 
111  // Progress types
113  {
114  ProgressHistogram = 0,
115  ProgressPyramids = 1,
116  ProgressStatistics = 2
117  };
118 
120 
121  QgsRasterDataProvider( QString const & uri );
122 
124 
125 
129  virtual void addLayers( QStringList const & layers,
130  QStringList const & styles = QStringList() ) = 0;
131 
133  virtual QStringList supportedImageEncodings() = 0;
134 
138  virtual QString imageEncoding() const = 0;
139 
143  virtual void setImageEncoding( QString const & mimeType ) = 0;
144 
148  virtual void setImageCrs( QString const & crs ) = 0;
149 
150 
151  // TODO: Document this better.
154  virtual QImage* draw( QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight ) = 0;
155 
161  virtual int capabilities() const
162  {
164  }
165 
169  QString capabilitiesString() const;
170 
171 
172  // TODO: Get the supported formats by this provider
173 
174  // TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
175 
177  virtual int dataType( int bandNo ) const
178  {
179  return srcDataType( bandNo );
180  }
181 
185  virtual int srcDataType( int bandNo ) const
186  {
187  Q_UNUSED( bandNo );
189  }
190 
191  int typeSize( int dataType ) const
192  {
193  // modified copy from GDAL
194  switch ( dataType )
195  {
196  case Byte:
197  return 8;
198 
199  case UInt16:
200  case Int16:
201  return 16;
202 
203  case UInt32:
204  case Int32:
205  case Float32:
206  case CInt16:
207  return 32;
208 
209  case Float64:
210  case CInt32:
211  case CFloat32:
212  return 64;
213 
214  case CFloat64:
215  return 128;
216 
217  case ARGBDataType:
218  return 32;
219 
220  default:
221  return 0;
222  }
223  }
224  int dataTypeSize( int bandNo ) const
225  {
226  return typeSize( dataType( bandNo ) );
227  }
228 
230  virtual int bandCount() const
231  {
232  return 1;
233  }
234 
236  virtual int colorInterpretation( int theBandNo ) const
237  {
238  Q_UNUSED( theBandNo );
240  }
241 
242  QString colorName( int colorInterpretation ) const
243  {
244  // Modified copy from GDAL
245  switch ( colorInterpretation )
246  {
247  case UndefinedColorInterpretation:
248  return "Undefined";
249 
250  case GrayIndex:
251  return "Gray";
252 
253  case PaletteIndex:
254  return "Palette";
255 
256  case RedBand:
257  return "Red";
258 
259  case GreenBand:
260  return "Green";
261 
262  case BlueBand:
263  return "Blue";
264 
265  case AlphaBand:
266  return "Alpha";
267 
268  case HueBand:
269  return "Hue";
270 
271  case SaturationBand:
272  return "Saturation";
273 
274  case LightnessBand:
275  return "Lightness";
276 
277  case CyanBand:
278  return "Cyan";
279 
280  case MagentaBand:
281  return "Magenta";
282 
283  case YellowBand:
284  return "Yellow";
285 
286  case BlackBand:
287  return "Black";
288 
289  case YCbCr_YBand:
290  return "YCbCr_Y";
291 
292  case YCbCr_CbBand:
293  return "YCbCr_Cb";
294 
295  case YCbCr_CrBand:
296  return "YCbCr_Cr";
297 
298  default:
299  return "Unknown";
300  }
301  }
303  virtual bool reload( ) { return true; }
304 
305  virtual QString colorInterpretationName( int theBandNo ) const
306  {
307  return colorName( colorInterpretation( theBandNo ) );
308  }
309 
311  virtual int xBlockSize() const { return 0; }
312  virtual int yBlockSize() const { return 0; }
313 
315  virtual int xSize() const { return 0; }
316  virtual int ySize() const { return 0; }
317 
319  // TODO clarify what happens on the last block (the part outside raster)
320  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
321  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
322 
324  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
325  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
326 
328  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );
329 
330  /* Read a value from a data block at a given index. */
331  virtual double readValue( void *data, int type, int index );
332 
334  virtual double noDataValue() const { return 0; }
335 
336  virtual double minimumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
337  virtual double maximumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
338 
339  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
340  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
341 
342  // Defined in parent
344  virtual QStringList subLayers() const
345  {
346  return QStringList();
347  }
348 
351  virtual void populateHistogram( int theBandNoInt,
352  QgsRasterBandStats & theBandStats,
353  int theBinCountInt = 256,
354  bool theIgnoreOutOfRangeFlag = true,
355  bool theThoroughBandScanFlag = false
356  )
357  { Q_UNUSED( theBandNoInt ); Q_UNUSED( theBandStats ); Q_UNUSED( theBinCountInt ); Q_UNUSED( theIgnoreOutOfRangeFlag ); Q_UNUSED( theThoroughBandScanFlag ); }
358 
360  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
361  const QString & theResamplingMethod = "NEAREST",
362  bool theTryInternalFlag = false )
363  { Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theTryInternalFlag ); return "FAILED_NOT_SUPPORTED"; };
364 
370  virtual QList<QgsRasterPyramid> buildPyramidList() { return QList<QgsRasterPyramid>(); };
371 
375  virtual QgsRasterBandStats bandStatistics( int theBandNo );
376 
378  QString generateBandName( int theBandNumber )
379  {
380  return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
381  };
382 
387  virtual QString metadata() = 0;
388 
390  virtual bool identify( const QgsPoint & point, QMap<QString, QString>& results );
391 
405  virtual QString identifyAsText( const QgsPoint& point ) = 0;
406 
422  virtual QString identifyAsHtml( const QgsPoint& point ) = 0;
423 
433  virtual QString lastErrorTitle() = 0;
434 
444  virtual QString lastError() = 0;
445 
451  virtual QString lastErrorFormat();
452 
453  //virtual void buildSupportedRasterFileFilter( QString & theFileFiltersString ) ;
454 
461  //virtual bool isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg ) { return false; } ;
462 
463  //virtual bool isValidRasterFileName( const QString & theFileNameQString ) { return false; };
464 
465 
468  int dpi() const {return mDpi;}
469 
472  void setDpi( int dpi ) {mDpi = dpi;}
473 
475  bool isNoDataValueValid() const { return mValidNoDataValue; }
476 
477  static QStringList cStringList2Q_( char ** stringList );
478 
479  static QString makeTableCell( QString const & value );
480  static QString makeTableCells( QStringList const & values );
481 
483  QByteArray noValueBytes( int theBandNo );
484 
486  virtual QDateTime timestamp() const { return mTimestamp; }
487 
489  virtual QDateTime dataTimestamp() const { return QDateTime(); }
490 
491  signals:
494  void progress( int theType, double theProgress, QString theMessage );
495 
496  protected:
500  int mDpi;
501 
503  QList<double> mNoDataValue;
504 
507 
509 };
510 
511 #endif