00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef GDAL_PRIV_H_INCLUDED
00032 #define GDAL_PRIV_H_INCLUDED
00033
00034
00035
00036
00037
00038 class GDALMajorObject;
00039 class GDALDataset;
00040 class GDALRasterBand;
00041 class GDALDriver;
00042 class GDALRasterAttributeTable;
00043
00044
00045
00046
00047
00048
00049
00050 #include "gdal.h"
00051 #include "gdal_frmts.h"
00052 #include "cpl_vsi.h"
00053 #include "cpl_conv.h"
00054 #include "cpl_string.h"
00055 #include "cpl_minixml.h"
00056 #include <vector>
00057
00058 #define GMO_VALID 0x0001
00059 #define GMO_IGNORE_UNIMPLEMENTED 0x0002
00060 #define GMO_SUPPORT_MD 0x0004
00061 #define GMO_SUPPORT_MDMD 0x0008
00062 #define GMO_MD_DIRTY 0x0010
00063 #define GMO_PAM_CLASS 0x0020
00064
00065
00066
00067
00068
00069 class CPL_DLL GDALMultiDomainMetadata
00070 {
00071 private:
00072 char **papszDomainList;
00073 char ***papapszMetadataLists;
00074
00075 public:
00076 GDALMultiDomainMetadata();
00077 ~GDALMultiDomainMetadata();
00078
00079 int XMLInit( CPLXMLNode *psMetadata, int bMerge );
00080 CPLXMLNode *Serialize();
00081
00082 char **GetDomainList() { return papszDomainList; }
00083
00084 char **GetMetadata( const char * pszDomain = "" );
00085 CPLErr SetMetadata( char ** papszMetadata,
00086 const char * pszDomain = "" );
00087 const char *GetMetadataItem( const char * pszName,
00088 const char * pszDomain = "" );
00089 CPLErr SetMetadataItem( const char * pszName,
00090 const char * pszValue,
00091 const char * pszDomain = "" );
00092
00093 void Clear();
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00104
00105 class CPL_DLL GDALMajorObject
00106 {
00107 protected:
00108 int nFlags;
00109 CPLString sDescription;
00110 GDALMultiDomainMetadata oMDMD;
00111
00112 public:
00113 GDALMajorObject();
00114 virtual ~GDALMajorObject();
00115
00116 int GetMOFlags();
00117 void SetMOFlags(int nFlags);
00118
00119 virtual const char *GetDescription() const;
00120 virtual void SetDescription( const char * );
00121
00122 virtual char **GetMetadata( const char * pszDomain = "" );
00123 virtual CPLErr SetMetadata( char ** papszMetadata,
00124 const char * pszDomain = "" );
00125 virtual const char *GetMetadataItem( const char * pszName,
00126 const char * pszDomain = "" );
00127 virtual CPLErr SetMetadataItem( const char * pszName,
00128 const char * pszValue,
00129 const char * pszDomain = "" );
00130 };
00131
00132
00133
00134
00135 class CPL_DLL GDALDefaultOverviews
00136 {
00137 GDALDataset *poDS;
00138 GDALDataset *poODS;
00139
00140 CPLString osOvrFilename;
00141
00142 int bOvrIsAux;
00143
00144 public:
00145 GDALDefaultOverviews();
00146 ~GDALDefaultOverviews();
00147
00148 void Initialize( GDALDataset *poDS, const char *pszName = NULL,
00149 int bNameIsOVR = FALSE );
00150 int IsInitialized() { return poDS != NULL; }
00151
00152 int GetOverviewCount(int);
00153 GDALRasterBand *GetOverview(int,int);
00154
00155 CPLErr BuildOverviews( const char * pszBasename,
00156 const char * pszResampling,
00157 int nOverviews, int * panOverviewList,
00158 int nBands, int * panBandList,
00159 GDALProgressFunc pfnProgress,
00160 void *pProgressData );
00161 };
00162
00163
00164
00165
00166
00168
00169 class CPL_DLL GDALDataset : public GDALMajorObject
00170 {
00171 friend GDALDatasetH CPL_STDCALL GDALOpen( const char *, GDALAccess);
00172 friend GDALDatasetH CPL_STDCALL GDALOpenShared( const char *, GDALAccess);
00173 friend class GDALDriver;
00174
00175 protected:
00176 GDALDriver *poDriver;
00177 GDALAccess eAccess;
00178
00179
00180 int nRasterXSize;
00181 int nRasterYSize;
00182 int nBands;
00183 GDALRasterBand **papoBands;
00184
00185 int bForceCachedIO;
00186
00187 int nRefCount;
00188 int bShared;
00189
00190 GDALDataset(void);
00191 void RasterInitialize( int, int );
00192 void SetBand( int, GDALRasterBand * );
00193
00194 GDALDefaultOverviews oOvManager;
00195
00196 virtual CPLErr IBuildOverviews( const char *, int, int *,
00197 int, int *, GDALProgressFunc, void * );
00198
00199 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00200 void *, int, int, GDALDataType,
00201 int, int *, int, int, int );
00202
00203 CPLErr BlockBasedRasterIO( GDALRWFlag, int, int, int, int,
00204 void *, int, int, GDALDataType,
00205 int, int *, int, int, int );
00206 void BlockBasedFlushCache();
00207
00208 friend class GDALRasterBand;
00209
00210 public:
00211 virtual ~GDALDataset();
00212
00213 int GetRasterXSize( void );
00214 int GetRasterYSize( void );
00215 int GetRasterCount( void );
00216 GDALRasterBand *GetRasterBand( int );
00217
00218 virtual void FlushCache(void);
00219
00220 virtual const char *GetProjectionRef(void);
00221 virtual CPLErr SetProjection( const char * );
00222
00223 virtual CPLErr GetGeoTransform( double * );
00224 virtual CPLErr SetGeoTransform( double * );
00225
00226 virtual CPLErr AddBand( GDALDataType eType,
00227 char **papszOptions=NULL );
00228
00229 virtual void *GetInternalHandle( const char * );
00230 virtual GDALDriver *GetDriver(void);
00231
00232 virtual int GetGCPCount();
00233 virtual const char *GetGCPProjection();
00234 virtual const GDAL_GCP *GetGCPs();
00235 virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
00236 const char *pszGCPProjection );
00237
00238 virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
00239 int nBufXSize, int nBufYSize,
00240 GDALDataType eDT,
00241 int nBandCount, int *panBandList,
00242 char **papszOptions );
00243
00244 CPLErr RasterIO( GDALRWFlag, int, int, int, int,
00245 void *, int, int, GDALDataType,
00246 int, int *, int, int, int );
00247
00248 int Reference();
00249 int Dereference();
00250 GDALAccess GetAccess() { return eAccess; }
00251
00252 int GetShared();
00253 void MarkAsShared();
00254
00255 static GDALDataset **GetOpenDatasets( int *pnDatasetCount );
00256
00257 CPLErr BuildOverviews( const char *, int, int *,
00258 int, int *, GDALProgressFunc, void * );
00259 };
00260
00261
00262
00263
00264
00267 class CPL_DLL GDALRasterBlock
00268 {
00269 GDALDataType eType;
00270
00271 int bDirty;
00272 int nLockCount;
00273
00274 int nXOff;
00275 int nYOff;
00276
00277 int nXSize;
00278 int nYSize;
00279
00280 void *pData;
00281
00282 GDALRasterBand *poBand;
00283
00284 GDALRasterBlock *poNext;
00285 GDALRasterBlock *poPrevious;
00286
00287 public:
00288 GDALRasterBlock( GDALRasterBand *, int, int );
00289 virtual ~GDALRasterBlock();
00290
00291 CPLErr Internalize( void );
00292 void Touch( void );
00293 void MarkDirty( void );
00294 void MarkClean( void );
00295 void AddLock( void ) { nLockCount++; }
00296 void DropLock( void ) { nLockCount--; }
00297 void Detach();
00298
00299 CPLErr Write();
00300
00301 GDALDataType GetDataType() { return eType; }
00302 int GetXOff() { return nXOff; }
00303 int GetYOff() { return nYOff; }
00304 int GetXSize() { return nXSize; }
00305 int GetYSize() { return nYSize; }
00306 int GetDirty() { return bDirty; }
00307 int GetLockCount() { return nLockCount; }
00308
00309 void *GetDataRef( void ) { return pData; }
00310
00311 GDALRasterBand *GetBand() { return poBand; }
00312
00313 static int FlushCacheBlock();
00314 static void Verify();
00315
00316 static int SafeLockBlock( GDALRasterBlock ** );
00317 };
00318
00319
00320
00321
00322
00323 class CPL_DLL GDALColorTable
00324 {
00325 GDALPaletteInterp eInterp;
00326
00327 std::vector<GDALColorEntry> aoEntries;
00328
00329 public:
00330 GDALColorTable( GDALPaletteInterp = GPI_RGB );
00331 ~GDALColorTable();
00332
00333 GDALColorTable *Clone() const;
00334
00335 GDALPaletteInterp GetPaletteInterpretation() const;
00336
00337 int GetColorEntryCount() const;
00338 const GDALColorEntry *GetColorEntry( int ) const;
00339 int GetColorEntryAsRGB( int, GDALColorEntry * ) const;
00340 void SetColorEntry( int, const GDALColorEntry * );
00341 };
00342
00343
00344
00345
00346
00348
00349 class CPL_DLL GDALRasterBand : public GDALMajorObject
00350 {
00351 protected:
00352 GDALDataset *poDS;
00353 int nBand;
00354
00355 int nRasterXSize;
00356 int nRasterYSize;
00357
00358 GDALDataType eDataType;
00359 GDALAccess eAccess;
00360
00361
00362 int nBlockXSize;
00363 int nBlockYSize;
00364 int nBlocksPerRow;
00365 int nBlocksPerColumn;
00366
00367 int bSubBlockingActive;
00368 int nSubBlocksPerRow;
00369 int nSubBlocksPerColumn;
00370 GDALRasterBlock **papoBlocks;
00371
00372 int nBlockReads;
00373 int bForceCachedIO;
00374
00375 friend class GDALDataset;
00376 friend class GDALRasterBlock;
00377
00378 protected:
00379 virtual CPLErr IReadBlock( int, int, void * ) = 0;
00380 virtual CPLErr IWriteBlock( int, int, void * );
00381 virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
00382 void *, int, int, GDALDataType,
00383 int, int );
00384 CPLErr OverviewRasterIO( GDALRWFlag, int, int, int, int,
00385 void *, int, int, GDALDataType,
00386 int, int );
00387
00388 int InitBlockInfo();
00389
00390 CPLErr AdoptBlock( int, int, GDALRasterBlock * );
00391 GDALRasterBlock *TryGetLockedBlockRef( int nXBlockOff, int nYBlockYOff );
00392
00393 public:
00394 GDALRasterBand();
00395
00396 virtual ~GDALRasterBand();
00397
00398 int GetXSize();
00399 int GetYSize();
00400 int GetBand();
00401 GDALDataset*GetDataset();
00402
00403 GDALDataType GetRasterDataType( void );
00404 void GetBlockSize( int *, int * );
00405 GDALAccess GetAccess();
00406
00407 CPLErr RasterIO( GDALRWFlag, int, int, int, int,
00408 void *, int, int, GDALDataType,
00409 int, int );
00410 CPLErr ReadBlock( int, int, void * );
00411
00412 CPLErr WriteBlock( int, int, void * );
00413
00414 GDALRasterBlock *GetLockedBlockRef( int nXBlockOff, int nYBlockOff,
00415 int bJustInitialize = FALSE );
00416 CPLErr FlushBlock( int = -1, int = -1 );
00417
00418
00419
00420 virtual CPLErr FlushCache();
00421 virtual char **GetCategoryNames();
00422 virtual double GetNoDataValue( int *pbSuccess = NULL );
00423 virtual double GetMinimum( int *pbSuccess = NULL );
00424 virtual double GetMaximum(int *pbSuccess = NULL );
00425 virtual double GetOffset( int *pbSuccess = NULL );
00426 virtual double GetScale( int *pbSuccess = NULL );
00427 virtual const char *GetUnitType();
00428 virtual GDALColorInterp GetColorInterpretation();
00429 virtual GDALColorTable *GetColorTable();
00430 virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
00431
00432 virtual CPLErr SetCategoryNames( char ** );
00433 virtual CPLErr SetNoDataValue( double );
00434 virtual CPLErr SetColorTable( GDALColorTable * );
00435 virtual CPLErr SetColorInterpretation( GDALColorInterp );
00436 virtual CPLErr SetOffset( double );
00437 virtual CPLErr SetScale( double );
00438 virtual CPLErr SetUnitType( const char * );
00439
00440 virtual CPLErr GetStatistics( int bApproxOK, int bForce,
00441 double *pdfMin, double *pdfMax,
00442 double *pdfMean, double *padfStdDev );
00443 virtual CPLErr ComputeStatistics( int bApproxOK,
00444 double *pdfMin, double *pdfMax,
00445 double *pdfMean, double *padfStdDev,
00446 GDALProgressFunc, void *pProgressData );
00447 virtual CPLErr SetStatistics( double dfMin, double dfMax,
00448 double dfMean, double dfStdDev );
00449
00450 virtual int HasArbitraryOverviews();
00451 virtual int GetOverviewCount();
00452 virtual GDALRasterBand *GetOverview(int);
00453 virtual CPLErr BuildOverviews( const char *, int, int *,
00454 GDALProgressFunc, void * );
00455
00456 virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
00457 int nBufXSize, int nBufYSize,
00458 GDALDataType eDT, char **papszOptions );
00459
00460 virtual CPLErr GetHistogram( double dfMin, double dfMax,
00461 int nBuckets, int * panHistogram,
00462 int bIncludeOutOfRange, int bApproxOK,
00463 GDALProgressFunc, void *pProgressData );
00464
00465 virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
00466 int *pnBuckets, int ** ppanHistogram,
00467 int bForce,
00468 GDALProgressFunc, void *pProgressData);
00469 virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
00470 int nBuckets, int *panHistogram );
00471
00472 virtual const GDALRasterAttributeTable *GetDefaultRAT();
00473 virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
00474 };
00475
00476
00477
00478
00479
00480
00481
00482 class CPL_DLL GDALOpenInfo
00483 {
00484 public:
00485
00486 GDALOpenInfo( const char * pszFile, GDALAccess eAccessIn );
00487 ~GDALOpenInfo( void );
00488
00489 char *pszFilename;
00490
00491 GDALAccess eAccess;
00492
00493 int bStatOK;
00494 int bIsDirectory;
00495
00496 FILE *fp;
00497
00498 int nHeaderBytes;
00499 GByte *pabyHeader;
00500
00501 };
00502
00503
00504
00505
00506
00507
00519 class CPL_DLL GDALDriver : public GDALMajorObject
00520 {
00521 public:
00522 GDALDriver();
00523 ~GDALDriver();
00524
00525
00526
00527
00528 GDALDataset *Create( const char * pszName,
00529 int nXSize, int nYSize, int nBands,
00530 GDALDataType eType, char ** papszOptions );
00531
00532 CPLErr Delete( const char * pszName );
00533
00534 GDALDataset *CreateCopy( const char *, GDALDataset *,
00535 int, char **,
00536 GDALProgressFunc pfnProgress,
00537 void * pProgressData );
00538
00539 GDALDataset *DefaultCreateCopy( const char *, GDALDataset *,
00540 int, char **,
00541 GDALProgressFunc pfnProgress,
00542 void * pProgressData );
00543
00544
00545
00546
00547
00548
00549 GDALDataset *(*pfnOpen)( GDALOpenInfo * );
00550
00551 GDALDataset *(*pfnCreate)( const char * pszName,
00552 int nXSize, int nYSize, int nBands,
00553 GDALDataType eType,
00554 char ** papszOptions );
00555
00556 CPLErr (*pfnDelete)( const char * pszName );
00557
00558 GDALDataset *(*pfnCreateCopy)( const char *, GDALDataset *,
00559 int, char **,
00560 GDALProgressFunc pfnProgress,
00561 void * pProgressData );
00562
00563 void *pDriverData;
00564
00565 void (*pfnUnloadDriver)(GDALDriver *);
00566 };
00567
00568
00569
00570
00571
00579 class CPL_DLL GDALDriverManager : public GDALMajorObject
00580 {
00581 int nDrivers;
00582 GDALDriver **papoDrivers;
00583
00584 char *pszHome;
00585
00586 public:
00587 GDALDriverManager();
00588 ~GDALDriverManager();
00589
00590 int GetDriverCount( void );
00591 GDALDriver *GetDriver( int );
00592 GDALDriver *GetDriverByName( const char * );
00593
00594 int RegisterDriver( GDALDriver * );
00595 void MoveDriver( GDALDriver *, int );
00596 void DeregisterDriver( GDALDriver * );
00597
00598 void AutoLoadDrivers();
00599 void AutoSkipDrivers();
00600
00601 const char *GetHome();
00602 void SetHome( const char * );
00603 };
00604
00605 CPL_C_START
00606 GDALDriverManager CPL_DLL * GetGDALDriverManager( void );
00607 CPL_C_END
00608
00609
00610
00611
00612
00613 CPL_C_START
00614
00615 CPLErr CPL_DLL
00616 GDALDefaultBuildOverviews( GDALDataset *hSrcDS, const char * pszBasename,
00617 const char * pszResampling,
00618 int nOverviews, int * panOverviewList,
00619 int nBands, int * panBandList,
00620 GDALProgressFunc pfnProgress, void * pProgressData);
00621
00622
00623 CPLErr CPL_DLL
00624 GDALRegenerateOverviews( GDALRasterBand *, int, GDALRasterBand **,
00625 const char *, GDALProgressFunc, void * );
00626
00627 int CPL_DLL GDALOvLevelAdjust( int nOvLevel, int nXSize );
00628
00629 GDALDataset CPL_DLL *
00630 GDALFindAssociatedAuxFile( const char *pszBasefile, GDALAccess eAccess );
00631
00632
00633
00634
00635
00636 CPLErr CPL_DLL GDALParseGMLCoverage( CPLXMLNode *psTree,
00637 int *pnXSize, int *pnYSize,
00638 double *padfGeoTransform,
00639 char **ppszProjection );
00640
00641 CPL_C_END
00642
00643 #endif