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