Quantum GIS API Documentation  1.8
src/core/qgsrasterdataprovider.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsrasterdataprovider.h - DataProvider Interface for raster layers
00003      --------------------------------------
00004     Date                 : Mar 11, 2005
00005     Copyright            : (C) 2005 by Brendan Morley
00006     email                : morb at ozemail dot com dot au
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 /* Thank you to Marco Hugentobler for the original vector DataProvider */
00019 
00020 #ifndef QGSRASTERDATAPROVIDER_H
00021 #define QGSRASTERDATAPROVIDER_H
00022 
00023 #include <QDateTime>
00024 
00025 #include "qgslogger.h"
00026 #include "qgsrectangle.h"
00027 #include "qgsdataprovider.h"
00028 #include "qgscolorrampshader.h"
00029 #include "qgsrasterpyramid.h"
00030 #include "qgscoordinatereferencesystem.h"
00031 #include "qgsrasterbandstats.h"
00032 
00033 #include "cpl_conv.h"
00034 #include <cmath>
00035 
00036 class QImage;
00037 class QgsPoint;
00038 class QByteArray;
00039 
00040 #define TINY_VALUE  std::numeric_limits<double>::epsilon() * 20
00041 
00042 
00050 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
00051 {
00052 
00053     Q_OBJECT
00054 
00055   public:
00056 
00058     enum Capability
00059     {
00060       NoCapabilities =          0,
00061       Identify =                1,
00062       ExactMinimumMaximum =     1 << 1,
00063       ExactResolution =         1 << 2,
00064       EstimatedMinimumMaximum = 1 << 3,
00065       BuildPyramids =           1 << 4,
00066       Histogram =               1 << 5,
00067       Size =                    1 << 6  // has fixed source type
00068     };
00069 
00070     // This is modified copy of GDALDataType
00071     enum DataType
00072     {          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,
00086       TypeCount = 13          /* maximum type # + 1 */
00087     };
00088 
00089     // This is modified copy of GDALColorInterp
00090     enum ColorInterpretation
00091     {
00092       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
00110     };
00111 
00112     // Progress types
00113     enum RasterProgressType
00114     {
00115       ProgressHistogram = 0,
00116       ProgressPyramids  = 1,
00117       ProgressStatistics = 2
00118     };
00119 
00120     QgsRasterDataProvider();
00121 
00122     QgsRasterDataProvider( QString const & uri );
00123 
00124     virtual ~QgsRasterDataProvider() {};
00125 
00126 
00130     virtual void addLayers( QStringList const & layers,
00131                             QStringList  const & styles = QStringList() ) = 0;
00132 
00134     virtual QStringList supportedImageEncodings() = 0;
00135 
00139     virtual QString imageEncoding() const = 0;
00140 
00144     virtual void setImageEncoding( QString  const & mimeType ) = 0;
00145 
00149     virtual void setImageCrs( QString const & crs ) = 0;
00150 
00151 
00152     // TODO: Document this better.
00155     virtual QImage* draw( QgsRectangle  const & viewExtent, int pixelWidth, int pixelHeight ) = 0;
00156 
00162     virtual int capabilities() const
00163     {
00164       return QgsRasterDataProvider::NoCapabilities;
00165     }
00166 
00170     QString capabilitiesString() const;
00171 
00172 
00173     // TODO: Get the supported formats by this provider
00174 
00175     // TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
00176 
00178     virtual int dataType( int bandNo ) const
00179     {
00180       return srcDataType( bandNo );
00181     }
00182 
00186     virtual int srcDataType( int bandNo ) const
00187     {
00188       Q_UNUSED( bandNo );
00189       return QgsRasterDataProvider::UnknownDataType;
00190     }
00191 
00192     int typeSize( int dataType ) const
00193     {
00194       // modified copy from GDAL
00195       switch ( dataType )
00196       {
00197         case Byte:
00198           return 8;
00199 
00200         case UInt16:
00201         case Int16:
00202           return 16;
00203 
00204         case UInt32:
00205         case Int32:
00206         case Float32:
00207         case CInt16:
00208           return 32;
00209 
00210         case Float64:
00211         case CInt32:
00212         case CFloat32:
00213           return 64;
00214 
00215         case CFloat64:
00216           return 128;
00217 
00218         case ARGBDataType:
00219           return 32;
00220 
00221         default:
00222           return 0;
00223       }
00224     }
00225     int dataTypeSize( int bandNo ) const
00226     {
00227       return typeSize( dataType( bandNo ) );
00228     }
00229 
00231     virtual int bandCount() const
00232     {
00233       return 1;
00234     }
00235 
00237     virtual int colorInterpretation( int theBandNo ) const
00238     {
00239       Q_UNUSED( theBandNo );
00240       return QgsRasterDataProvider::UndefinedColorInterpretation;
00241     }
00242 
00243     QString colorName( int colorInterpretation ) const
00244     {
00245       // Modified copy from GDAL
00246       switch ( colorInterpretation )
00247       {
00248         case UndefinedColorInterpretation:
00249           return "Undefined";
00250 
00251         case GrayIndex:
00252           return "Gray";
00253 
00254         case PaletteIndex:
00255           return "Palette";
00256 
00257         case RedBand:
00258           return "Red";
00259 
00260         case GreenBand:
00261           return "Green";
00262 
00263         case BlueBand:
00264           return "Blue";
00265 
00266         case AlphaBand:
00267           return "Alpha";
00268 
00269         case HueBand:
00270           return "Hue";
00271 
00272         case SaturationBand:
00273           return "Saturation";
00274 
00275         case LightnessBand:
00276           return "Lightness";
00277 
00278         case CyanBand:
00279           return "Cyan";
00280 
00281         case MagentaBand:
00282           return "Magenta";
00283 
00284         case YellowBand:
00285           return "Yellow";
00286 
00287         case BlackBand:
00288           return "Black";
00289 
00290         case YCbCr_YBand:
00291           return "YCbCr_Y";
00292 
00293         case YCbCr_CbBand:
00294           return "YCbCr_Cb";
00295 
00296         case YCbCr_CrBand:
00297           return "YCbCr_Cr";
00298 
00299         default:
00300           return "Unknown";
00301       }
00302     }
00304     virtual bool reload( ) { return true; }
00305 
00306     virtual QString colorInterpretationName( int theBandNo ) const
00307     {
00308       return colorName( colorInterpretation( theBandNo ) );
00309     }
00310 
00312     virtual int xBlockSize() const { return 0; }
00313     virtual int yBlockSize() const { return 0; }
00314 
00316     virtual int xSize() const { return 0; }
00317     virtual int ySize() const { return 0; }
00318 
00320     // TODO clarify what happens on the last block (the part outside raster)
00321     virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
00322     { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
00323 
00325     virtual void readBlock( int bandNo, QgsRectangle  const & viewExtent, int width, int height, void *data )
00326     { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
00327 
00329     virtual void readBlock( int bandNo, QgsRectangle  const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );
00330 
00331     /* Read a value from a data block at a given index. */
00332     virtual double readValue( void *data, int type, int index );
00333 
00335     virtual double noDataValue() const { return 0; }
00336 
00337     virtual double minimumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
00338     virtual double maximumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
00339 
00340     virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
00341     { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
00342 
00343     // Defined in parent
00345     virtual QStringList subLayers() const
00346     {
00347       return QStringList();
00348     }
00349 
00352     virtual void populateHistogram( int theBandNoInt,
00353                                     QgsRasterBandStats & theBandStats,
00354                                     int theBinCountInt = 256,
00355                                     bool theIgnoreOutOfRangeFlag = true,
00356                                     bool theThoroughBandScanFlag = false
00357                                   )
00358     { Q_UNUSED( theBandNoInt ); Q_UNUSED( theBandStats ); Q_UNUSED( theBinCountInt ); Q_UNUSED( theIgnoreOutOfRangeFlag ); Q_UNUSED( theThoroughBandScanFlag ); }
00359 
00361     virtual QString buildPyramids( const QList<QgsRasterPyramid>  & thePyramidList,
00362                                    const QString &  theResamplingMethod = "NEAREST",
00363                                    bool theTryInternalFlag = false )
00364     { Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theTryInternalFlag ); return "FAILED_NOT_SUPPORTED"; };
00365 
00371     virtual QList<QgsRasterPyramid> buildPyramidList() { return QList<QgsRasterPyramid>(); };
00372 
00376     virtual QgsRasterBandStats bandStatistics( int theBandNo );
00377 
00379     QString  generateBandName( int theBandNumber )
00380     {
00381       return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber,  1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
00382     }
00383 
00388     virtual QString metadata() = 0;
00389 
00391     virtual bool identify( const QgsPoint & point, QMap<QString, QString>& results );
00392 
00406     virtual QString identifyAsText( const QgsPoint& point ) = 0;
00407 
00423     virtual QString identifyAsHtml( const QgsPoint& point ) = 0;
00424 
00434     virtual QString lastErrorTitle() = 0;
00435 
00445     virtual QString lastError() = 0;
00446 
00452     virtual QString lastErrorFormat();
00453 
00454     //virtual void buildSupportedRasterFileFilter( QString & theFileFiltersString ) ;
00455 
00462     //virtual bool isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg ) { return false; } ;
00463 
00464     //virtual bool isValidRasterFileName( const QString & theFileNameQString ) { return false; };
00465 
00466 
00469     int dpi() const {return mDpi;}
00470 
00473     void setDpi( int dpi ) {mDpi = dpi;}
00474 
00476     bool isNoDataValueValid() const { return mValidNoDataValue; }
00477 
00478     static QStringList cStringList2Q_( char ** stringList );
00479 
00480     static QString makeTableCell( QString const & value );
00481     static QString makeTableCells( QStringList const & values );
00482 
00484     QByteArray noValueBytes( int theBandNo );
00485 
00487     virtual QDateTime timestamp() const { return mTimestamp; }
00488 
00490     virtual QDateTime dataTimestamp() const { return QDateTime(); }
00491 
00492   signals:
00495     void progress( int theType, double theProgress, QString theMessage );
00496 
00497   protected:
00501     int mDpi;
00502 
00504     QList<double> mNoDataValue;
00505 
00507     bool mValidNoDataValue;
00508 
00509     QgsRectangle mExtent;
00510 };
00511 
00512 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines