Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

gdaldataset.cpp

00001 /******************************************************************************
00002  * $Id: gdaldataset_cpp-source.html,v 1.8 2001/07/05 13:24:08 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.8  2001/07/05 13:24:08  warmerda
00030  * *** empty log message ***
00030  *
00031  * Revision 1.22  2001/01/10 22:24:37  warmerda
00032  * Patched GDALDataset::FlushCache() to recover gracefully if papoBands
00033  * doesn't exist yet matching nBands.
00034  *
00035  * Revision 1.21  2000/10/06 15:27:13  warmerda
00036  * default bands to same access as dataset in SetBand()
00037  *
00038  * Revision 1.20  2000/08/09 16:26:00  warmerda
00039  * debug message on dataset cleanup
00040  *
00041  * Revision 1.19  2000/07/11 14:35:43  warmerda
00042  * added documentation
00043  *
00044  * Revision 1.18  2000/06/27 16:46:56  warmerda
00045  * default to using dummy progress func
00046  *
00047  * Revision 1.17  2000/06/26 21:44:50  warmerda
00048  * make progress func save for overviews
00049  *
00050  * Revision 1.16  2000/06/26 18:47:31  warmerda
00051  * added GDALBuildOverviews
00052  *
00053  * Revision 1.15  2000/04/21 21:56:23  warmerda
00054  * move metadata to GDALMajorObject, added BuildOverviews
00055  *
00056  * Revision 1.14  2000/03/31 13:42:06  warmerda
00057  * added gcp support methods
00058  *
00059  * Revision 1.13  2000/03/23 16:53:55  warmerda
00060  * default geotransform is 0,1,0,0,0,1
00061  *
00062  * Revision 1.12  2000/03/06 21:50:10  warmerda
00063  * fixed bug with setting nBands
00064  *
00065  * Revision 1.11  2000/03/06 02:20:56  warmerda
00066  * added reference counting
00067  *
00068  * Revision 1.10  2000/02/28 16:34:49  warmerda
00069  * set the nRasterX/YSize in bands
00070  *
00071  * Revision 1.9  1999/11/11 21:59:07  warmerda
00072  * added GetDriver() for datasets
00073  *
00074  * Revision 1.8  1999/10/01 14:44:02  warmerda
00075  * added documentation
00076  *
00077  * Revision 1.7  1999/05/17 01:43:10  warmerda
00078  * fixed GDALSetGeoTransform()
00079  *
00080  * Revision 1.6  1999/05/16 20:04:58  warmerda
00081  * Don't emit an error message when SetProjection() is called for datasets
00082  * that don't implement the call.
00083  *
00084  * Revision 1.5  1999/04/21 04:16:51  warmerda
00085  * experimental docs
00086  *
00087  * Revision 1.4  1999/01/11 15:37:55  warmerda
00088  * fixed log keyword
00089  */
00090 
00091 #include "gdal_priv.h"
00092 #include "cpl_string.h"
00093 
00094 /************************************************************************/
00095 /*                            GDALDataset()                             */
00096 /************************************************************************/
00097 
00098 GDALDataset::GDALDataset()
00099 
00100 {
00101     poDriver = NULL;
00102     eAccess = GA_ReadOnly;
00103     nRasterXSize = 512;
00104     nRasterYSize = 512;
00105     nBands = 0;
00106     papoBands = NULL;
00107     nRefCount = 1;
00108 }
00109 
00110 /************************************************************************/
00111 /*                            ~GDALDataset()                            */
00112 /************************************************************************/
00113 
00123 GDALDataset::~GDALDataset()
00124 
00125 {
00126     int         i;
00127 
00128     CPLDebug( "GDAL", "GDALClose(%s)\n", GetDescription() );
00129 
00130 /* -------------------------------------------------------------------- */
00131 /*      Destroy the raster bands if they exist.                         */
00132 /* -------------------------------------------------------------------- */
00133     for( i = 0; i < nBands && papoBands != NULL; i++ )
00134     {
00135         if( papoBands[i] != NULL )
00136             delete papoBands[i];
00137     }
00138 
00139     CPLFree( papoBands );
00140 }
00141 
00142 /************************************************************************/
00143 /*                             GDALClose()                              */
00144 /************************************************************************/
00145 
00146 void GDALClose( GDALDatasetH hDS )
00147 
00148 {
00149     delete ((GDALDataset *) hDS);
00150 }
00151 
00152 /************************************************************************/
00153 /*                             FlushCache()                             */
00154 /************************************************************************/
00155 
00163 void GDALDataset::FlushCache()
00164 
00165 {
00166     int         i;
00167 
00168     // This sometimes happens if a dataset is destroyed before completely
00169     // built. 
00170 
00171     if( papoBands == NULL )
00172         return;
00173 
00174     for( i = 0; i < nBands; i++ )
00175     {
00176         if( papoBands[i] != NULL )
00177             papoBands[i]->FlushCache();
00178     }
00179 }
00180 
00181 /************************************************************************/
00182 /*                          RasterInitialize()                          */
00183 /*                                                                      */
00184 /*      Initialize raster size                                          */
00185 /************************************************************************/
00186 
00187 void GDALDataset::RasterInitialize( int nXSize, int nYSize )
00188 
00189 {
00190     CPLAssert( nXSize > 0 && nYSize > 0 );
00191     
00192     nRasterXSize = nXSize;
00193     nRasterYSize = nYSize;
00194 }
00195 
00196 /************************************************************************/
00197 /*                              SetBand()                               */
00198 /*                                                                      */
00199 /*      Set a band in the band array, updating the band count, and      */
00200 /*      array size appropriately.                                       */
00201 /************************************************************************/
00202 
00203 void GDALDataset::SetBand( int nNewBand, GDALRasterBand * poBand )
00204 
00205 {
00206 /* -------------------------------------------------------------------- */
00207 /*      Do we need to grow the bands list?                              */
00208 /* -------------------------------------------------------------------- */
00209     if( nBands < nNewBand || papoBands == NULL ) {
00210         int             i;
00211 
00212         if( papoBands == NULL )
00213             papoBands = (GDALRasterBand **)
00214                 VSICalloc(sizeof(GDALRasterBand*), MAX(nNewBand,nBands));
00215         else
00216             papoBands = (GDALRasterBand **)
00217                 VSIRealloc(papoBands, sizeof(GDALRasterBand*) *
00218                            MAX(nNewBand,nBands));
00219 
00220         for( i = nBands; i < nNewBand; i++ )
00221             papoBands[i] = NULL;
00222 
00223         nBands = MAX(nBands,nNewBand);
00224     }
00225 
00226 /* -------------------------------------------------------------------- */
00227 /*      Set the band.  Resetting the band is currently not permitted.   */
00228 /* -------------------------------------------------------------------- */
00229     CPLAssert( papoBands[nNewBand-1] == NULL );
00230 
00231     papoBands[nNewBand-1] = poBand;
00232 
00233 /* -------------------------------------------------------------------- */
00234 /*      Set back reference information on the raster band.  Note        */
00235 /*      that the GDALDataset is a friend of the GDALRasterBand          */
00236 /*      specifically to allow this.                                     */
00237 /* -------------------------------------------------------------------- */
00238     poBand->nBand = nNewBand;
00239     poBand->poDS = this;
00240     poBand->nRasterXSize = nRasterXSize;
00241     poBand->nRasterYSize = nRasterYSize;
00242     poBand->eAccess = eAccess; /* default access to be same as dataset */
00243 }
00244 
00245 /************************************************************************/
00246 /*                           GetRasterXSize()                           */
00247 /************************************************************************/
00248 
00259 int GDALDataset::GetRasterXSize()
00260 
00261 {
00262     return nRasterXSize;
00263 }
00264 
00265 /************************************************************************/
00266 /*                         GDALGetRasterXSize()                         */
00267 /************************************************************************/
00268 
00269 int GDALGetRasterXSize( GDALDatasetH hDataset )
00270 
00271 {
00272     return ((GDALDataset *) hDataset)->GetRasterXSize();
00273 }
00274 
00275 
00276 /************************************************************************/
00277 /*                           GetRasterYSize()                           */
00278 /************************************************************************/
00279 
00290 int GDALDataset::GetRasterYSize()
00291 
00292 {
00293     return nRasterYSize;
00294 }
00295 
00296 /************************************************************************/
00297 /*                         GDALGetRasterYSize()                         */
00298 /************************************************************************/
00299 
00300 int GDALGetRasterYSize( GDALDatasetH hDataset )
00301 
00302 {
00303     return ((GDALDataset *) hDataset)->GetRasterYSize();
00304 }
00305 
00306 /************************************************************************/
00307 /*                           GetRasterBand()                            */
00308 /************************************************************************/
00309 
00323 GDALRasterBand * GDALDataset::GetRasterBand( int nBandId )
00324 
00325 {
00326     if( nBandId < 1 || nBandId > nBands )
00327     {
00328         CPLError( CE_Fatal, CPLE_IllegalArg,
00329                   "GDALDataset::GetRasterBand(%d) - Illegal band #\n",
00330                   nBandId );
00331     }
00332 
00333     return( papoBands[nBandId-1] );
00334 }
00335 
00336 /************************************************************************/
00337 /*                         GDALGetRasterBand()                          */
00338 /************************************************************************/
00339 
00340 GDALRasterBandH GDALGetRasterBand( GDALDatasetH hDS, int nBandId )
00341 
00342 {
00343     return( (GDALRasterBandH) ((GDALDataset *) hDS)->GetRasterBand(nBandId) );
00344 }
00345 
00346 /************************************************************************/
00347 /*                           GetRasterCount()                           */
00348 /************************************************************************/
00349 
00358 int GDALDataset::GetRasterCount()
00359 
00360 {
00361     return( nBands );
00362 }
00363 
00364 /************************************************************************/
00365 /*                         GDALGetRasterCount()                         */
00366 /************************************************************************/
00367 
00368 int GDALGetRasterCount( GDALDatasetH hDS )
00369 
00370 {
00371     return( ((GDALDataset *) hDS)->GetRasterCount() );
00372 }
00373 
00374 /************************************************************************/
00375 /*                          GetProjectionRef()                          */
00376 /************************************************************************/
00377 
00394 const char *GDALDataset::GetProjectionRef()
00395 
00396 {
00397     return( "" );
00398 }
00399 
00400 /************************************************************************/
00401 /*                        GDALGetProjectionRef()                        */
00402 /************************************************************************/
00403 
00404 const char *GDALGetProjectionRef( GDALDatasetH hDS )
00405 
00406 {
00407     return( ((GDALDataset *) hDS)->GetProjectionRef() );
00408 }
00409 
00410 /************************************************************************/
00411 /*                           SetProjection()                            */
00412 /************************************************************************/
00413 
00429 CPLErr GDALDataset::SetProjection( const char * )
00430 
00431 {
00432     return CE_Failure;
00433 }
00434 
00435 /************************************************************************/
00436 /*                         GDALSetProjection()                          */
00437 /************************************************************************/
00438 
00439 CPLErr GDALSetProjection( GDALDatasetH hDS, const char * pszProjection )
00440 
00441 {
00442     return( ((GDALDataset *) hDS)->SetProjection(pszProjection) );
00443 }
00444 
00445 /************************************************************************/
00446 /*                          GetGeoTransform()                           */
00447 /************************************************************************/
00448 
00479 CPLErr GDALDataset::GetGeoTransform( double * padfTransform )
00480 
00481 {
00482     CPLAssert( padfTransform != NULL );
00483         
00484     padfTransform[0] = 0.0;     /* X Origin (top left corner) */
00485     padfTransform[1] = 1.0;     /* X Pixel size */
00486     padfTransform[2] = 0.0;
00487 
00488     padfTransform[3] = 0.0;     /* Y Origin (top left corner) */
00489     padfTransform[4] = 0.0;     
00490     padfTransform[5] = 1.0;     /* Y Pixel Size */
00491 
00492     return( CE_Failure );
00493 }
00494 
00495 /************************************************************************/
00496 /*                        GDALGetGeoTransform()                         */
00497 /************************************************************************/
00498 
00499 CPLErr GDALGetGeoTransform( GDALDatasetH hDS, double * padfTransform )
00500 
00501 {
00502     return( ((GDALDataset *) hDS)->GetGeoTransform(padfTransform) );
00503 }
00504 
00505 /************************************************************************/
00506 /*                          SetGeoTransform()                           */
00507 /************************************************************************/
00508 
00524 CPLErr GDALDataset::SetGeoTransform( double * )
00525 
00526 {
00527     CPLError( CE_Failure, CPLE_NotSupported,
00528               "SetGeoTransform() not supported for this dataset." );
00529     
00530     return( CE_Failure );
00531 }
00532 
00533 /************************************************************************/
00534 /*                        GDALSetGeoTransform()                         */
00535 /************************************************************************/
00536 
00537 CPLErr GDALSetGeoTransform( GDALDatasetH hDS, double * padfTransform )
00538 
00539 {
00540     return( ((GDALDataset *) hDS)->SetGeoTransform(padfTransform) );
00541 }
00542 
00543 /************************************************************************/
00544 /*                         GetInternalHandle()                          */
00545 /************************************************************************/
00546 
00558 void *GDALDataset::GetInternalHandle( const char * )
00559 
00560 {
00561     return( NULL );
00562 }
00563 
00564 /************************************************************************/
00565 /*                       GDALGetInternalHandle()                        */
00566 /************************************************************************/
00567 
00568 void *GDALGetInternalHandle( GDALDatasetH hDS, const char * pszRequest )
00569 
00570 {
00571     return( ((GDALDataset *) hDS)->GetInternalHandle(pszRequest) );
00572 }
00573 
00574 /************************************************************************/
00575 /*                             GetDriver()                              */
00576 /************************************************************************/
00577 
00587 GDALDriver * GDALDataset::GetDriver()
00588 
00589 {
00590     return poDriver;
00591 }
00592 
00593 /************************************************************************/
00594 /*                        GDALGetDatasetDriver()                        */
00595 /************************************************************************/
00596 
00597 GDALDriverH GDALGetDatasetDriver( GDALDatasetH hDataset )
00598 
00599 {
00600     return (GDALDriverH) ((GDALDataset *) hDataset)->GetDriver();
00601 }
00602 
00603 /************************************************************************/
00604 /*                             Reference()                              */
00605 /************************************************************************/
00606 
00617 int GDALDataset::Reference()
00618 
00619 {
00620     return ++nRefCount;
00621 }
00622 
00623 /************************************************************************/
00624 /*                        GDALReferenceDataset()                        */
00625 /************************************************************************/
00626 
00627 int GDALReferenceDataset( GDALDatasetH hDataset )
00628 
00629 {
00630     return ((GDALDataset *) hDataset)->Reference();
00631 }
00632 
00633 /************************************************************************/
00634 /*                             Reference()                              */
00635 /************************************************************************/
00636 
00648 int GDALDataset::Dereference()
00649 
00650 {
00651     return --nRefCount;
00652 }
00653 
00654 /************************************************************************/
00655 /*                       GDALDereferenceDataset()                       */
00656 /************************************************************************/
00657 
00658 int GDALDereferenceDataset( GDALDatasetH hDataset )
00659 
00660 {
00661     return ((GDALDataset *) hDataset)->Dereference();
00662 }
00663 
00664 /************************************************************************/
00665 /*                            GetGCPCount()                             */
00666 /************************************************************************/
00667 
00676 int GDALDataset::GetGCPCount()
00677 
00678 {
00679     return 0;
00680 }
00681 
00682 /************************************************************************/
00683 /*                          GDALGetGCPCount()                           */
00684 /************************************************************************/
00685 
00686 int GDALGetGCPCount( GDALDatasetH hDS )
00687 
00688 {
00689     return ((GDALDataset *) hDS)->GetGCPCount();
00690 }
00691 
00692 /************************************************************************/
00693 /*                          GetGCPProjection()                          */
00694 /************************************************************************/
00695 
00706 const char *GDALDataset::GetGCPProjection()
00707 
00708 {
00709     return "";
00710 }
00711 
00712 /************************************************************************/
00713 /*                        GDALGetGCPProjection()                        */
00714 /************************************************************************/
00715 
00716 const char *GDALGetGCPProjection( GDALDatasetH hDS )
00717 
00718 {
00719     return ((GDALDataset *) hDS)->GetGCPProjection();
00720 }
00721 
00722 /************************************************************************/
00723 /*                               GetGCPs()                              */
00724 /************************************************************************/
00725 
00735 const GDAL_GCP *GDALDataset::GetGCPs()
00736 
00737 {
00738     return NULL;
00739 }
00740 
00741 /************************************************************************/
00742 /*                            GDALGetGCPs()                             */
00743 /************************************************************************/
00744 
00745 const GDAL_GCP *GDALGetGCPs( GDALDatasetH hDS )
00746 
00747 {
00748     return ((GDALDataset *) hDS)->GetGCPs();
00749 }
00750 
00751 /************************************************************************/
00752 /*                           BuildOverviews()                           */
00753 /************************************************************************/
00754 
00783 CPLErr GDALDataset::BuildOverviews( const char *pszResampling, 
00784                                     int nOverviews, int *panOverviewList, 
00785                                     int nBands, int *panBandList,
00786                                     GDALProgressFunc pfnProgress, 
00787                                     void * pProgressData )
00788     
00789 {
00790     CPLErr   eErr;
00791     int      *panAllBandList = NULL;
00792 
00793     if( nBands == 0 )
00794     {
00795         nBands = GetRasterCount();
00796         panAllBandList = (int *) CPLMalloc(sizeof(int) * nBands);
00797         for( int i = 0; i < nBands; i++ )
00798             panAllBandList[i] = i+1;
00799 
00800         panBandList = panAllBandList;
00801     }
00802 
00803     if( pfnProgress == NULL )
00804         pfnProgress = GDALDummyProgress;
00805 
00806     eErr = IBuildOverviews( pszResampling, nOverviews, panOverviewList, 
00807                             nBands, panBandList, pfnProgress, pProgressData );
00808 
00809     if( panAllBandList != NULL )
00810         CPLFree( panAllBandList );
00811 
00812     return eErr;
00813 }
00814 
00815 /************************************************************************/
00816 /*                         GDALBuildOverviews()                         */
00817 /************************************************************************/
00818 
00819 CPLErr GDALBuildOverviews( GDALDatasetH hDataset,
00820                            const char *pszResampling, 
00821                            int nOverviews, int *panOverviewList, 
00822                            int nBands, int *panBandList,
00823                            GDALProgressFunc pfnProgress, 
00824                            void * pProgressData )
00825 
00826 {
00827     return ((GDALDataset *) hDataset)->BuildOverviews(
00828         pszResampling, nOverviews, panOverviewList, nBands, panBandList, 
00829         pfnProgress, pProgressData );
00830 }
00831     
00832 /************************************************************************/
00833 /*                          IBuildOverviews()                           */
00834 /*                                                                      */
00835 /*      Default implementation.                                         */
00836 /************************************************************************/
00837 
00838 CPLErr GDALDataset::IBuildOverviews( const char *pszResampling, 
00839                                      int nOverviews, int *panOverviewList, 
00840                                      int nBands, int *panBandList,
00841                                      GDALProgressFunc pfnProgress, 
00842                                      void * pProgressData )
00843     
00844 {
00845     if( pfnProgress == NULL )
00846         pfnProgress = GDALDummyProgress;
00847 
00848     if( oOvManager.IsInitialized() )
00849         return oOvManager.BuildOverviews( NULL, pszResampling, 
00850                                           nOverviews, panOverviewList,
00851                                           nBands, panBandList,
00852                                           pfnProgress, pProgressData );
00853     else
00854     {
00855         CPLError( CE_Failure, CPLE_NotSupported,
00856                   "BuildOverviews() not supported for this dataset." );
00857         
00858         return( CE_Failure );
00859     }
00860 }
00861 

Generated at Thu Jul 5 09:16:12 2001 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000