00001 /****************************************************************************** 00002 * $Id: gdaldataset_cpp-source.html,v 1.1 2000/09/25 20:50:11 warmerda Exp $ 00003 * 00004 * Project: GDAL Core 00005 * Purpose: Base class for raster file formats. 00006 * Author: Frank Warmerdam, warmerda@home.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 1998, 2000, Frank Warmerdam 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************** 00029 * 00030 * $Log: gdaldataset_cpp-source.html,v $ 00030 * Revision 1.1 2000/09/25 20:50:11 warmerda 00030 * New 00030 * 00031 * Revision 1.20 2000/08/09 16:26:00 warmerda 00032 * debug message on dataset cleanup 00033 * 00034 * Revision 1.19 2000/07/11 14:35:43 warmerda 00035 * added documentation 00036 * 00037 * Revision 1.18 2000/06/27 16:46:56 warmerda 00038 * default to using dummy progress func 00039 * 00040 * Revision 1.17 2000/06/26 21:44:50 warmerda 00041 * make progress func save for overviews 00042 * 00043 * Revision 1.16 2000/06/26 18:47:31 warmerda 00044 * added GDALBuildOverviews 00045 * 00046 * Revision 1.15 2000/04/21 21:56:23 warmerda 00047 * move metadata to GDALMajorObject, added BuildOverviews 00048 * 00049 * Revision 1.14 2000/03/31 13:42:06 warmerda 00050 * added gcp support methods 00051 * 00052 * Revision 1.13 2000/03/23 16:53:55 warmerda 00053 * default geotransform is 0,1,0,0,0,1 00054 * 00055 * Revision 1.12 2000/03/06 21:50:10 warmerda 00056 * fixed bug with setting nBands 00057 * 00058 * Revision 1.11 2000/03/06 02:20:56 warmerda 00059 * added reference counting 00060 * 00061 * Revision 1.10 2000/02/28 16:34:49 warmerda 00062 * set the nRasterX/YSize in bands 00063 * 00064 * Revision 1.9 1999/11/11 21:59:07 warmerda 00065 * added GetDriver() for datasets 00066 * 00067 * Revision 1.8 1999/10/01 14:44:02 warmerda 00068 * added documentation 00069 * 00070 * Revision 1.7 1999/05/17 01:43:10 warmerda 00071 * fixed GDALSetGeoTransform() 00072 * 00073 * Revision 1.6 1999/05/16 20:04:58 warmerda 00074 * Don't emit an error message when SetProjection() is called for datasets 00075 * that don't implement the call. 00076 * 00077 * Revision 1.5 1999/04/21 04:16:51 warmerda 00078 * experimental docs 00079 * 00080 * Revision 1.4 1999/01/11 15:37:55 warmerda 00081 * fixed log keyword 00082 */ 00083 00084 #include "gdal_priv.h" 00085 #include "cpl_string.h" 00086 00087 /************************************************************************/ 00088 /* GDALDataset() */ 00089 /************************************************************************/ 00090 00091 GDALDataset::GDALDataset() 00092 00093 { 00094 poDriver = NULL; 00095 eAccess = GA_ReadOnly; 00096 nRasterXSize = 512; 00097 nRasterYSize = 512; 00098 nBands = 0; 00099 papoBands = NULL; 00100 nRefCount = 1; 00101 } 00102 00103 /************************************************************************/ 00104 /* ~GDALDataset() */ 00105 /************************************************************************/ 00106 00116 GDALDataset::~GDALDataset() 00117 00118 { 00119 int i; 00120 00121 CPLDebug( "GDAL", "GDALClose(%s)\n", GetDescription() ); 00122 00123 /* -------------------------------------------------------------------- */ 00124 /* Destroy the raster bands if they exist. */ 00125 /* -------------------------------------------------------------------- */ 00126 for( i = 0; i < nBands && papoBands != NULL; i++ ) 00127 { 00128 if( papoBands[i] != NULL ) 00129 delete papoBands[i]; 00130 } 00131 00132 CPLFree( papoBands ); 00133 } 00134 00135 /************************************************************************/ 00136 /* GDALClose() */ 00137 /************************************************************************/ 00138 00139 void GDALClose( GDALDatasetH hDS ) 00140 00141 { 00142 delete ((GDALDataset *) hDS); 00143 } 00144 00145 /************************************************************************/ 00146 /* FlushCache() */ 00147 /************************************************************************/ 00148 00156 void GDALDataset::FlushCache() 00157 00158 { 00159 int i; 00160 00161 for( i = 0; i < nBands; i++ ) 00162 { 00163 if( papoBands[i] != NULL ) 00164 papoBands[i]->FlushCache(); 00165 } 00166 } 00167 00168 /************************************************************************/ 00169 /* RasterInitialize() */ 00170 /* */ 00171 /* Initialize raster size */ 00172 /************************************************************************/ 00173 00174 void GDALDataset::RasterInitialize( int nXSize, int nYSize ) 00175 00176 { 00177 CPLAssert( nXSize > 0 && nYSize > 0 ); 00178 00179 nRasterXSize = nXSize; 00180 nRasterYSize = nYSize; 00181 } 00182 00183 /************************************************************************/ 00184 /* SetBand() */ 00185 /* */ 00186 /* Set a band in the band array, updating the band count, and */ 00187 /* array size appropriately. */ 00188 /************************************************************************/ 00189 00190 void GDALDataset::SetBand( int nNewBand, GDALRasterBand * poBand ) 00191 00192 { 00193 /* -------------------------------------------------------------------- */ 00194 /* Do we need to grow the bands list? */ 00195 /* -------------------------------------------------------------------- */ 00196 if( nBands < nNewBand || papoBands == NULL ) { 00197 int i; 00198 00199 if( papoBands == NULL ) 00200 papoBands = (GDALRasterBand **) 00201 VSICalloc(sizeof(GDALRasterBand*), MAX(nNewBand,nBands)); 00202 else 00203 papoBands = (GDALRasterBand **) 00204 VSIRealloc(papoBands, sizeof(GDALRasterBand*) * 00205 MAX(nNewBand,nBands)); 00206 00207 for( i = nBands; i < nNewBand; i++ ) 00208 papoBands[i] = NULL; 00209 00210 nBands = MAX(nBands,nNewBand); 00211 } 00212 00213 /* -------------------------------------------------------------------- */ 00214 /* Set the band. Resetting the band is currently not permitted. */ 00215 /* -------------------------------------------------------------------- */ 00216 CPLAssert( papoBands[nNewBand-1] == NULL ); 00217 00218 papoBands[nNewBand-1] = poBand; 00219 00220 /* -------------------------------------------------------------------- */ 00221 /* Set back reference information on the raster band. Note */ 00222 /* that the GDALDataset is a friend of the GDALRasterBand */ 00223 /* specifically to allow this. */ 00224 /* -------------------------------------------------------------------- */ 00225 poBand->nBand = nNewBand; 00226 poBand->poDS = this; 00227 poBand->nRasterXSize = nRasterXSize; 00228 poBand->nRasterYSize = nRasterYSize; 00229 } 00230 00231 /************************************************************************/ 00232 /* GetRasterXSize() */ 00233 /************************************************************************/ 00234 00245 int GDALDataset::GetRasterXSize() 00246 00247 { 00248 return nRasterXSize; 00249 } 00250 00251 /************************************************************************/ 00252 /* GDALGetRasterXSize() */ 00253 /************************************************************************/ 00254 00255 int GDALGetRasterXSize( GDALDatasetH hDataset ) 00256 00257 { 00258 return ((GDALDataset *) hDataset)->GetRasterXSize(); 00259 } 00260 00261 00262 /************************************************************************/ 00263 /* GetRasterYSize() */ 00264 /************************************************************************/ 00265 00276 int GDALDataset::GetRasterYSize() 00277 00278 { 00279 return nRasterYSize; 00280 } 00281 00282 /************************************************************************/ 00283 /* GDALGetRasterYSize() */ 00284 /************************************************************************/ 00285 00286 int GDALGetRasterYSize( GDALDatasetH hDataset ) 00287 00288 { 00289 return ((GDALDataset *) hDataset)->GetRasterYSize(); 00290 } 00291 00292 /************************************************************************/ 00293 /* GetRasterBand() */ 00294 /************************************************************************/ 00295 00309 GDALRasterBand * GDALDataset::GetRasterBand( int nBandId ) 00310 00311 { 00312 if( nBandId < 1 || nBandId > nBands ) 00313 { 00314 CPLError( CE_Fatal, CPLE_IllegalArg, 00315 "GDALDataset::GetRasterBand(%d) - Illegal band #\n", 00316 nBandId ); 00317 } 00318 00319 return( papoBands[nBandId-1] ); 00320 } 00321 00322 /************************************************************************/ 00323 /* GDALGetRasterBand() */ 00324 /************************************************************************/ 00325 00326 GDALRasterBandH GDALGetRasterBand( GDALDatasetH hDS, int nBandId ) 00327 00328 { 00329 return( (GDALRasterBandH) ((GDALDataset *) hDS)->GetRasterBand(nBandId) ); 00330 } 00331 00332 /************************************************************************/ 00333 /* GetRasterCount() */ 00334 /************************************************************************/ 00335 00344 int GDALDataset::GetRasterCount() 00345 00346 { 00347 return( nBands ); 00348 } 00349 00350 /************************************************************************/ 00351 /* GDALGetRasterCount() */ 00352 /************************************************************************/ 00353 00354 int GDALGetRasterCount( GDALDatasetH hDS ) 00355 00356 { 00357 return( ((GDALDataset *) hDS)->GetRasterCount() ); 00358 } 00359 00360 /************************************************************************/ 00361 /* GetProjectionRef() */ 00362 /************************************************************************/ 00363 00380 const char *GDALDataset::GetProjectionRef() 00381 00382 { 00383 return( "" ); 00384 } 00385 00386 /************************************************************************/ 00387 /* GDALGetProjectionRef() */ 00388 /************************************************************************/ 00389 00390 const char *GDALGetProjectionRef( GDALDatasetH hDS ) 00391 00392 { 00393 return( ((GDALDataset *) hDS)->GetProjectionRef() ); 00394 } 00395 00396 /************************************************************************/ 00397 /* SetProjection() */ 00398 /************************************************************************/ 00399 00415 CPLErr GDALDataset::SetProjection( const char * ) 00416 00417 { 00418 return CE_Failure; 00419 } 00420 00421 /************************************************************************/ 00422 /* GDALSetProjection() */ 00423 /************************************************************************/ 00424 00425 CPLErr GDALSetProjection( GDALDatasetH hDS, const char * pszProjection ) 00426 00427 { 00428 return( ((GDALDataset *) hDS)->SetProjection(pszProjection) ); 00429 } 00430 00431 /************************************************************************/ 00432 /* GetGeoTransform() */ 00433 /************************************************************************/ 00434 00465 CPLErr GDALDataset::GetGeoTransform( double * padfTransform ) 00466 00467 { 00468 CPLAssert( padfTransform != NULL ); 00469 00470 padfTransform[0] = 0.0; /* X Origin (top left corner) */ 00471 padfTransform[1] = 1.0; /* X Pixel size */ 00472 padfTransform[2] = 0.0; 00473 00474 padfTransform[3] = 0.0; /* Y Origin (top left corner) */ 00475 padfTransform[4] = 0.0; 00476 padfTransform[5] = 1.0; /* Y Pixel Size */ 00477 00478 return( CE_Failure ); 00479 } 00480 00481 /************************************************************************/ 00482 /* GDALGetGeoTransform() */ 00483 /************************************************************************/ 00484 00485 CPLErr GDALGetGeoTransform( GDALDatasetH hDS, double * padfTransform ) 00486 00487 { 00488 return( ((GDALDataset *) hDS)->GetGeoTransform(padfTransform) ); 00489 } 00490 00491 /************************************************************************/ 00492 /* SetGeoTransform() */ 00493 /************************************************************************/ 00494 00510 CPLErr GDALDataset::SetGeoTransform( double * ) 00511 00512 { 00513 CPLError( CE_Failure, CPLE_NotSupported, 00514 "SetGeoTransform() not supported for this dataset." ); 00515 00516 return( CE_Failure ); 00517 } 00518 00519 /************************************************************************/ 00520 /* GDALSetGeoTransform() */ 00521 /************************************************************************/ 00522 00523 CPLErr GDALSetGeoTransform( GDALDatasetH hDS, double * padfTransform ) 00524 00525 { 00526 return( ((GDALDataset *) hDS)->SetGeoTransform(padfTransform) ); 00527 } 00528 00529 /************************************************************************/ 00530 /* GetInternalHandle() */ 00531 /************************************************************************/ 00532 00544 void *GDALDataset::GetInternalHandle( const char * ) 00545 00546 { 00547 return( NULL ); 00548 } 00549 00550 /************************************************************************/ 00551 /* GDALGetInternalHandle() */ 00552 /************************************************************************/ 00553 00554 void *GDALGetInternalHandle( GDALDatasetH hDS, const char * pszRequest ) 00555 00556 { 00557 return( ((GDALDataset *) hDS)->GetInternalHandle(pszRequest) ); 00558 } 00559 00560 /************************************************************************/ 00561 /* GetDriver() */ 00562 /************************************************************************/ 00563 00573 GDALDriver * GDALDataset::GetDriver() 00574 00575 { 00576 return poDriver; 00577 } 00578 00579 /************************************************************************/ 00580 /* GDALGetDatasetDriver() */ 00581 /************************************************************************/ 00582 00583 GDALDriverH GDALGetDatasetDriver( GDALDatasetH hDataset ) 00584 00585 { 00586 return (GDALDriverH) ((GDALDataset *) hDataset)->GetDriver(); 00587 } 00588 00589 /************************************************************************/ 00590 /* Reference() */ 00591 /************************************************************************/ 00592 00603 int GDALDataset::Reference() 00604 00605 { 00606 return ++nRefCount; 00607 } 00608 00609 /************************************************************************/ 00610 /* GDALReferenceDataset() */ 00611 /************************************************************************/ 00612 00613 int GDALReferenceDataset( GDALDatasetH hDataset ) 00614 00615 { 00616 return ((GDALDataset *) hDataset)->Reference(); 00617 } 00618 00619 /************************************************************************/ 00620 /* Reference() */ 00621 /************************************************************************/ 00622 00634 int GDALDataset::Dereference() 00635 00636 { 00637 return --nRefCount; 00638 } 00639 00640 /************************************************************************/ 00641 /* GDALDereferenceDataset() */ 00642 /************************************************************************/ 00643 00644 int GDALDereferenceDataset( GDALDatasetH hDataset ) 00645 00646 { 00647 return ((GDALDataset *) hDataset)->Dereference(); 00648 } 00649 00650 /************************************************************************/ 00651 /* GetGCPCount() */ 00652 /************************************************************************/ 00653 00662 int GDALDataset::GetGCPCount() 00663 00664 { 00665 return 0; 00666 } 00667 00668 /************************************************************************/ 00669 /* GDALGetGCPCount() */ 00670 /************************************************************************/ 00671 00672 int GDALGetGCPCount( GDALDatasetH hDS ) 00673 00674 { 00675 return ((GDALDataset *) hDS)->GetGCPCount(); 00676 } 00677 00678 /************************************************************************/ 00679 /* GetGCPProjection() */ 00680 /************************************************************************/ 00681 00692 const char *GDALDataset::GetGCPProjection() 00693 00694 { 00695 return ""; 00696 } 00697 00698 /************************************************************************/ 00699 /* GDALGetGCPProjection() */ 00700 /************************************************************************/ 00701 00702 const char *GDALGetGCPProjection( GDALDatasetH hDS ) 00703 00704 { 00705 return ((GDALDataset *) hDS)->GetGCPProjection(); 00706 } 00707 00708 /************************************************************************/ 00709 /* GetGCPs() */ 00710 /************************************************************************/ 00711 00721 const GDAL_GCP *GDALDataset::GetGCPs() 00722 00723 { 00724 return NULL; 00725 } 00726 00727 /************************************************************************/ 00728 /* GDALGetGCPs() */ 00729 /************************************************************************/ 00730 00731 const GDAL_GCP *GDALGetGCPs( GDALDatasetH hDS ) 00732 00733 { 00734 return ((GDALDataset *) hDS)->GetGCPs(); 00735 } 00736 00737 /************************************************************************/ 00738 /* BuildOverviews() */ 00739 /************************************************************************/ 00740 00769 CPLErr GDALDataset::BuildOverviews( const char *pszResampling, 00770 int nOverviews, int *panOverviewList, 00771 int nBands, int *panBandList, 00772 GDALProgressFunc pfnProgress, 00773 void * pProgressData ) 00774 00775 { 00776 CPLErr eErr; 00777 int *panAllBandList = NULL; 00778 00779 if( nBands == 0 ) 00780 { 00781 nBands = GetRasterCount(); 00782 panAllBandList = (int *) CPLMalloc(sizeof(int) * nBands); 00783 for( int i = 0; i < nBands; i++ ) 00784 panAllBandList[i] = i+1; 00785 00786 panBandList = panAllBandList; 00787 } 00788 00789 if( pfnProgress == NULL ) 00790 pfnProgress = GDALDummyProgress; 00791 00792 eErr = IBuildOverviews( pszResampling, nOverviews, panOverviewList, 00793 nBands, panBandList, pfnProgress, pProgressData ); 00794 00795 if( panAllBandList != NULL ) 00796 CPLFree( panAllBandList ); 00797 00798 return eErr; 00799 } 00800 00801 /************************************************************************/ 00802 /* GDALBuildOverviews() */ 00803 /************************************************************************/ 00804 00805 CPLErr GDALBuildOverviews( GDALDatasetH hDataset, 00806 const char *pszResampling, 00807 int nOverviews, int *panOverviewList, 00808 int nBands, int *panBandList, 00809 GDALProgressFunc pfnProgress, 00810 void * pProgressData ) 00811 00812 { 00813 return ((GDALDataset *) hDataset)->BuildOverviews( 00814 pszResampling, nOverviews, panOverviewList, nBands, panBandList, 00815 pfnProgress, pProgressData ); 00816 } 00817 00818 /************************************************************************/ 00819 /* IBuildOverviews() */ 00820 /* */ 00821 /* Default implementation. */ 00822 /************************************************************************/ 00823 00824 CPLErr GDALDataset::IBuildOverviews( const char *pszResampling, 00825 int nOverviews, int *panOverviewList, 00826 int nBands, int *panBandList, 00827 GDALProgressFunc pfnProgress, 00828 void * pProgressData ) 00829 00830 { 00831 if( pfnProgress == NULL ) 00832 pfnProgress = GDALDummyProgress; 00833 00834 if( oOvManager.IsInitialized() ) 00835 return oOvManager.BuildOverviews( NULL, pszResampling, 00836 nOverviews, panOverviewList, 00837 nBands, panBandList, 00838 pfnProgress, pProgressData ); 00839 else 00840 { 00841 CPLError( CE_Failure, CPLE_NotSupported, 00842 "BuildOverviews() not supported for this dataset." ); 00843 00844 return( CE_Failure ); 00845 } 00846 } 00847