00001 /****************************************************************************** 00002 * $Id: gdaldataset_cpp-source.html,v 1.5 2000/11/06 04:49:01 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.5 2000/11/06 04:49:01 warmerda 00030 * *** empty log message *** 00030 * 00031 * Revision 1.21 2000/10/06 15:27:13 warmerda 00032 * default bands to same access as dataset in SetBand() 00033 * 00034 * Revision 1.20 2000/08/09 16:26:00 warmerda 00035 * debug message on dataset cleanup 00036 * 00037 * Revision 1.19 2000/07/11 14:35:43 warmerda 00038 * added documentation 00039 * 00040 * Revision 1.18 2000/06/27 16:46:56 warmerda 00041 * default to using dummy progress func 00042 * 00043 * Revision 1.17 2000/06/26 21:44:50 warmerda 00044 * make progress func save for overviews 00045 * 00046 * Revision 1.16 2000/06/26 18:47:31 warmerda 00047 * added GDALBuildOverviews 00048 * 00049 * Revision 1.15 2000/04/21 21:56:23 warmerda 00050 * move metadata to GDALMajorObject, added BuildOverviews 00051 * 00052 * Revision 1.14 2000/03/31 13:42:06 warmerda 00053 * added gcp support methods 00054 * 00055 * Revision 1.13 2000/03/23 16:53:55 warmerda 00056 * default geotransform is 0,1,0,0,0,1 00057 * 00058 * Revision 1.12 2000/03/06 21:50:10 warmerda 00059 * fixed bug with setting nBands 00060 * 00061 * Revision 1.11 2000/03/06 02:20:56 warmerda 00062 * added reference counting 00063 * 00064 * Revision 1.10 2000/02/28 16:34:49 warmerda 00065 * set the nRasterX/YSize in bands 00066 * 00067 * Revision 1.9 1999/11/11 21:59:07 warmerda 00068 * added GetDriver() for datasets 00069 * 00070 * Revision 1.8 1999/10/01 14:44:02 warmerda 00071 * added documentation 00072 * 00073 * Revision 1.7 1999/05/17 01:43:10 warmerda 00074 * fixed GDALSetGeoTransform() 00075 * 00076 * Revision 1.6 1999/05/16 20:04:58 warmerda 00077 * Don't emit an error message when SetProjection() is called for datasets 00078 * that don't implement the call. 00079 * 00080 * Revision 1.5 1999/04/21 04:16:51 warmerda 00081 * experimental docs 00082 * 00083 * Revision 1.4 1999/01/11 15:37:55 warmerda 00084 * fixed log keyword 00085 */ 00086 00087 #include "gdal_priv.h" 00088 #include "cpl_string.h" 00089 00090 /************************************************************************/ 00091 /* GDALDataset() */ 00092 /************************************************************************/ 00093 00094 GDALDataset::GDALDataset() 00095 00096 { 00097 poDriver = NULL; 00098 eAccess = GA_ReadOnly; 00099 nRasterXSize = 512; 00100 nRasterYSize = 512; 00101 nBands = 0; 00102 papoBands = NULL; 00103 nRefCount = 1; 00104 } 00105 00106 /************************************************************************/ 00107 /* ~GDALDataset() */ 00108 /************************************************************************/ 00109 00119 GDALDataset::~GDALDataset() 00120 00121 { 00122 int i; 00123 00124 CPLDebug( "GDAL", "GDALClose(%s)\n", GetDescription() ); 00125 00126 /* -------------------------------------------------------------------- */ 00127 /* Destroy the raster bands if they exist. */ 00128 /* -------------------------------------------------------------------- */ 00129 for( i = 0; i < nBands && papoBands != NULL; i++ ) 00130 { 00131 if( papoBands[i] != NULL ) 00132 delete papoBands[i]; 00133 } 00134 00135 CPLFree( papoBands ); 00136 } 00137 00138 /************************************************************************/ 00139 /* GDALClose() */ 00140 /************************************************************************/ 00141 00142 void GDALClose( GDALDatasetH hDS ) 00143 00144 { 00145 delete ((GDALDataset *) hDS); 00146 } 00147 00148 /************************************************************************/ 00149 /* FlushCache() */ 00150 /************************************************************************/ 00151 00159 void GDALDataset::FlushCache() 00160 00161 { 00162 int i; 00163 00164 for( i = 0; i < nBands; i++ ) 00165 { 00166 if( papoBands[i] != NULL ) 00167 papoBands[i]->FlushCache(); 00168 } 00169 } 00170 00171 /************************************************************************/ 00172 /* RasterInitialize() */ 00173 /* */ 00174 /* Initialize raster size */ 00175 /************************************************************************/ 00176 00177 void GDALDataset::RasterInitialize( int nXSize, int nYSize ) 00178 00179 { 00180 CPLAssert( nXSize > 0 && nYSize > 0 ); 00181 00182 nRasterXSize = nXSize; 00183 nRasterYSize = nYSize; 00184 } 00185 00186 /************************************************************************/ 00187 /* SetBand() */ 00188 /* */ 00189 /* Set a band in the band array, updating the band count, and */ 00190 /* array size appropriately. */ 00191 /************************************************************************/ 00192 00193 void GDALDataset::SetBand( int nNewBand, GDALRasterBand * poBand ) 00194 00195 { 00196 /* -------------------------------------------------------------------- */ 00197 /* Do we need to grow the bands list? */ 00198 /* -------------------------------------------------------------------- */ 00199 if( nBands < nNewBand || papoBands == NULL ) { 00200 int i; 00201 00202 if( papoBands == NULL ) 00203 papoBands = (GDALRasterBand **) 00204 VSICalloc(sizeof(GDALRasterBand*), MAX(nNewBand,nBands)); 00205 else 00206 papoBands = (GDALRasterBand **) 00207 VSIRealloc(papoBands, sizeof(GDALRasterBand*) * 00208 MAX(nNewBand,nBands)); 00209 00210 for( i = nBands; i < nNewBand; i++ ) 00211 papoBands[i] = NULL; 00212 00213 nBands = MAX(nBands,nNewBand); 00214 } 00215 00216 /* -------------------------------------------------------------------- */ 00217 /* Set the band. Resetting the band is currently not permitted. */ 00218 /* -------------------------------------------------------------------- */ 00219 CPLAssert( papoBands[nNewBand-1] == NULL ); 00220 00221 papoBands[nNewBand-1] = poBand; 00222 00223 /* -------------------------------------------------------------------- */ 00224 /* Set back reference information on the raster band. Note */ 00225 /* that the GDALDataset is a friend of the GDALRasterBand */ 00226 /* specifically to allow this. */ 00227 /* -------------------------------------------------------------------- */ 00228 poBand->nBand = nNewBand; 00229 poBand->poDS = this; 00230 poBand->nRasterXSize = nRasterXSize; 00231 poBand->nRasterYSize = nRasterYSize; 00232 poBand->eAccess = eAccess; /* default access to be same as dataset */ 00233 } 00234 00235 /************************************************************************/ 00236 /* GetRasterXSize() */ 00237 /************************************************************************/ 00238 00249 int GDALDataset::GetRasterXSize() 00250 00251 { 00252 return nRasterXSize; 00253 } 00254 00255 /************************************************************************/ 00256 /* GDALGetRasterXSize() */ 00257 /************************************************************************/ 00258 00259 int GDALGetRasterXSize( GDALDatasetH hDataset ) 00260 00261 { 00262 return ((GDALDataset *) hDataset)->GetRasterXSize(); 00263 } 00264 00265 00266 /************************************************************************/ 00267 /* GetRasterYSize() */ 00268 /************************************************************************/ 00269 00280 int GDALDataset::GetRasterYSize() 00281 00282 { 00283 return nRasterYSize; 00284 } 00285 00286 /************************************************************************/ 00287 /* GDALGetRasterYSize() */ 00288 /************************************************************************/ 00289 00290 int GDALGetRasterYSize( GDALDatasetH hDataset ) 00291 00292 { 00293 return ((GDALDataset *) hDataset)->GetRasterYSize(); 00294 } 00295 00296 /************************************************************************/ 00297 /* GetRasterBand() */ 00298 /************************************************************************/ 00299 00313 GDALRasterBand * GDALDataset::GetRasterBand( int nBandId ) 00314 00315 { 00316 if( nBandId < 1 || nBandId > nBands ) 00317 { 00318 CPLError( CE_Fatal, CPLE_IllegalArg, 00319 "GDALDataset::GetRasterBand(%d) - Illegal band #\n", 00320 nBandId ); 00321 } 00322 00323 return( papoBands[nBandId-1] ); 00324 } 00325 00326 /************************************************************************/ 00327 /* GDALGetRasterBand() */ 00328 /************************************************************************/ 00329 00330 GDALRasterBandH GDALGetRasterBand( GDALDatasetH hDS, int nBandId ) 00331 00332 { 00333 return( (GDALRasterBandH) ((GDALDataset *) hDS)->GetRasterBand(nBandId) ); 00334 } 00335 00336 /************************************************************************/ 00337 /* GetRasterCount() */ 00338 /************************************************************************/ 00339 00348 int GDALDataset::GetRasterCount() 00349 00350 { 00351 return( nBands ); 00352 } 00353 00354 /************************************************************************/ 00355 /* GDALGetRasterCount() */ 00356 /************************************************************************/ 00357 00358 int GDALGetRasterCount( GDALDatasetH hDS ) 00359 00360 { 00361 return( ((GDALDataset *) hDS)->GetRasterCount() ); 00362 } 00363 00364 /************************************************************************/ 00365 /* GetProjectionRef() */ 00366 /************************************************************************/ 00367 00384 const char *GDALDataset::GetProjectionRef() 00385 00386 { 00387 return( "" ); 00388 } 00389 00390 /************************************************************************/ 00391 /* GDALGetProjectionRef() */ 00392 /************************************************************************/ 00393 00394 const char *GDALGetProjectionRef( GDALDatasetH hDS ) 00395 00396 { 00397 return( ((GDALDataset *) hDS)->GetProjectionRef() ); 00398 } 00399 00400 /************************************************************************/ 00401 /* SetProjection() */ 00402 /************************************************************************/ 00403 00419 CPLErr GDALDataset::SetProjection( const char * ) 00420 00421 { 00422 return CE_Failure; 00423 } 00424 00425 /************************************************************************/ 00426 /* GDALSetProjection() */ 00427 /************************************************************************/ 00428 00429 CPLErr GDALSetProjection( GDALDatasetH hDS, const char * pszProjection ) 00430 00431 { 00432 return( ((GDALDataset *) hDS)->SetProjection(pszProjection) ); 00433 } 00434 00435 /************************************************************************/ 00436 /* GetGeoTransform() */ 00437 /************************************************************************/ 00438 00469 CPLErr GDALDataset::GetGeoTransform( double * padfTransform ) 00470 00471 { 00472 CPLAssert( padfTransform != NULL ); 00473 00474 padfTransform[0] = 0.0; /* X Origin (top left corner) */ 00475 padfTransform[1] = 1.0; /* X Pixel size */ 00476 padfTransform[2] = 0.0; 00477 00478 padfTransform[3] = 0.0; /* Y Origin (top left corner) */ 00479 padfTransform[4] = 0.0; 00480 padfTransform[5] = 1.0; /* Y Pixel Size */ 00481 00482 return( CE_Failure ); 00483 } 00484 00485 /************************************************************************/ 00486 /* GDALGetGeoTransform() */ 00487 /************************************************************************/ 00488 00489 CPLErr GDALGetGeoTransform( GDALDatasetH hDS, double * padfTransform ) 00490 00491 { 00492 return( ((GDALDataset *) hDS)->GetGeoTransform(padfTransform) ); 00493 } 00494 00495 /************************************************************************/ 00496 /* SetGeoTransform() */ 00497 /************************************************************************/ 00498 00514 CPLErr GDALDataset::SetGeoTransform( double * ) 00515 00516 { 00517 CPLError( CE_Failure, CPLE_NotSupported, 00518 "SetGeoTransform() not supported for this dataset." ); 00519 00520 return( CE_Failure ); 00521 } 00522 00523 /************************************************************************/ 00524 /* GDALSetGeoTransform() */ 00525 /************************************************************************/ 00526 00527 CPLErr GDALSetGeoTransform( GDALDatasetH hDS, double * padfTransform ) 00528 00529 { 00530 return( ((GDALDataset *) hDS)->SetGeoTransform(padfTransform) ); 00531 } 00532 00533 /************************************************************************/ 00534 /* GetInternalHandle() */ 00535 /************************************************************************/ 00536 00548 void *GDALDataset::GetInternalHandle( const char * ) 00549 00550 { 00551 return( NULL ); 00552 } 00553 00554 /************************************************************************/ 00555 /* GDALGetInternalHandle() */ 00556 /************************************************************************/ 00557 00558 void *GDALGetInternalHandle( GDALDatasetH hDS, const char * pszRequest ) 00559 00560 { 00561 return( ((GDALDataset *) hDS)->GetInternalHandle(pszRequest) ); 00562 } 00563 00564 /************************************************************************/ 00565 /* GetDriver() */ 00566 /************************************************************************/ 00567 00577 GDALDriver * GDALDataset::GetDriver() 00578 00579 { 00580 return poDriver; 00581 } 00582 00583 /************************************************************************/ 00584 /* GDALGetDatasetDriver() */ 00585 /************************************************************************/ 00586 00587 GDALDriverH GDALGetDatasetDriver( GDALDatasetH hDataset ) 00588 00589 { 00590 return (GDALDriverH) ((GDALDataset *) hDataset)->GetDriver(); 00591 } 00592 00593 /************************************************************************/ 00594 /* Reference() */ 00595 /************************************************************************/ 00596 00607 int GDALDataset::Reference() 00608 00609 { 00610 return ++nRefCount; 00611 } 00612 00613 /************************************************************************/ 00614 /* GDALReferenceDataset() */ 00615 /************************************************************************/ 00616 00617 int GDALReferenceDataset( GDALDatasetH hDataset ) 00618 00619 { 00620 return ((GDALDataset *) hDataset)->Reference(); 00621 } 00622 00623 /************************************************************************/ 00624 /* Reference() */ 00625 /************************************************************************/ 00626 00638 int GDALDataset::Dereference() 00639 00640 { 00641 return --nRefCount; 00642 } 00643 00644 /************************************************************************/ 00645 /* GDALDereferenceDataset() */ 00646 /************************************************************************/ 00647 00648 int GDALDereferenceDataset( GDALDatasetH hDataset ) 00649 00650 { 00651 return ((GDALDataset *) hDataset)->Dereference(); 00652 } 00653 00654 /************************************************************************/ 00655 /* GetGCPCount() */ 00656 /************************************************************************/ 00657 00666 int GDALDataset::GetGCPCount() 00667 00668 { 00669 return 0; 00670 } 00671 00672 /************************************************************************/ 00673 /* GDALGetGCPCount() */ 00674 /************************************************************************/ 00675 00676 int GDALGetGCPCount( GDALDatasetH hDS ) 00677 00678 { 00679 return ((GDALDataset *) hDS)->GetGCPCount(); 00680 } 00681 00682 /************************************************************************/ 00683 /* GetGCPProjection() */ 00684 /************************************************************************/ 00685 00696 const char *GDALDataset::GetGCPProjection() 00697 00698 { 00699 return ""; 00700 } 00701 00702 /************************************************************************/ 00703 /* GDALGetGCPProjection() */ 00704 /************************************************************************/ 00705 00706 const char *GDALGetGCPProjection( GDALDatasetH hDS ) 00707 00708 { 00709 return ((GDALDataset *) hDS)->GetGCPProjection(); 00710 } 00711 00712 /************************************************************************/ 00713 /* GetGCPs() */ 00714 /************************************************************************/ 00715 00725 const GDAL_GCP *GDALDataset::GetGCPs() 00726 00727 { 00728 return NULL; 00729 } 00730 00731 /************************************************************************/ 00732 /* GDALGetGCPs() */ 00733 /************************************************************************/ 00734 00735 const GDAL_GCP *GDALGetGCPs( GDALDatasetH hDS ) 00736 00737 { 00738 return ((GDALDataset *) hDS)->GetGCPs(); 00739 } 00740 00741 /************************************************************************/ 00742 /* BuildOverviews() */ 00743 /************************************************************************/ 00744 00773 CPLErr GDALDataset::BuildOverviews( const char *pszResampling, 00774 int nOverviews, int *panOverviewList, 00775 int nBands, int *panBandList, 00776 GDALProgressFunc pfnProgress, 00777 void * pProgressData ) 00778 00779 { 00780 CPLErr eErr; 00781 int *panAllBandList = NULL; 00782 00783 if( nBands == 0 ) 00784 { 00785 nBands = GetRasterCount(); 00786 panAllBandList = (int *) CPLMalloc(sizeof(int) * nBands); 00787 for( int i = 0; i < nBands; i++ ) 00788 panAllBandList[i] = i+1; 00789 00790 panBandList = panAllBandList; 00791 } 00792 00793 if( pfnProgress == NULL ) 00794 pfnProgress = GDALDummyProgress; 00795 00796 eErr = IBuildOverviews( pszResampling, nOverviews, panOverviewList, 00797 nBands, panBandList, pfnProgress, pProgressData ); 00798 00799 if( panAllBandList != NULL ) 00800 CPLFree( panAllBandList ); 00801 00802 return eErr; 00803 } 00804 00805 /************************************************************************/ 00806 /* GDALBuildOverviews() */ 00807 /************************************************************************/ 00808 00809 CPLErr GDALBuildOverviews( GDALDatasetH hDataset, 00810 const char *pszResampling, 00811 int nOverviews, int *panOverviewList, 00812 int nBands, int *panBandList, 00813 GDALProgressFunc pfnProgress, 00814 void * pProgressData ) 00815 00816 { 00817 return ((GDALDataset *) hDataset)->BuildOverviews( 00818 pszResampling, nOverviews, panOverviewList, nBands, panBandList, 00819 pfnProgress, pProgressData ); 00820 } 00821 00822 /************************************************************************/ 00823 /* IBuildOverviews() */ 00824 /* */ 00825 /* Default implementation. */ 00826 /************************************************************************/ 00827 00828 CPLErr GDALDataset::IBuildOverviews( const char *pszResampling, 00829 int nOverviews, int *panOverviewList, 00830 int nBands, int *panBandList, 00831 GDALProgressFunc pfnProgress, 00832 void * pProgressData ) 00833 00834 { 00835 if( pfnProgress == NULL ) 00836 pfnProgress = GDALDummyProgress; 00837 00838 if( oOvManager.IsInitialized() ) 00839 return oOvManager.BuildOverviews( NULL, pszResampling, 00840 nOverviews, panOverviewList, 00841 nBands, panBandList, 00842 pfnProgress, pProgressData ); 00843 else 00844 { 00845 CPLError( CE_Failure, CPLE_NotSupported, 00846 "BuildOverviews() not supported for this dataset." ); 00847 00848 return( CE_Failure ); 00849 } 00850 } 00851