|
Quantum GIS API Documentation
master-693a1fe
|
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 <cmath> 00024 00025 #include <QDateTime> 00026 #include <QVariant> 00027 00028 #include "qgscolorrampshader.h" 00029 #include "qgscoordinatereferencesystem.h" 00030 #include "qgsdataprovider.h" 00031 #include "qgserror.h" 00032 #include "qgsfeature.h" 00033 #include "qgsfield.h" 00034 #include "qgslogger.h" 00035 #include "qgsrasterbandstats.h" 00036 #include "qgsraster.h" 00037 #include "qgsrasterhistogram.h" 00038 #include "qgsrasterinterface.h" 00039 #include "qgsrasterpyramid.h" 00040 #include "qgsrasterrange.h" 00041 #include "qgsrectangle.h" 00042 00043 class QImage; 00044 class QByteArray; 00045 00046 class QgsPoint; 00047 class QgsRasterIdentifyResult; 00048 00052 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface 00053 { 00054 Q_OBJECT 00055 00056 public: 00057 QgsRasterDataProvider(); 00058 00059 QgsRasterDataProvider( const QString & uri ); 00060 00061 virtual ~QgsRasterDataProvider() {}; 00062 00063 virtual QgsRasterInterface * clone() const = 0; 00064 00065 /* It makes no sense to set input on provider */ 00066 bool setInput( QgsRasterInterface* input ) { Q_UNUSED( input ); return false; } 00067 00069 virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0; 00070 00073 virtual QgsRectangle extent() = 0; 00074 00076 virtual QGis::DataType dataType( int bandNo ) const = 0; 00077 00080 virtual QGis::DataType srcDataType( int bandNo ) const = 0; 00081 00083 virtual int colorInterpretation( int theBandNo ) const 00084 { 00085 Q_UNUSED( theBandNo ); 00086 return QgsRaster::UndefinedColorInterpretation; 00087 } 00088 00089 QString colorName( int colorInterpretation ) const 00090 { 00091 // Modified copy from GDAL 00092 switch ( colorInterpretation ) 00093 { 00094 case QgsRaster::UndefinedColorInterpretation: 00095 return "Undefined"; 00096 00097 case QgsRaster::GrayIndex: 00098 return "Gray"; 00099 00100 case QgsRaster::PaletteIndex: 00101 return "Palette"; 00102 00103 case QgsRaster::RedBand: 00104 return "Red"; 00105 00106 case QgsRaster::GreenBand: 00107 return "Green"; 00108 00109 case QgsRaster::BlueBand: 00110 return "Blue"; 00111 00112 case QgsRaster::AlphaBand: 00113 return "Alpha"; 00114 00115 case QgsRaster::HueBand: 00116 return "Hue"; 00117 00118 case QgsRaster::SaturationBand: 00119 return "Saturation"; 00120 00121 case QgsRaster::LightnessBand: 00122 return "Lightness"; 00123 00124 case QgsRaster::CyanBand: 00125 return "Cyan"; 00126 00127 case QgsRaster::MagentaBand: 00128 return "Magenta"; 00129 00130 case QgsRaster::YellowBand: 00131 return "Yellow"; 00132 00133 case QgsRaster::BlackBand: 00134 return "Black"; 00135 00136 case QgsRaster::YCbCr_YBand: 00137 return "YCbCr_Y"; 00138 00139 case QgsRaster::YCbCr_CbBand: 00140 return "YCbCr_Cb"; 00141 00142 case QgsRaster::YCbCr_CrBand: 00143 return "YCbCr_Cr"; 00144 00145 default: 00146 return "Unknown"; 00147 } 00148 } 00150 virtual bool reload() { return true; } 00151 00152 virtual QString colorInterpretationName( int theBandNo ) const 00153 { 00154 return colorName( colorInterpretation( theBandNo ) ); 00155 } 00156 00157 // TODO: remove or make protected all readBlock working with void* 00158 00160 virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight ); 00161 00162 /* Return true if source band has no data value */ 00163 virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); } 00164 00166 virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); } 00167 00169 virtual void setUseSrcNoDataValue( int bandNo, bool use ); 00170 00172 virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); } 00173 00174 virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData ); 00175 00177 virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); } 00178 00179 virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const 00180 { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); } 00181 00184 virtual QStringList subLayers() const 00185 { 00186 return QStringList(); 00187 } 00188 00190 virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList, 00191 const QString & theResamplingMethod = "NEAREST", 00192 QgsRaster::RasterPyramidsFormat theFormat = QgsRaster::PyramidsGTiff, 00193 const QStringList & theConfigOptions = QStringList() ) 00194 { 00195 Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod ); 00196 Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions ); 00197 return "FAILED_NOT_SUPPORTED"; 00198 }; 00199 00207 virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) 00208 { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }; 00209 00211 bool hasPyramids(); 00212 00217 virtual QString metadata() = 0; 00218 00241 //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 ); 00242 virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 ); 00243 00253 virtual QString lastErrorTitle() = 0; 00254 00264 virtual QString lastError() = 0; 00265 00271 virtual QString lastErrorFormat(); 00272 00275 int dpi() const {return mDpi;} 00276 00279 void setDpi( int dpi ) {mDpi = dpi;} 00280 00282 virtual QDateTime timestamp() const { return mTimestamp; } 00283 00285 virtual QDateTime dataTimestamp() const { return QDateTime(); } 00286 00288 // TODO: add data type (may be defferent from band type) 00289 virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset ) 00290 { 00291 Q_UNUSED( data ); 00292 Q_UNUSED( band ); 00293 Q_UNUSED( width ); 00294 Q_UNUSED( height ); 00295 Q_UNUSED( xOffset ); 00296 Q_UNUSED( yOffset ); 00297 return false; 00298 } 00299 00301 static QgsRasterDataProvider* create( const QString &providerKey, 00302 const QString &uri, 00303 const QString& format, int nBands, 00304 QGis::DataType type, 00305 int width, int height, double* geoTransform, 00306 const QgsCoordinateReferenceSystem& crs, 00307 QStringList createOptions = QStringList() ); 00308 00313 virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; } 00314 00316 // TODO: this should be static and call C functions in provider library 00317 //static QStringList createFormats(); 00318 00320 virtual bool remove() { return false; } 00321 00324 static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey ); 00325 00329 virtual QString validateCreationOptions( const QStringList& createOptions, QString format ) 00330 { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); } 00331 00334 virtual QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat, 00335 const QStringList & theConfigOptions, const QString & fileFormat ) 00336 { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); } 00337 00338 static QString identifyFormatName( QgsRaster::IdentifyFormat format ); 00339 static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName ); 00340 static QString identifyFormatLabel( QgsRaster::IdentifyFormat format ); 00341 static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format ); 00342 00343 signals: 00346 void progress( int theType, double theProgress, QString theMessage ); 00347 void progressUpdate( int theProgress ); 00348 00349 protected: 00352 virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ) 00353 { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); } 00354 00357 virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data ) 00358 { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); } 00359 00361 bool userNoDataValuesContains( int bandNo, double value ) const; 00362 00363 static QStringList cStringList2Q_( char ** stringList ); 00364 00365 static QString makeTableCell( const QString & value ); 00366 static QString makeTableCells( const QStringList & values ); 00367 00371 int mDpi; 00372 00375 //bool hasNoDataValue ( int theBandNo ); 00376 00378 QList<double> mSrcNoDataValue; 00379 00381 QList<bool> mSrcHasNoDataValue; 00382 00386 QList<bool> mUseSrcNoDataValue; 00387 00390 QList< QgsRasterRangeList > mUserNoDataValue; 00391 00392 QgsRectangle mExtent; 00393 00394 static void initPyramidResamplingDefs(); 00395 static QStringList mPyramidResamplingListGdal; 00396 static QgsStringMap mPyramidResamplingMapGdal; 00397 00398 }; 00399 #endif