root/tags/gdal_1_3_2/gcore/gdaldataset.cpp
| Revision 9300, 63.0 kB (checked in by fwarmerdam, 3 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /****************************************************************************** |
| 2 | * $Id$ |
| 3 | * |
| 4 | * Project: GDAL Core |
| 5 | * Purpose: Base class for raster file formats. |
| 6 | * Author: Frank Warmerdam, warmerdam@pobox.com |
| 7 | * |
| 8 | ****************************************************************************** |
| 9 | * Copyright (c) 1998, 2003, Frank Warmerdam |
| 10 | * |
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 12 | * copy of this software and associated documentation files (the "Software"), |
| 13 | * to deal in the Software without restriction, including without limitation |
| 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 15 | * and/or sell copies of the Software, and to permit persons to whom the |
| 16 | * Software is furnished to do so, subject to the following conditions: |
| 17 | * |
| 18 | * The above copyright notice and this permission notice shall be included |
| 19 | * in all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 22 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 24 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 | * DEALINGS IN THE SOFTWARE. |
| 28 | ****************************************************************************** |
| 29 | * |
| 30 | * $Log$ |
| 31 | * Revision 1.57 2006/03/03 19:44:45 fwarmerdam |
| 32 | * force C numeric locale in select locations |
| 33 | * |
| 34 | * Revision 1.56 2005/09/23 20:52:55 fwarmerdam |
| 35 | * avoid issuing NotSupported errors if GMO_IGNORE_UNIMPLEMENTED is set |
| 36 | * |
| 37 | * Revision 1.55 2005/07/25 23:15:31 fwarmerdam |
| 38 | * Fixed another typo. |
| 39 | * |
| 40 | * Revision 1.54 2005/07/25 23:13:38 fwarmerdam |
| 41 | * Fixed typo in BuildOverviews docs. |
| 42 | * |
| 43 | * Revision 1.53 2005/07/11 17:10:02 fwarmerdam |
| 44 | * moved in GDALOpen, GDALClose - make shared list thread safer |
| 45 | * |
| 46 | * Revision 1.52 2005/06/20 01:52:47 fwarmerdam |
| 47 | * an illegal band in GetRasterBand() no longer fatal |
| 48 | * |
| 49 | * Revision 1.51 2005/05/23 06:42:16 fwarmerdam |
| 50 | * added mutex to protect dataset list |
| 51 | * |
| 52 | * Revision 1.50 2005/04/20 16:39:04 fwarmerdam |
| 53 | * Fixed last fix. |
| 54 | * |
| 55 | * Revision 1.49 2005/04/20 16:38:10 fwarmerdam |
| 56 | * Undo last change, error is fatal. |
| 57 | * |
| 58 | * Revision 1.48 2005/04/20 16:32:06 fwarmerdam |
| 59 | * Ensure GetRasterBand() returns NULL on illegal band. |
| 60 | * |
| 61 | * Revision 1.47 2005/04/04 15:24:48 fwarmerdam |
| 62 | * Most C entry points now CPL_STDCALL |
| 63 | * |
| 64 | * Revision 1.46 2005/03/09 17:06:48 fwarmerdam |
| 65 | * Added use of BlockBasedRasterIO() if bForceCachedIO turned on. untested. |
| 66 | * |
| 67 | * Revision 1.45 2005/02/17 22:13:16 fwarmerdam |
| 68 | * added bForceCachedIO on dataset |
| 69 | * |
| 70 | * Revision 1.44 2004/12/10 19:04:07 fwarmerdam |
| 71 | * fix up docs a bit |
| 72 | * |
| 73 | * Revision 1.43 2004/12/02 20:32:28 fwarmerdam |
| 74 | * added AdviseRead methods |
| 75 | * |
| 76 | * Revision 1.42 2004/10/01 13:28:26 fwarmerdam |
| 77 | * Fixed osr_tutorial link. |
| 78 | * |
| 79 | * Revision 1.41 2003/05/21 04:45:39 warmerda |
| 80 | * avoid warings about unused formal parameters |
| 81 | * |
| 82 | * Revision 1.40 2003/05/21 03:05:47 warmerda |
| 83 | * remove unused variable |
| 84 | * |
| 85 | * Revision 1.39 2003/05/14 08:53:10 dron |
| 86 | * Fixed mistake in RasterIO() description. |
| 87 | * |
| 88 | * Revision 1.38 2003/05/08 14:38:40 warmerda |
| 89 | * added BlockBasedFlushCache |
| 90 | * |
| 91 | * Revision 1.37 2003/04/30 17:13:48 warmerda |
| 92 | * added docs for many C functions |
| 93 | * |
| 94 | * Revision 1.36 2003/04/25 19:49:51 warmerda |
| 95 | * first crack at RasterIO implementation |
| 96 | * |
| 97 | * Revision 1.35 2003/03/18 05:58:52 warmerda |
| 98 | * Added GDALFlushCache(). |
| 99 | * |
| 100 | * Revision 1.34 2003/02/13 16:18:58 warmerda |
| 101 | * Fixed typo. |
| 102 | * |
| 103 | * Revision 1.33 2003/02/13 16:10:23 warmerda |
| 104 | * Cleaned up GetProjectionRef() info. |
| 105 | * |
| 106 | * Revision 1.32 2003/01/28 16:54:49 warmerda |
| 107 | * indicate required include file |
| 108 | * |
| 109 | * Revision 1.31 2003/01/28 16:07:31 warmerda |
| 110 | * improved documentation |
| 111 | */ |
| 112 | |
| 113 | #include "gdal_priv.h" |
| 114 | #include "cpl_string.h" |
| 115 | #include "cpl_multiproc.h" |
| 116 | |
| 117 | CPL_CVSID("$Id$"); |
| 118 | |
| 119 | static volatile int nGDALDatasetCount = 0; |
| 120 | static GDALDataset ** volatile papoGDALDatasetList = NULL; |
| 121 | static void *hDLMutex = NULL; |
| 122 | |
| 123 | /************************************************************************/ |
| 124 | /* ==================================================================== */ |
| 125 | /* GDALDataset */ |
| 126 | /* ==================================================================== */ |
| 127 | /************************************************************************/ |
| 128 | |
| 129 | /** |
| 130 | * \class GDALDataset "gdal_priv.h" |
| 131 | * |
| 132 | * A dataset encapsulating one or more raster bands. Details are |
| 133 | * further discussed in the <a href="gdal_datamodel.html#GDALDataset">GDAL |
| 134 | * Data Model</a>. |
| 135 | * |
| 136 | * Use GDALOpen() or GDALOpenShared() to create a GDALDataset for a named file, |
| 137 | * or GDALDriver::Create() or GDALDriver::CreateCopy() to create a new |
| 138 | * dataset. |
| 139 | */ |
| 140 | |
| 141 | /************************************************************************/ |
| 142 | /* GDALDataset() */ |
| 143 | /************************************************************************/ |
| 144 | |
| 145 | GDALDataset::GDALDataset() |
| 146 | |
| 147 | { |
| 148 | poDriver = NULL; |
| 149 | eAccess = GA_ReadOnly; |
| 150 | nRasterXSize = 512; |
| 151 | nRasterYSize = 512; |
| 152 | nBands = 0; |
| 153 | papoBands = NULL; |
| 154 | nRefCount = 1; |
| 155 | bShared = FALSE; |
| 156 | |
| 157 | /* -------------------------------------------------------------------- */ |
| 158 | /* Add this dataset to the open dataset list. */ |
| 159 | /* -------------------------------------------------------------------- */ |
| 160 | { |
| 161 | CPLMutexHolderD( &hDLMutex ); |
| 162 | |
| 163 | nGDALDatasetCount++; |
| 164 | papoGDALDatasetList = (GDALDataset ** volatile) |
| 165 | CPLRealloc( papoGDALDatasetList, sizeof(void *)*nGDALDatasetCount); |
| 166 | papoGDALDatasetList[nGDALDatasetCount-1] = this; |
| 167 | } |
| 168 | |
| 169 | /* -------------------------------------------------------------------- */ |
| 170 | /* Set forced caching flag. */ |
| 171 | /* -------------------------------------------------------------------- */ |
| 172 | bForceCachedIO = CSLTestBoolean( |
| 173 | CPLGetConfigOption( "GDAL_FORCE_CACHING", "NO") ); |
| 174 | } |
| 175 | |
| 176 | /************************************************************************/ |
| 177 | /* ~GDALDataset() */ |
| 178 | /************************************************************************/ |
| 179 | |
| 180 | /** |
| 181 | * Destroy an open GDALDataset. |
| 182 | * |
| 183 | * This is the accepted method of closing a GDAL dataset and deallocating |
| 184 | * all resources associated with it. |
| 185 | * |
| 186 | * Equivelent of the C callable GDALClose(). Except that GDALClose() first |
| 187 | * decrements the reference count, and then closes only if it has dropped to |
| 188 | * zero. |
| 189 | */ |
| 190 | |
| 191 | GDALDataset::~GDALDataset() |
| 192 | |
| 193 | { |
| 194 | int i; |
| 195 | |
| 196 | CPLDebug( "GDAL", "GDALClose(%s)\n", GetDescription() ); |
| 197 | |
| 198 | /* -------------------------------------------------------------------- */ |
| 199 | /* Remove dataset from the "open" dataset list. */ |
| 200 | /* -------------------------------------------------------------------- */ |
| 201 | { |
| 202 | CPLMutexHolderD( &hDLMutex ); |
| 203 | |
| 204 | for( i = 0; i < nGDALDatasetCount; i++ ) |
| 205 | { |
| 206 | if( papoGDALDatasetList[i] == this ) |
| 207 | { |
| 208 | papoGDALDatasetList[i] = |
| 209 | papoGDALDatasetList[nGDALDatasetCount-1]; |
| 210 | nGDALDatasetCount--; |
| 211 | if( nGDALDatasetCount == 0 ) |
| 212 | { |
| 213 | CPLFree( papoGDALDatasetList ); |
| 214 | papoGDALDatasetList = NULL; |
| 215 | } |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* -------------------------------------------------------------------- */ |
| 222 | /* Destroy the raster bands if they exist. */ |
| 223 | /* -------------------------------------------------------------------- */ |
| 224 | for( i = 0; i < nBands && papoBands != NULL; i++ ) |
| 225 | { |
| 226 | if( papoBands[i] != NULL ) |
| 227 | delete papoBands[i]; |
| 228 | } |
| 229 | |
| 230 | CPLFree( papoBands ); |
| 231 | } |
| 232 | |
| 233 | /************************************************************************/ |
| 234 | /* FlushCache() */ |
| 235 | /************************************************************************/ |
| 236 | |
| 237 | /** |
| 238 | * Flush all write cached data to disk. |
| 239 | * |
| 240 | * Any raster (or other GDAL) data written via GDAL calls, but buffered |
| 241 | * internally will be written to disk. |
| 242 | * |
| 243 | * This method is the same as the C function GDALFlushCache(). |
| 244 | */ |
| 245 | |
| 246 | void GDALDataset::FlushCache() |
| 247 | |
| 248 | { |
| 249 | int i; |
| 250 | |
| 251 | // This sometimes happens if a dataset is destroyed before completely |
| 252 | // built. |
| 253 | |
| 254 | if( papoBands == NULL ) |
| 255 | return; |
| 256 | |
| 257 | for( i = 0; i < nBands; i++ ) |
| 258 | { |
| 259 | if( papoBands[i] != NULL ) |
| 260 | papoBands[i]->FlushCache(); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /************************************************************************/ |
| 265 | /* GDALFlushCache() */ |
| 266 | /************************************************************************/ |
| 267 | |
| 268 | /** |
| 269 | * @see GDALDataset::FlushCache(). |
| 270 | */ |
| 271 | |
| 272 | void CPL_STDCALL GDALFlushCache( GDALDatasetH hDS ) |
| 273 | |
| 274 | { |
| 275 | ((GDALDataset *) hDS)->FlushCache(); |
| 276 | } |
| 277 | |
| 278 | /************************************************************************/ |
| 279 | /* BlockBasedFlushCache() */ |
| 280 | /* */ |
| 281 | /* This helper method can be called by the */ |
| 282 | /* GDALDataset::FlushCache() for particular drivers to ensure */ |
| 283 | /* that buffers will be flushed in a manner suitable for pixel */ |
| 284 | /* interleaved (by block) IO. That is, if all the bands have */ |
| 285 | /* the same size blocks then a given block will be flushed for */ |
| 286 | /* all bands before proceeding to the next block. */ |
| 287 | /************************************************************************/ |
| 288 | |
| 289 | void GDALDataset::BlockBasedFlushCache() |
| 290 | |
| 291 | { |
| 292 | GDALRasterBand *poBand1; |
| 293 | int nBlockXSize, nBlockYSize, iBand; |
| 294 | |
| 295 | poBand1 = GetRasterBand( 1 ); |
| 296 | if( poBand1 == NULL ) |
| 297 | { |
| 298 | GDALDataset::FlushCache(); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | poBand1->GetBlockSize( &nBlockXSize, &nBlockYSize ); |
| 303 | |
| 304 | /* -------------------------------------------------------------------- */ |
| 305 | /* Verify that all bands match. */ |
| 306 | /* -------------------------------------------------------------------- */ |
| 307 | for( iBand = 1; iBand < nBands; iBand++ ) |
| 308 | { |
| 309 | int nThisBlockXSize, nThisBlockYSize; |
| 310 | GDALRasterBand *poBand = GetRasterBand( iBand+1 ); |
| 311 | |
| 312 | poBand->GetBlockSize( &nThisBlockXSize, &nThisBlockYSize ); |
| 313 | if( nThisBlockXSize != nBlockXSize && nThisBlockYSize != nBlockYSize ) |
| 314 | { |
| 315 | GDALDataset::FlushCache(); |
| 316 | return; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /* -------------------------------------------------------------------- */ |
| 321 | /* Now flush writable data. */ |
| 322 | /* -------------------------------------------------------------------- */ |
| 323 | for( int iY = 0; iY < poBand1->nBlocksPerColumn; iY++ ) |
| 324 | { |
| 325 | for( int iX = 0; iX < poBand1->nBlocksPerRow; iX++ ) |
| 326 | { |
| 327 | for( iBand = 0; iBand < nBands; iBand++ ) |
| 328 | { |
| 329 | GDALRasterBand *poBand = GetRasterBand( iBand+1 ); |
| 330 | |
| 331 | if( poBand->papoBlocks[iX + iY*poBand1->nBlocksPerRow] != NULL) |
| 332 | { |
| 333 | CPLErr eErr; |
| 334 | |
| 335 | eErr = poBand->FlushBlock( iX, iY ); |
| 336 | |
| 337 | if( eErr != CE_None ) |
| 338 | return; |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /************************************************************************/ |
| 346 | /* RasterInitialize() */ |
| 347 | /* */ |
| 348 | /* Initialize raster size */ |
| 349 | /************************************************************************/ |
| 350 | |
| 351 | void GDALDataset::RasterInitialize( int nXSize, int nYSize ) |
| 352 | |
| 353 | { |
| 354 | CPLAssert( nXSize > 0 && nYSize > 0 ); |
| 355 | |
| 356 | nRasterXSize = nXSize; |
| 357 | nRasterYSize = nYSize; |
| 358 | } |
| 359 | |
| 360 | /************************************************************************/ |
| 361 | /* AddBand() */ |
| 362 | /************************************************************************/ |
| 363 | |
| 364 | /** |
| 365 | * Add a band to a dataset. |
| 366 | * |
| 367 | * This method will add a new band to the dataset if the underlying format |
| 368 | * supports this action. Most formats do not. |
| 369 | * |
| 370 | * Note that the new GDALRasterBand is not returned. It may be fetched |
| 371 | * after successful completion of the method by calling |
| 372 | * GDALDataset::GetRasterBand(GDALDataset::GetRasterCount()-1) as the newest |
| 373 | * band will always be the last band. |
| 374 | * |
| 375 | * @param eType the data type of the pixels in the new band. |
| 376 | * |
| 377 | * @param papszOptions a list of NAME=VALUE option strings. The supported |
| 378 | * options are format specific. NULL may be passed by default. |
| 379 | * |
| 380 | * @return CE_None on success or CE_Failure on failure. |
| 381 | */ |
| 382 | |
| 383 | CPLErr GDALDataset::AddBand( GDALDataType eType, char ** papszOptions ) |
| 384 | |
| 385 | { |
| 386 | (void) eType; |
| 387 | (void) papszOptions; |
| 388 | |
| 389 | CPLError( CE_Failure, CPLE_NotSupported, |
| 390 | "Dataset does not support the AddBand() method." ); |
| 391 | |
| 392 | return CE_Failure; |
| 393 | } |
| 394 | |
| 395 | /************************************************************************/ |
| 396 | /* GDALAddBand() */ |
| 397 | /************************************************************************/ |
| 398 | |
| 399 | /** |
| 400 | * @see GDALDataset::AddBand(). |
| 401 | */ |
| 402 | |
| 403 | CPLErr CPL_STDCALL GDALAddBand( GDALDatasetH hDataset, |
| 404 | GDALDataType eType, char **papszOptions ) |
| 405 | |
| 406 | { |
| 407 | return ((GDALDataset *) hDataset)->AddBand( eType, papszOptions ); |
| 408 | } |
| 409 | |
| 410 | /************************************************************************/ |
| 411 | /* SetBand() */ |
| 412 | /* */ |
| 413 | /* Set a band in the band array, updating the band count, and */ |
| 414 | /* array size appropriately. */ |
| 415 | /************************************************************************/ |
| 416 | |
| 417 | void GDALDataset::SetBand( int nNewBand, GDALRasterBand * poBand ) |
| 418 | |
| 419 | { |
| 420 | /* -------------------------------------------------------------------- */ |
| 421 | /* Do we need to grow the bands list? */ |
| 422 | /* -------------------------------------------------------------------- */ |
| 423 | if( nBands < nNewBand || papoBands == NULL ) { |
| 424 | int i; |
| 425 | |
| 426 | if( papoBands == NULL ) |
| 427 | papoBands = (GDALRasterBand **) |
| 428 | VSICalloc(sizeof(GDALRasterBand*), MAX(nNewBand,nBands)); |
| 429 | else |
| 430 | papoBands = (GDALRasterBand **) |
| 431 | VSIRealloc(papoBands, sizeof(GDALRasterBand*) * |
| 432 | MAX(nNewBand,nBands)); |
| 433 | |
| 434 | for( i = nBands; i < nNewBand; i++ ) |
| 435 | papoBands[i] = NULL; |
| 436 | |
| 437 | nBands = MAX(nBands,nNewBand); |
| 438 | } |
| 439 | |
| 440 | /* -------------------------------------------------------------------- */ |
| 441 | /* Set the band. Resetting the band is currently not permitted. */ |
| 442 | /* -------------------------------------------------------------------- */ |
| 443 | CPLAssert( papoBands[nNewBand-1] == NULL ); |
| 444 | |
| 445 | papoBands[nNewBand-1] = poBand; |
| 446 | |
| 447 | /* -------------------------------------------------------------------- */ |
| 448 | /* Set back reference information on the raster band. Note */ |
| 449 | /* that the GDALDataset is a friend of the GDALRasterBand */ |
| 450 | /* specifically to allow this. */ |
| 451 | /* -------------------------------------------------------------------- */ |
| 452 | poBand->nBand = nNewBand; |
| 453 | poBand->poDS = this; |
| 454 | poBand->nRasterXSize = nRasterXSize; |
| 455 | poBand->nRasterYSize = nRasterYSize; |
| 456 | poBand->eAccess = eAccess; /* default access to be same as dataset */ |
| 457 | } |
| 458 | |
| 459 | /************************************************************************/ |
| 460 | /* GetRasterXSize() */ |
| 461 | /************************************************************************/ |
| 462 | |
| 463 | /** |
| 464 | |
| 465 | Fetch raster width in pixels. |
| 466 | |
| 467 | Equivelent of the C function GDALGetRasterXSize(). |
| 468 | |
| 469 | @return the width in pixels of raster bands in this GDALDataset. |
| 470 | |
| 471 | */ |
| 472 | |
| 473 | int GDALDataset::GetRasterXSize() |
| 474 | |
| 475 | { |
| 476 | return nRasterXSize; |
| 477 | } |
| 478 | |
| 479 | /************************************************************************/ |
| 480 | /* GDALGetRasterXSize() */ |
| 481 | /************************************************************************/ |
| 482 | |
| 483 | /** |
| 484 | * @see GDALDataset::GetRasterXSize(). |
| 485 | */ |
| 486 | |
| 487 | int CPL_STDCALL GDALGetRasterXSize( GDALDatasetH hDataset ) |
| 488 | |
| 489 | { |
| 490 | return ((GDALDataset *) hDataset)->GetRasterXSize(); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | /************************************************************************/ |
| 495 | /* GetRasterYSize() */ |
| 496 | /************************************************************************/ |
| 497 | |
| 498 | /** |
| 499 | |
| 500 | Fetch raster height in pixels. |
| 501 | |
| 502 | Equivelent of the C function GDALGetRasterYSize(). |
| 503 | |
| 504 | @return the height in pixels of raster bands in this GDALDataset. |
| 505 | |
| 506 | */ |
| 507 | |
| 508 | int GDALDataset::GetRasterYSize() |
| 509 | |
| 510 | { |
| 511 | return nRasterYSize; |
| 512 | } |
| 513 | |
| 514 | /************************************************************************/ |
| 515 | /* GDALGetRasterYSize() */ |
| 516 | /************************************************************************/ |
| 517 | |
| 518 | /** |
| 519 | * @see GDALDataset::GetRasterYSize(). |
| 520 | */ |
| 521 | |
| 522 | int CPL_STDCALL GDALGetRasterYSize( GDALDatasetH hDataset ) |
| 523 | |
| 524 | { |
| 525 | return ((GDALDataset *) hDataset)->GetRasterYSize(); |
| 526 | } |
| 527 | |
| 528 | /************************************************************************/ |
| 529 | /* GetRasterBand() */ |
| 530 | /************************************************************************/ |
| 531 | |
| 532 | /** |
| 533 | |
| 534 | Fetch a band object for a dataset. |
| 535 | |
| 536 | Equivelent of the C function GDALGetRasterBand(). |
| 537 | |
| 538 | @param nBandId the index number of the band to fetch, from 1 to |
| 539 | GetRasterCount(). |
| 540 | |
| 541 | @return the height in pixels of raster bands in this GDALDataset. |
| 542 | |
| 543 | */ |
| 544 | |
| 545 | GDALRasterBand * GDALDataset::GetRasterBand( int nBandId ) |
| 546 | |
| 547 | { |
| 548 | if( nBandId < 1 || nBandId > nBands ) |
| 549 | { |
| 550 | CPLError( CE_Failure, CPLE_IllegalArg, |
| 551 | "GDALDataset::GetRasterBand(%d) - Illegal band #\n", |
| 552 | nBandId ); |
| 553 | return NULL; |
| 554 | } |
| 555 | else |
| 556 | return( papoBands[nBandId-1] ); |
| 557 | } |
| 558 | |
| 559 | /************************************************************************/ |
| 560 | /* GDALGetRasterBand() */ |
| 561 | /************************************************************************/ |
| 562 | |
| 563 | /** |
| 564 | * @see GDALDataset::GetRasterBand(). |
| 565 | */ |
| 566 | |
| 567 | GDALRasterBandH CPL_STDCALL GDALGetRasterBand( GDALDatasetH hDS, int nBandId ) |
| 568 | |
| 569 | { |
| 570 | return( (GDALRasterBandH) ((GDALDataset *) hDS)->GetRasterBand(nBandId) ); |
| 571 | } |
| 572 | |
| 573 | /************************************************************************/ |
| 574 | /* GetRasterCount() */ |
| 575 | /************************************************************************/ |
| 576 | |
| 577 | /** |
| 578 | * Fetch the number of raster bands on this dataset. |
| 579 | * |
| 580 | * Same as the C function GDALGetRasterCount(). |
| 581 | * |
| 582 | * @return the number of raster bands. |
| 583 | */ |
| 584 | |
| 585 | int GDALDataset::GetRasterCount() |
| 586 | |
| 587 | { |
| 588 | return( nBands ); |
| 589 | } |
| 590 | |
| 591 | /************************************************************************/ |
| 592 | /* GDALGetRasterCount() */ |
| 593 | /************************************************************************/ |
| 594 | |
| 595 | /** |
| 596 | * @see GDALDataset::GetRasterCount(). |
| 597 | */ |
| 598 | |
| 599 | int CPL_STDCALL GDALGetRasterCount( GDALDatasetH hDS ) |
| 600 | |
| 601 | { |
| 602 | return( ((GDALDataset *) hDS)->GetRasterCount() ); |
| 603 | } |
| 604 | |
| 605 | /************************************************************************/ |
| 606 | /* GetProjectionRef() */ |
| 607 | /************************************************************************/ |
| 608 | |
| 609 | /** |
| 610 | * Fetch the projection definition string for this dataset. |
| 611 | * |
| 612 | * Same as the C function GDALGetProjectionRef(). |
| 613 | * |
| 614 | * The returned string defines the projection coordinate system of the |
| 615 | * image in OpenGIS WKT format. It should be suitable for use with the |
| 616 | * OGRSpatialReference class. |
| 617 | * |
| 618 | * When a projection definition is not available an empty (but not NULL) |
| 619 | * string is returned. |
| 620 | * |
| 621 | * @return a pointer to an internal projection reference string. It should |
| 622 | * not be altered, freed or expected to last for long. |
| 623 | * |
| 624 | * @see http://www.gdal.org/ogr/osr_tutorial.html |
| 625 | */ |
| 626 | |
| 627 | const char *GDALDataset::GetProjectionRef() |
| 628 | |
| 629 | { |
| 630 | return( "" ); |
| 631 | } |
| 632 | |
| 633 | /************************************************************************/ |
| 634 | /* GDALGetProjectionRef() */ |
| 635 | /************************************************************************/ |
| 636 | |
| 637 | /** |
| 638 | * @see GDALDataset::GetProjectionRef() |
| 639 | */ |
| 640 | |
| 641 | const char * CPL_STDCALL GDALGetProjectionRef( GDALDatasetH hDS ) |
| 642 | |
| 643 | { |
| 644 | return( ((GDALDataset *) hDS)->GetProjectionRef() ); |
| 645 | } |
| 646 | |
| 647 | /************************************************************************/ |
| 648 | /* SetProjection() */ |
| 649 | /************************************************************************/ |
| 650 | |
| 651 | /** |
| 652 | * Set the projection reference string for this dataset. |
| 653 | * |
| 654 | * The string should be in OGC WKT or PROJ.4 format. An error may occur |
| 655 | * because of incorrectly specified projection strings, because the dataset |
| 656 | * is not writable, or because the dataset does not support the indicated |
| 657 | * projection. Many formats do not support writing projections. |
| 658 | * |
| 659 | * This method is the same as the C GDALSetProjection() function. |
| 660 | * |
| 661 | * @param pszProjection projection reference string. |
| 662 | * |
| 663 | * @return CE_Failure if an error occurs, otherwise CE_None. |
| 664 | */ |
| 665 | |
| 666 | CPLErr GDALDataset::SetProjection( const char * ) |
| 667 | |
| 668 | { |
| 669 | if( !(GetMOFlags() & GMO_IGNORE_UNIMPLEMENTED) ) |
| 670 | CPLError( CE_Failure, CPLE_NotSupported, |
| 671 | "Dataset does not support the SetProjection() method." ); |
| 672 | return CE_Failure; |
| 673 | } |
| 674 | |
| 675 | /************************************************************************/ |
| 676 | /* GDALSetProjection() */ |
| 677 | /************************************************************************/ |
| 678 | |
| 679 | /** |
| 680 | * @see GDALDataset::SetProjection() |
| 681 | */ |
| 682 | |
| 683 | CPLErr CPL_STDCALL GDALSetProjection( GDALDatasetH hDS, const char * pszProjection ) |
| 684 | |
| 685 | { |
| 686 | return( ((GDALDataset *) hDS)->SetProjection(pszProjection) ); |
| 687 | } |
| 688 | |
| 689 | /************************************************************************/ |
| 690 | /* GetGeoTransform() */ |
| 691 | /************************************************************************/ |
| 692 | |
| 693 | /** |
| 694 | * Fetch the affine transformation coefficients. |
| 695 | * |
| 696 | * Fetches the coefficients for transforming between pixel/line (P,L) raster |
| 697 | * space, and projection coordinates (Xp,Yp) space. |
| 698 | * |
| 699 | * \code |
| 700 | * Xp = padfTransform[0] + P*padfTransform[1] + L*padfTransform[2]; |
| 701 | * Yp = padfTransform[3] + P*padfTransform[4] + L*padfTransform[5]; |
| 702 | * \endcode |
| 703 | * |
| 704 | * In a north up image, padfTransform[1] is the pixel width, and |
| 705 | * padfTransform[5] is the pixel height. The upper left corner of the |
| 706 | * upper left pixel is at position (padfTransform[0],padfTransform[3]). |
| 707 | * |
| 708 | * The default transform is (0,1,0,0,0,1) and should be returned even when |
| 709 | * a CE_Failure error is returned, such as for formats that don't support |
| 710 | * transformation to projection coordinates. |
| 711 | * |
| 712 | * NOTE: GetGeoTransform() isn't expressive enough to handle the variety of |
| 713 | * OGC Grid Coverages pixel/line to projection transformation schemes. |
| 714 | * Eventually this method will be depreciated in favour of a more general |
| 715 | * scheme. |
| 716 | * |
| 717 | * This method does the same thing as the C GDALGetGeoTransform() function. |
| 718 | * |
| 719 | * @param padfTransform an existing six double buffer into which the |
| 720 | * transformation will be placed. |
| 721 | * |
| 722 | * @return CE_None on success, or CE_Failure if no transform can be fetched. |
| 723 | */ |
| 724 | |
| 725 | CPLErr GDALDataset::GetGeoTransform( double * padfTransform ) |
| 726 | |
| 727 | { |
| 728 | CPLAssert( padfTransform != NULL ); |
| 729 | |
| 730 | padfTransform[0] = 0.0; /* X Origin (top left corner) */ |
| 731 | padfTransform[1] = 1.0; /* X Pixel size */ |
| 732 | padfTransform[2] = 0.0; |
| 733 | |
| 734 | padfTransform[3] = 0.0; /* Y Origin (top left corner) */ |
| 735 | padfTransform[4] = 0.0; |
| 736 | padfTransform[5] = 1.0; /* Y Pixel Size */ |
| 737 | |
| 738 | return( CE_Failure ); |
| 739 | } |
| 740 | |
| 741 | /************************************************************************/ |
| 742 | /* GDALGetGeoTransform() */ |
| 743 | /************************************************************************/ |
| 744 | |
| 745 | /** |
| 746 | * @see GDALDataset::GetGeoTransform() |
| 747 | */ |
| 748 | |
| 749 | CPLErr CPL_STDCALL GDALGetGeoTransform( GDALDatasetH hDS, double * padfTransform ) |
| 750 | |
| 751 | { |
| 752 | return( ((GDALDataset *) hDS)->GetGeoTransform(padfTransform) ); |
| 753 | } |
| 754 | |
| 755 | /************************************************************************/ |
| 756 | /* SetGeoTransform() */ |
| 757 | /************************************************************************/ |
| 758 | |
| 759 | /** |
| 760 | * Set the affine transformation coefficients. |
| 761 | * |
| 762 | * See GetGeoTransform() for details on the meaning of the padfTransform |
| 763 | * coefficients. |
| 764 | * |
| 765 | * This method does the same thing as the C GDALSetGeoTransform() function. |
| 766 | * |
| 767 | * @param padfTransform a six double buffer containing the transformation |
| 768 | * coefficients to be written with the dataset. |
| 769 | * |
| 770 | * @return CE_None on success, or CE_Failure if this transform cannot be |
| 771 | * written. |
| 772 | */ |
| 773 | |
| 774 | CPLErr GDALDataset::SetGeoTransform( double * ) |
| 775 | |
| 776 | { |
| 777 | if( !(GetMOFlags() & GMO_IGNORE_UNIMPLEMENTED) ) |
| 778 | CPLError( CE_Failure, CPLE_NotSupported, |
| 779 | "SetGeoTransform() not supported for this dataset." ); |
| 780 | |
| 781 | return( CE_Failure ); |
| 782 | } |
| 783 | |
| 784 | /************************************************************************/ |
| 785 | /* GDALSetGeoTransform() */ |
| 786 | /************************************************************************/ |
| 787 | |
| 788 | /** |
| 789 | * @see GDALDataset::SetGeoTransform() |
| 790 | */ |
| 791 | |
| 792 | CPLErr CPL_STDCALL |
| 793 | GDALSetGeoTransform( GDALDatasetH hDS, double * padfTransform ) |
| 794 | |
| 795 | { |
| 796 | return( ((GDALDataset *) hDS)->SetGeoTransform(padfTransform) ); |
| 797 | } |
| 798 | |
| 799 | /************************************************************************/ |
| 800 | /* GetInternalHandle() */ |
| 801 | /************************************************************************/ |
| 802 | |
| 803 | /** |
| 804 | * Fetch a format specific internally meaningful handle. |
| 805 | * |
| 806 | * This method is the same as the C GDALGetInternalHandle() method. |
| 807 | * |
| 808 | * @param pszHandleName the handle name desired. The meaningful names |
| 809 | * will be specific to the file format. |
| 810 | * |
| 811 | * @return the desired handle value, or NULL if not recognised/supported. |
| 812 | */ |
| 813 | |
| 814 | void *GDALDataset::GetInternalHandle( const char * ) |
| 815 | |
| 816 | { |
| 817 | return( NULL ); |
| 818 | } |
| 819 | |
| 820 | /************************************************************************/ |
| 821 | /* GDALGetInternalHandle() */ |
| 822 | /************************************************************************/ |
| 823 | |
| 824 | /** |
| 825 | * @see GDALDataset::GetInternalHandle() |
| 826 | */ |
| 827 | |
| 828 | void * CPL_STDCALL |
| 829 | GDALGetInternalHandle( GDALDatasetH hDS, const char * pszRequest ) |
| 830 | |
| 831 | { |
| 832 | return( ((GDALDataset *) hDS)->GetInternalHandle(pszRequest) ); |
| 833 | } |
| 834 | |
| 835 | /************************************************************************/ |
| 836 | /* GetDriver() */ |
| 837 | /************************************************************************/ |
| 838 | |
| 839 | /** |
| 840 | * Fetch the driver to which this dataset relates. |
| 841 | * |
| 842 | * This method is the same as the C GDALGetDatasetDriver() function. |
| 843 | * |
| 844 | * @return the driver on which the dataset was created with GDALOpen() or |
| 845 | * GDALCreate(). |
| 846 | */ |
| 847 | |
| 848 | GDALDriver * GDALDataset::GetDriver() |
| 849 | |
| 850 | { |
| 851 | return poDriver; |
| 852 | } |
| 853 | |
| 854 | /************************************************************************/ |
| 855 | /* GDALGetDatasetDriver() */ |
| 856 | /************************************************************************/ |
| 857 | |
| 858 | /** |
| 859 | * @see GDALDataset::GetDriver() |
| 860 | */ |
| 861 | |
| 862 | GDALDriverH CPL_STDCALL GDALGetDatasetDriver( GDALDatasetH hDataset ) |
| 863 | |
| 864 | { |
| 865 | return (GDALDriverH) ((GDALDataset *) hDataset)->GetDriver(); |
| 866 | } |
| 867 | |
| 868 | /************************************************************************/ |
| 869 | /* Reference() */ |
| 870 | /************************************************************************/ |
| 871 | |
| 872 | /** |
| 873 | * Add one to dataset reference count. |
| 874 | * |
| 875 | * The reference is one after instantiation. |
| 876 | * |
| 877 | * This method is the same as the C GDALReferenceDataset() function. |
| 878 | * |
| 879 | * @return the post-increment reference count. |
| 880 | */ |
| 881 | |
| 882 | int GDALDataset::Reference() |
| 883 | |
| 884 | { |
| 885 | return ++nRefCount; |
| 886 | } |
| 887 | |
| 888 | /************************************************************************/ |
| 889 | /* GDALReferenceDataset() */ |
| 890 | /************************************************************************/ |
| 891 | |
| 892 | /** |
| 893 | * @see GDALDataset::Reference() |
| 894 | */ |
| 895 | |
| 896 | int CPL_STDCALL GDALReferenceDataset( GDALDatasetH hDataset ) |
| 897 | |
| 898 | { |
| 899 | return ((GDALDataset *) hDataset)->Reference(); |
| 900 | } |
| 901 | |
| 902 | /************************************************************************/ |
| 903 | /* Dereference() */ |
| 904 | /************************************************************************/ |
| 905 | |
| 906 | /** |
| 907 | * Subtract one from dataset reference count. |
| 908 | * |
| 909 | * The reference is one after instantiation. Generally when the reference |
| 910 | * count has dropped to zero the dataset may be safely deleted (closed). |
| 911 | * |
| 912 | * This method is the same as the C GDALDereferenceDataset() function. |
| 913 | * |
| 914 | * @return the post-decrement reference count. |
| 915 | */ |
| 916 | |
| 917 | int GDALDataset::Dereference() |
| 918 | |
| 919 | { |
| 920 | return --nRefCount; |
| 921 | } |
| 922 | |
| 923 | /************************************************************************/ |
| 924 | /* GDALDereferenceDataset() */ |
| 925 | /************************************************************************/ |
| 926 | |
| 927 | /** |
| 928 | * @see GDALDataset::Dereference() |
| 929 | */ |
| 930 | |
| 931 | int CPL_STDCALL GDALDereferenceDataset( GDALDatasetH hDataset ) |
| 932 | |
| 933 | { |
| 934 | return ((GDALDataset *) hDataset)->Dereference(); |
| 935 | } |
| 936 | |
| < |
