Quantum GIS API Documentation  1.7.4
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 #include "cpl_conv.h"
00033 #include <cmath>
00034 
00035 class QImage;
00036 class QgsPoint;
00037 class QByteArray;
00038 
00039 #define TINY_VALUE  std::numeric_limits<double>::epsilon() * 20
00040 
00041 
00049 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
00050 {
00051 
00052     Q_OBJECT
00053 
00054   public:
00055 
00057     enum Capability
00058     {
00059       NoCapabilities =          0,
00060       Identify =                1,
00061       ExactMinimumMaximum =     1 << 1,
00062       ExactResolution =         1 << 2,
00063       EstimatedMinimumMaximum = 1 << 3,
00064       BuildPyramids =           1 << 4,
00065       Histogram =               1 << 5,
00066       Size =                    1 << 6  // has fixed source type
00067     };
00068 
00069     // This is modified copy of GDALDataType
00070     enum DataType
00071     {          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,
00085       TypeCount = 13          /* maximum type # + 1 */
00086     };
00087 
00088     // This is modified copy of GDALColorInterp
00089     enum ColorInterpretation
00090     {
00091       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
00109     };
00110 
00111     // Progress types
00112     enum RasterProgressType
00113     {
00114       ProgressHistogram = 0,
00115       ProgressPyramids  = 1,
00116       ProgressStatistics = 2
00117     };
00118 
00119     QgsRasterDataProvider();
00120 
00121     QgsRasterDataProvider( QString const & uri );
00122 
00123     virtual ~QgsRasterDataProvider() {};
00124 
00125 
00129     virtual void addLayers( QStringList const & layers,
00130                             QStringList  const & styles = QStringList() ) = 0;
00131 
00133     virtual QStringList supportedImageEncodings() = 0;
00134 
00138     virtual QString imageEncoding() const = 0;
00139 
00143     virtual void setImageEncoding( QString  const & mimeType ) = 0;
00144 
00148     virtual void setImageCrs( QString const & crs ) = 0;
00149 
00150 
00151     // TODO: Document this better.
00154     virtual QImage* draw( QgsRectangle  const & viewExtent, int pixelWidth, int pixelHeight ) = 0;
00155 
00161     virtual int capabilities() const
00162     {
00163       return QgsRasterDataProvider::NoCapabilities;
00164     }
00165 
00169     QString capabilitiesString() const;
00170 
00171 
00172     // TODO: Get the supported formats by this provider
00173 
00174     // TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
00175 
00177     virtual int dataType( int bandNo ) const
00178     {
00179       return srcDataType( bandNo );
00180     }
00181 
00185     virtual int srcDataType( int bandNo ) const
00186     {
00187       Q_UNUSED( bandNo );
00188       return QgsRasterDataProvider::UnknownDataType;
00189     }
00190 
00191     int typeSize( int dataType ) const
00192     {
00193       // modified copy from GDAL
00194       switch ( dataType )
00195       {
00196         case Byte:
00197           return 8;
00198 
00199         case UInt16:
00200         case Int16:
00201           return 16;
00202 
00203         case UInt32:
00204         case Int32:
00205         case Float32:
00206         case CInt16:
00207           return 32;
00208 
00209         case Float64:
00210         case CInt32:
00211         case CFloat32:
00212           return 64;
00213 
00214         case CFloat64:
00215           return 128;
00216 
00217         case ARGBDataType:
00218           return 32;
00219 
00220         default:
00221           return 0;
00222       }
00223     }
00224     int dataTypeSize( int bandNo ) const
00225     {
00226       return typeSize( dataType( bandNo ) );
00227     }
00228 
00230     virtual int bandCount() const
00231     {
00232       return 1;
00233     }
00234 
00236     virtual int colorInterpretation( int theBandNo ) const
00237     {
00238       Q_UNUSED( theBandNo );
00239       return QgsRasterDataProvider::UndefinedColorInterpretation;
00240     }
00241 
00242     QString colorName( int colorInterpretation ) const
00243     {
00244       // Modified copy from GDAL
00245       switch ( colorInterpretation )
00246       {
00247         case UndefinedColorInterpretation:
00248           return "Undefined";
00249 
00250         case GrayIndex:
00251           return "Gray";
00252 
00253         case PaletteIndex:
00254           return "Palette";
00255 
00256         case RedBand:
00257           return "Red";
00258 
00259         case GreenBand:
00260           return "Green";
00261 
00262         case BlueBand:
00263           return "Blue";
00264 
00265         case AlphaBand:
00266           return "Alpha";
00267 
00268         case HueBand:
00269           return "Hue";
00270 
00271         case SaturationBand:
00272           return "Saturation";
00273 
00274         case LightnessBand:
00275           return "Lightness";
00276 
00277         case CyanBand:
00278           return "Cyan";
00279 
00280         case MagentaBand:
00281           return "Magenta";
00282 
00283         case YellowBand:
00284           return "Yellow";
00285 
00286         case BlackBand:
00287           return "Black";
00288 
00289         case YCbCr_YBand:
00290           return "YCbCr_Y";
00291 
00292         case YCbCr_CbBand:
00293           return "YCbCr_Cb";
00294 
00295         case YCbCr_CrBand:
00296           return "YCbCr_Cr";
00297 
00298         default:
00299           return "Unknown";
00300       }
00301     }
00303     virtual bool reload( ) { return true; }
00304 
00305     virtual QString colorInterpretationName( int theBandNo ) const
00306     {
00307       return colorName( colorInterpretation( theBandNo ) );
00308     }
00309 
00311     virtual int xBlockSize() const { return 0; }
00312     virtual int yBlockSize() const { return 0; }
00313 
00315     virtual int xSize() const { return 0; }
00316     virtual int ySize() const { return 0; }
00317 
00319     // TODO clarify what happens on the last block (the part outside raster)
00320     virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
00321     { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
00322 
00324     virtual void readBlock( int bandNo, QgsRectangle  const & viewExtent, int width, int height, void *data )
00325     { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
00326 
00328     virtual void readBlock( int bandNo, QgsRectangle  const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );
00329     
00330     /* Read a value from a data block at a given index. */
00331     virtual double readValue( void *data, int type, int index );
00332 
00334     virtual double noDataValue() const { return 0; }
00335 
00336     virtual double minimumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
00337     virtual double maximumValue( int bandNo ) const { Q_UNUSED( bandNo ); return 0; }
00338 
00339     virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
00340     { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
00341 
00342     // Defined in parent
00344     virtual QStringList subLayers() const
00345     {
00346       return QStringList();
00347     }
00348 
00351     virtual void populateHistogram( int theBandNoInt,
00352                                     QgsRasterBandStats & theBandStats,
00353                                     int theBinCountInt = 256,
00354                                     bool theIgnoreOutOfRangeFlag = true,
00355                                     bool theThoroughBandScanFlag = false
00356                                   )
00357     { Q_UNUSED( theBandNoInt ); Q_UNUSED( theBandStats ); Q_UNUSED( theBinCountInt ); Q_UNUSED( theIgnoreOutOfRangeFlag ); Q_UNUSED( theThoroughBandScanFlag ); }
00358 
00360     virtual QString buildPyramids( const QList<QgsRasterPyramid>  & thePyramidList,
00361                                    const QString &  theResamplingMethod = "NEAREST",
00362                                    bool theTryInternalFlag = false )
00363     { Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); Q_UNUSED( theTryInternalFlag ); return "FAILED_NOT_SUPPORTED"; };
00364 
00370     virtual QList<QgsRasterPyramid> buildPyramidList() { return QList<QgsRasterPyramid>(); };
00371 
00375     virtual QgsRasterBandStats bandStatistics( int theBandNo );
00376 
00378     QString  generateBandName( int theBandNumber )
00379     {
00380       return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber,  1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
00381     };
00382 
00387     virtual QString metadata() = 0;
00388 
00390     virtual bool identify( const QgsPoint & point, QMap<QString, QString>& results );
00391 
00405     virtual QString identifyAsText( const QgsPoint& point ) = 0;
00406 
00422     virtual QString identifyAsHtml( const QgsPoint& point ) = 0;
00423 
00433     virtual QString lastErrorTitle() = 0;
00434 
00444     virtual QString lastError() = 0;
00445 
00451     virtual QString lastErrorFormat();
00452 
00453     //virtual void buildSupportedRasterFileFilter( QString & theFileFiltersString ) ;
00454 
00461     //virtual bool isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg ) { return false; } ;
00462 
00463     //virtual bool isValidRasterFileName( const QString & theFileNameQString ) { return false; };
00464 
00465 
00468     int dpi() const {return mDpi;}
00469 
00472     void setDpi( int dpi ) {mDpi = dpi;}
00473 
00475     bool isNoDataValueValid() const { return mValidNoDataValue; }
00476 
00477     static QStringList cStringList2Q_( char ** stringList );
00478 
00479     static QString makeTableCell( QString const & value );
00480     static QString makeTableCells( QStringList const & values );
00481 
00483     QByteArray noValueBytes( int theBandNo );
00484 
00486     virtual QDateTime timestamp() const { return mTimestamp; }
00487 
00489     virtual QDateTime dataTimestamp() const { return QDateTime(); }
00490 
00491   signals:
00494     void progress( int theType, double theProgress, QString theMessage );
00495 
00496   protected:
00500     int mDpi;
00501 
00503     QList<double> mNoDataValue;
00504 
00506     bool mValidNoDataValue;
00507 
00508     QgsRectangle mExtent;
00509 };
00510 
00511 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines