1 : /******************************************************************************
2 : * $Id: hdf5imagedataset.cpp 23068 2011-09-06 20:50:23Z antonio $
3 : *
4 : * Project: Hierarchical Data Format Release 5 (HDF5)
5 : * Purpose: Read subdatasets of HDF5 file.
6 : * Author: Denis Nadeau <denis.nadeau@gmail.com>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
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 : #define H5_USE_16_API
31 :
32 : #include "hdf5.h"
33 :
34 : #include "gdal_pam.h"
35 : #include "gdal_priv.h"
36 : #include "cpl_string.h"
37 : #include "hdf5dataset.h"
38 : #include "ogr_spatialref.h"
39 :
40 : CPL_CVSID("$Id: hdf5imagedataset.cpp 23068 2011-09-06 20:50:23Z antonio $");
41 :
42 : CPL_C_START
43 : void GDALRegister_HDF5Image(void);
44 : CPL_C_END
45 :
46 : /* release 1.6.3 or 1.6.4 changed the type of count in some api functions */
47 :
48 : #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR <= 6 \
49 : && (H5_VERS_MINOR < 6 || H5_VERS_RELEASE < 3)
50 : # define H5OFFSET_TYPE hssize_t
51 : #else
52 : # define H5OFFSET_TYPE hsize_t
53 : #endif
54 :
55 : class HDF5ImageDataset : public HDF5Dataset
56 : {
57 :
58 : friend class HDF5ImageRasterBand;
59 :
60 : char *pszProjection;
61 : char *pszGCPProjection;
62 : GDAL_GCP *pasGCPList;
63 : int nGCPCount;
64 : OGRSpatialReference oSRS;
65 :
66 : hsize_t *dims,*maxdims;
67 : HDF5GroupObjects *poH5Objects;
68 : int ndims,dimensions;
69 : hid_t dataset_id;
70 : hid_t dataspace_id;
71 : hsize_t size;
72 : haddr_t address;
73 : hid_t datatype;
74 : hid_t native;
75 : H5T_class_t clas;
76 :
77 : public:
78 : HDF5ImageDataset();
79 : ~HDF5ImageDataset();
80 :
81 : CPLErr CreateProjections( );
82 : static GDALDataset *Open( GDALOpenInfo * );
83 : static int Identify( GDALOpenInfo * );
84 :
85 : const char *GetProjectionRef();
86 : virtual int GetGCPCount( );
87 : virtual const char *GetGCPProjection();
88 : virtual const GDAL_GCP *GetGCPs( );
89 :
90 : };
91 :
92 : /************************************************************************/
93 : /* ==================================================================== */
94 : /* HDF5ImageDataset */
95 : /* ==================================================================== */
96 : /************************************************************************/
97 :
98 : /************************************************************************/
99 : /* HDF5ImageDataset() */
100 : /************************************************************************/
101 10 : HDF5ImageDataset::HDF5ImageDataset()
102 : {
103 10 : nGCPCount = 0;
104 10 : pszProjection = NULL;
105 10 : pszGCPProjection= NULL;
106 10 : pasGCPList = NULL;
107 10 : poH5Objects = NULL;
108 10 : poH5RootGroup = NULL;
109 10 : dims = NULL;
110 10 : maxdims = NULL;
111 10 : papszMetadata = NULL;
112 10 : }
113 :
114 : /************************************************************************/
115 : /* ~HDF5ImageDataset() */
116 : /************************************************************************/
117 10 : HDF5ImageDataset::~HDF5ImageDataset( )
118 : {
119 10 : FlushCache();
120 :
121 10 : CPLFree(pszProjection);
122 10 : CPLFree(pszGCPProjection);
123 :
124 10 : if( dims )
125 10 : CPLFree( dims );
126 :
127 10 : if( maxdims )
128 10 : CPLFree( maxdims );
129 :
130 10 : if( nGCPCount > 0 )
131 : {
132 0 : for( int i = 0; i < nGCPCount; i++ )
133 : {
134 0 : if( pasGCPList[i].pszId )
135 0 : CPLFree( pasGCPList[i].pszId );
136 0 : if( pasGCPList[i].pszInfo )
137 0 : CPLFree( pasGCPList[i].pszInfo );
138 : }
139 :
140 0 : CPLFree( pasGCPList );
141 : }
142 10 : }
143 :
144 : /************************************************************************/
145 : /* ==================================================================== */
146 : /* Hdf5imagerasterband */
147 : /* ==================================================================== */
148 : /************************************************************************/
149 : class HDF5ImageRasterBand : public GDALPamRasterBand
150 : {
151 : friend class HDF5ImageDataset;
152 :
153 : int bNoDataSet;
154 : double dfNoDataValue;
155 : char *pszFilename;
156 :
157 : public:
158 :
159 : HDF5ImageRasterBand( HDF5ImageDataset *, int, GDALDataType );
160 : ~HDF5ImageRasterBand();
161 :
162 : virtual CPLErr IReadBlock( int, int, void * );
163 : virtual double GetNoDataValue( int * );
164 : virtual CPLErr SetNoDataValue( double );
165 : /* virtual CPLErr IWriteBlock( int, int, void * ); */
166 : };
167 :
168 : /************************************************************************/
169 : /* ~HDF5ImageRasterBand() */
170 : /************************************************************************/
171 :
172 10 : HDF5ImageRasterBand::~HDF5ImageRasterBand()
173 : {
174 :
175 10 : }
176 : /************************************************************************/
177 : /* HDF5ImageRasterBand() */
178 : /************************************************************************/
179 10 : HDF5ImageRasterBand::HDF5ImageRasterBand( HDF5ImageDataset *poDS, int nBand,
180 10 : GDALDataType eType )
181 :
182 : {
183 : char **papszMetaGlobal;
184 10 : this->poDS = poDS;
185 10 : this->nBand = nBand;
186 10 : eDataType = eType;
187 10 : bNoDataSet = FALSE;
188 10 : dfNoDataValue = -9999;
189 10 : nBlockXSize = poDS->GetRasterXSize( );
190 10 : nBlockYSize = 1;
191 :
192 : /* -------------------------------------------------------------------- */
193 : /* Take a copy of Global Metadata since I can't pass Raster */
194 : /* variable to Iterate function. */
195 : /* -------------------------------------------------------------------- */
196 10 : papszMetaGlobal = CSLDuplicate( poDS->papszMetadata );
197 10 : CSLDestroy( poDS->papszMetadata );
198 10 : poDS->papszMetadata = NULL;
199 :
200 10 : if( poDS->poH5Objects->nType == H5G_DATASET ) {
201 10 : poDS->CreateMetadata( poDS->poH5Objects, H5G_DATASET );
202 : }
203 :
204 : /* -------------------------------------------------------------------- */
205 : /* Recover Global Metadat and set Band Metadata */
206 : /* -------------------------------------------------------------------- */
207 :
208 10 : SetMetadata( poDS->papszMetadata );
209 :
210 10 : CSLDestroy( poDS->papszMetadata );
211 10 : poDS->papszMetadata = CSLDuplicate( papszMetaGlobal );
212 10 : CSLDestroy( papszMetaGlobal );
213 :
214 : /* check for chunksize and set it as the blocksize (optimizes read) */
215 10 : hid_t listid = H5Dget_create_plist(((HDF5ImageDataset * )poDS)->dataset_id);
216 10 : if (listid>0)
217 : {
218 10 : if(H5Pget_layout(listid) == H5D_CHUNKED)
219 : {
220 : hsize_t panChunkDims[3];
221 0 : int nDimSize = H5Pget_chunk(listid, 3, panChunkDims);
222 0 : nBlockXSize = (int) panChunkDims[nDimSize-1];
223 0 : nBlockYSize = (int) panChunkDims[nDimSize-2];
224 : }
225 10 : H5Pclose(listid);
226 : }
227 :
228 10 : }
229 :
230 : /************************************************************************/
231 : /* GetNoDataValue() */
232 : /************************************************************************/
233 2 : double HDF5ImageRasterBand::GetNoDataValue( int * pbSuccess )
234 :
235 : {
236 2 : if( bNoDataSet )
237 : {
238 0 : if( pbSuccess )
239 0 : *pbSuccess = bNoDataSet;
240 :
241 0 : return dfNoDataValue;
242 : }
243 : else
244 2 : return GDALPamRasterBand::GetNoDataValue( pbSuccess );
245 : }
246 :
247 : /************************************************************************/
248 : /* SetNoDataValue() */
249 : /************************************************************************/
250 0 : CPLErr HDF5ImageRasterBand::SetNoDataValue( double dfNoData )
251 :
252 : {
253 0 : bNoDataSet = TRUE;
254 0 : dfNoDataValue = dfNoData;
255 :
256 0 : return CE_None;
257 : }
258 :
259 : /************************************************************************/
260 : /* IReadBlock() */
261 : /************************************************************************/
262 919 : CPLErr HDF5ImageRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
263 : void * pImage )
264 : {
265 : herr_t status;
266 : hsize_t count[3];
267 : H5OFFSET_TYPE offset[3];
268 : int nSizeOfData;
269 : hid_t memspace;
270 : hsize_t col_dims[3];
271 : hsize_t rank;
272 :
273 919 : HDF5ImageDataset *poGDS = ( HDF5ImageDataset * ) poDS;
274 :
275 919 : if( poGDS->eAccess == GA_Update ) {
276 : memset( pImage, 0,
277 : nBlockXSize * nBlockYSize *
278 0 : GDALGetDataTypeSize( eDataType )/8 );
279 0 : return CE_None;
280 : }
281 :
282 919 : rank=2;
283 :
284 919 : if( poGDS->ndims == 3 ){
285 0 : rank=3;
286 0 : offset[0] = nBand-1;
287 0 : count[0] = 1;
288 0 : col_dims[0] = 1;
289 : }
290 :
291 919 : offset[poGDS->ndims - 2] = nBlockYOff*nBlockYSize;
292 919 : offset[poGDS->ndims - 1] = nBlockXOff*nBlockXSize;
293 919 : count[poGDS->ndims - 2] = nBlockYSize;
294 919 : count[poGDS->ndims - 1] = nBlockXSize;
295 :
296 919 : nSizeOfData = H5Tget_size( poGDS->native );
297 919 : memset( pImage,0,nBlockXSize*nBlockYSize*nSizeOfData );
298 :
299 : /* blocksize may not be a multiple of imagesize */
300 1845 : count[poGDS->ndims - 2] = MIN( size_t(nBlockYSize),
301 : poDS->GetRasterYSize() -
302 1845 : offset[poGDS->ndims - 2]);
303 2757 : count[poGDS->ndims - 1] = MIN( size_t(nBlockXSize),
304 : poDS->GetRasterXSize()-
305 2757 : offset[poGDS->ndims - 1]);
306 :
307 : /* -------------------------------------------------------------------- */
308 : /* Select block from file space */
309 : /* -------------------------------------------------------------------- */
310 : status = H5Sselect_hyperslab( poGDS->dataspace_id,
311 : H5S_SELECT_SET,
312 : offset, NULL,
313 919 : count, NULL );
314 :
315 : /* -------------------------------------------------------------------- */
316 : /* Create memory space to receive the data */
317 : /* -------------------------------------------------------------------- */
318 919 : col_dims[poGDS->ndims-2]=nBlockYSize;
319 919 : col_dims[poGDS->ndims-1]=nBlockXSize;
320 919 : memspace = H5Screate_simple( (int) rank, col_dims, NULL );
321 919 : H5OFFSET_TYPE mem_offset[3] = {0, 0, 0};
322 : status = H5Sselect_hyperslab(memspace,
323 : H5S_SELECT_SET,
324 : mem_offset, NULL,
325 919 : count, NULL);
326 :
327 : status = H5Dread ( poGDS->dataset_id,
328 : poGDS->native,
329 : memspace,
330 : poGDS->dataspace_id,
331 : H5P_DEFAULT,
332 919 : pImage );
333 :
334 919 : H5Sclose( memspace );
335 :
336 919 : return CE_None;
337 : }
338 :
339 : /************************************************************************/
340 : /* Identify() */
341 : /************************************************************************/
342 :
343 9245 : int HDF5ImageDataset::Identify( GDALOpenInfo *poOpenInfo )
344 :
345 : {
346 9245 : if(!EQUALN( poOpenInfo->pszFilename, "HDF5:", 5 ) )
347 9245 : return FALSE;
348 : else
349 0 : return TRUE;
350 : }
351 :
352 : /************************************************************************/
353 : /* Open() */
354 : /************************************************************************/
355 1470 : GDALDataset *HDF5ImageDataset::Open( GDALOpenInfo * poOpenInfo )
356 : {
357 : int i;
358 : HDF5ImageDataset *poDS;
359 : char szFilename[2048];
360 :
361 1470 : if(!EQUALN( poOpenInfo->pszFilename, "HDF5:", 5 ) ||
362 : strlen(poOpenInfo->pszFilename) > sizeof(szFilename) - 3 )
363 1460 : return NULL;
364 :
365 : /* -------------------------------------------------------------------- */
366 : /* Confirm the requested access is supported. */
367 : /* -------------------------------------------------------------------- */
368 10 : if( poOpenInfo->eAccess == GA_Update )
369 : {
370 : CPLError( CE_Failure, CPLE_NotSupported,
371 : "The HDF5ImageDataset driver does not support update access to existing"
372 0 : " datasets.\n" );
373 0 : return NULL;
374 : }
375 :
376 10 : poDS = new HDF5ImageDataset();
377 :
378 : /* -------------------------------------------------------------------- */
379 : /* Create a corresponding GDALDataset. */
380 : /* -------------------------------------------------------------------- */
381 : /* printf("poOpenInfo->pszFilename %s\n",poOpenInfo->pszFilename); */
382 : char **papszName =
383 : CSLTokenizeString2( poOpenInfo->pszFilename,
384 10 : ":", CSLT_HONOURSTRINGS|CSLT_PRESERVEESCAPES );
385 :
386 10 : if( !((CSLCount(papszName) == 3) || (CSLCount(papszName) == 4)) )
387 : {
388 0 : CSLDestroy(papszName);
389 0 : delete poDS;
390 0 : return NULL;
391 : }
392 :
393 10 : poDS->SetDescription( poOpenInfo->pszFilename );
394 :
395 : /* -------------------------------------------------------------------- */
396 : /* Check for drive name in windows HDF5:"D:\... */
397 : /* -------------------------------------------------------------------- */
398 10 : strcpy(szFilename, papszName[1]);
399 :
400 10 : if( strlen(papszName[1]) == 1 && papszName[3] != NULL )
401 : {
402 0 : strcat(szFilename, ":");
403 0 : strcat(szFilename, papszName[2]);
404 :
405 0 : poDS->SetSubdatasetName( papszName[3] );
406 : }
407 : else
408 10 : poDS->SetSubdatasetName( papszName[2] );
409 :
410 10 : CSLDestroy(papszName);
411 10 : papszName = NULL;
412 :
413 10 : if( !H5Fis_hdf5(szFilename) ) {
414 0 : delete poDS;
415 0 : return NULL;
416 : }
417 :
418 10 : poDS->SetPhysicalFilename( szFilename );
419 :
420 : /* -------------------------------------------------------------------- */
421 : /* Try opening the dataset. */
422 : /* -------------------------------------------------------------------- */
423 : poDS->hHDF5 = H5Fopen(szFilename,
424 : H5F_ACC_RDONLY,
425 10 : H5P_DEFAULT );
426 :
427 10 : if( poDS->hHDF5 < 0 )
428 : {
429 0 : delete poDS;
430 0 : return NULL;
431 : }
432 :
433 10 : poDS->hGroupID = H5Gopen( poDS->hHDF5, "/" );
434 10 : if( poDS->hGroupID < 0 )
435 : {
436 0 : poDS->bIsHDFEOS=false;
437 0 : delete poDS;
438 0 : return NULL;
439 : }
440 :
441 : /* -------------------------------------------------------------------- */
442 : /* THIS IS AN HDF5 FILE */
443 : /* -------------------------------------------------------------------- */
444 10 : poDS->bIsHDFEOS=TRUE;
445 10 : poDS->ReadGlobalAttributes( FALSE );
446 :
447 : /* -------------------------------------------------------------------- */
448 : /* Create HDF5 Data Hierarchy in a link list */
449 : /* -------------------------------------------------------------------- */
450 : poDS->poH5Objects =
451 : poDS->HDF5FindDatasetObjectsbyPath( poDS->poH5RootGroup,
452 10 : (char *)poDS->GetSubdatasetName() );
453 :
454 10 : if( poDS->poH5Objects == NULL ) {
455 0 : delete poDS;
456 0 : return NULL;
457 : }
458 : /* -------------------------------------------------------------------- */
459 : /* Retrieve HDF5 data information */
460 : /* -------------------------------------------------------------------- */
461 10 : poDS->dataset_id = H5Dopen( poDS->hHDF5,poDS->poH5Objects->pszPath );
462 10 : poDS->dataspace_id = H5Dget_space( poDS->dataset_id );
463 10 : poDS->ndims = H5Sget_simple_extent_ndims( poDS->dataspace_id );
464 10 : poDS->dims = (hsize_t*)CPLCalloc( poDS->ndims, sizeof(hsize_t) );
465 10 : poDS->maxdims = (hsize_t*)CPLCalloc( poDS->ndims, sizeof(hsize_t) );
466 : poDS->dimensions = H5Sget_simple_extent_dims( poDS->dataspace_id,
467 : poDS->dims,
468 10 : poDS->maxdims );
469 10 : poDS->datatype = H5Dget_type( poDS->dataset_id );
470 10 : poDS->clas = H5Tget_class( poDS->datatype );
471 10 : poDS->size = H5Tget_size( poDS->datatype );
472 10 : poDS->address = H5Dget_offset( poDS->dataset_id );
473 10 : poDS->native = H5Tget_native_type( poDS->datatype, H5T_DIR_ASCEND );
474 :
475 10 : poDS->nRasterYSize=(int)poDS->dims[poDS->ndims-2]; // Y
476 10 : poDS->nRasterXSize=(int)poDS->dims[poDS->ndims-1]; // X alway last
477 :
478 10 : poDS->nBands=1;
479 :
480 10 : if( poDS->ndims == 3 ) poDS->nBands=(int) poDS->dims[0];
481 :
482 :
483 20 : for( i = 1; i <= poDS->nBands; i++ ) {
484 : HDF5ImageRasterBand *poBand =
485 : new HDF5ImageRasterBand( poDS, i,
486 10 : poDS->GetDataType( poDS->native ) );
487 :
488 10 : poDS->SetBand( i, poBand );
489 10 : if( poBand->bNoDataSet )
490 0 : poBand->SetNoDataValue( 255 );
491 : }
492 :
493 10 : poDS->CreateProjections( );
494 :
495 10 : poDS->SetMetadata( poDS->papszMetadata );
496 :
497 : /* -------------------------------------------------------------------- */
498 : /* Setup/check for pam .aux.xml. */
499 : /* -------------------------------------------------------------------- */
500 10 : poDS->TryLoadXML();
501 :
502 : /* -------------------------------------------------------------------- */
503 : /* Setup overviews. */
504 : /* -------------------------------------------------------------------- */
505 10 : poDS->oOvManager.Initialize( poDS, ":::VIRTUAL:::" );
506 :
507 10 : return( poDS );
508 : }
509 :
510 :
511 : /************************************************************************/
512 : /* GDALRegister_HDF5Image() */
513 : /************************************************************************/
514 558 : void GDALRegister_HDF5Image( )
515 :
516 : {
517 : GDALDriver *poDriver;
518 :
519 558 : if (! GDAL_CHECK_VERSION("HDF5Image driver"))
520 0 : return;
521 :
522 558 : if( GDALGetDriverByName( "HDF5Image" ) == NULL )
523 : {
524 537 : poDriver = new GDALDriver( );
525 :
526 537 : poDriver->SetDescription( "HDF5Image" );
527 : poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
528 537 : "HDF5 Dataset" );
529 : poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC,
530 537 : "frmt_hdf5.html" );
531 537 : poDriver->pfnOpen = HDF5ImageDataset::Open;
532 537 : poDriver->pfnIdentify = HDF5ImageDataset::Identify;
533 :
534 537 : GetGDALDriverManager( )->RegisterDriver( poDriver );
535 : }
536 : }
537 :
538 : /************************************************************************/
539 : /* CreateProjections() */
540 : /************************************************************************/
541 10 : CPLErr HDF5ImageDataset::CreateProjections()
542 : {
543 : #define NBGCPLAT 100
544 : #define NBGCPLON 30
545 :
546 10 : hid_t LatitudeDatasetID = -1;
547 10 : hid_t LongitudeDatasetID = -1;
548 : hid_t LatitudeDataspaceID;
549 : hid_t LongitudeDataspaceID;
550 : float* Latitude;
551 : float* Longitude;
552 : int i,j;
553 : int nDeltaLat;
554 : int nDeltaLon;
555 :
556 10 : nDeltaLat = nRasterYSize / NBGCPLAT;
557 10 : nDeltaLon = nRasterXSize / NBGCPLON;
558 :
559 10 : if( nDeltaLat == 0 || nDeltaLon == 0 )
560 8 : return CE_None;
561 :
562 : /* -------------------------------------------------------------------- */
563 : /* Create HDF5 Data Hierarchy in a link list */
564 : /* -------------------------------------------------------------------- */
565 2 : poH5Objects=HDF5FindDatasetObjects( poH5RootGroup, "Latitude" );
566 2 : if( !poH5Objects ) {
567 2 : return CE_None;
568 : }
569 : /* -------------------------------------------------------------------- */
570 : /* The Lattitude and Longitude arrays must have a rank of 2 to */
571 : /* retrieve GCPs. */
572 : /* -------------------------------------------------------------------- */
573 0 : if( poH5Objects->nRank != 2 ) {
574 0 : return CE_None;
575 : }
576 :
577 : /* -------------------------------------------------------------------- */
578 : /* Retrieve HDF5 data information */
579 : /* -------------------------------------------------------------------- */
580 0 : LatitudeDatasetID = H5Dopen( hHDF5,poH5Objects->pszPath );
581 0 : LatitudeDataspaceID = H5Dget_space( dataset_id );
582 :
583 0 : poH5Objects=HDF5FindDatasetObjects( poH5RootGroup, "Longitude" );
584 0 : LongitudeDatasetID = H5Dopen( hHDF5,poH5Objects->pszPath );
585 0 : LongitudeDataspaceID = H5Dget_space( dataset_id );
586 :
587 0 : if( ( LatitudeDatasetID > 0 ) && ( LongitudeDatasetID > 0) ) {
588 :
589 : Latitude = ( float * ) CPLCalloc( nRasterYSize*nRasterXSize,
590 0 : sizeof( float ) );
591 : Longitude = ( float * ) CPLCalloc( nRasterYSize*nRasterXSize,
592 0 : sizeof( float ) );
593 0 : memset( Latitude, 0, nRasterXSize*nRasterYSize*sizeof( float ) );
594 0 : memset( Longitude, 0, nRasterXSize*nRasterYSize*sizeof( float ) );
595 :
596 : H5Dread ( LatitudeDatasetID,
597 : H5T_NATIVE_FLOAT,
598 : H5S_ALL,
599 : H5S_ALL,
600 : H5P_DEFAULT,
601 0 : Latitude );
602 :
603 : H5Dread ( LongitudeDatasetID,
604 : H5T_NATIVE_FLOAT,
605 : H5S_ALL,
606 : H5S_ALL,
607 : H5P_DEFAULT,
608 0 : Longitude );
609 :
610 0 : oSRS.SetWellKnownGeogCS( "WGS84" );
611 0 : CPLFree(pszProjection);
612 0 : CPLFree(pszGCPProjection);
613 0 : oSRS.exportToWkt( &pszProjection );
614 0 : oSRS.exportToWkt( &pszGCPProjection );
615 :
616 : /* -------------------------------------------------------------------- */
617 : /* Fill the GCPs list. */
618 : /* -------------------------------------------------------------------- */
619 0 : nGCPCount = nRasterYSize/nDeltaLat * nRasterXSize/nDeltaLon;
620 :
621 : pasGCPList = ( GDAL_GCP * )
622 0 : CPLCalloc( nGCPCount, sizeof( GDAL_GCP ) );
623 :
624 0 : GDALInitGCPs( nGCPCount, pasGCPList );
625 0 : int k=0;
626 :
627 0 : int nYLimit = ((int)nRasterYSize/nDeltaLat) * nDeltaLat;
628 0 : int nXLimit = ((int)nRasterXSize/nDeltaLon) * nDeltaLon;
629 0 : for( j = 0; j < nYLimit; j+=nDeltaLat )
630 : {
631 0 : for( i = 0; i < nXLimit; i+=nDeltaLon )
632 : {
633 0 : int iGCP = j * nRasterXSize + i;
634 0 : pasGCPList[k].dfGCPX = ( double ) Longitude[iGCP]+180.0;
635 0 : pasGCPList[k].dfGCPY = ( double ) Latitude[iGCP];
636 :
637 0 : pasGCPList[k].dfGCPPixel = i + 0.5;
638 0 : pasGCPList[k++].dfGCPLine = j + 0.5;
639 :
640 : }
641 : }
642 :
643 0 : CPLFree( Latitude );
644 0 : CPLFree( Longitude );
645 : }
646 0 : return CE_None;
647 :
648 : }
649 : /************************************************************************/
650 : /* GetProjectionRef() */
651 : /************************************************************************/
652 :
653 0 : const char *HDF5ImageDataset::GetProjectionRef( )
654 :
655 : {
656 0 : if( pszProjection )
657 0 : return pszProjection;
658 : else
659 0 : return GDALPamDataset::GetProjectionRef();
660 : }
661 :
662 : /************************************************************************/
663 : /* GetGCPCount() */
664 : /************************************************************************/
665 :
666 0 : int HDF5ImageDataset::GetGCPCount( )
667 :
668 : {
669 0 : if( nGCPCount > 0 )
670 0 : return nGCPCount;
671 : else
672 0 : return GDALPamDataset::GetGCPCount();
673 : }
674 :
675 : /************************************************************************/
676 : /* GetGCPProjection() */
677 : /************************************************************************/
678 :
679 0 : const char *HDF5ImageDataset::GetGCPProjection( )
680 :
681 : {
682 0 : if( nGCPCount > 0 )
683 0 : return pszGCPProjection;
684 : else
685 0 : return GDALPamDataset::GetGCPProjection();
686 : }
687 :
688 : /************************************************************************/
689 : /* GetGCPs() */
690 : /************************************************************************/
691 :
692 0 : const GDAL_GCP *HDF5ImageDataset::GetGCPs( )
693 : {
694 0 : if( nGCPCount > 0 )
695 0 : return pasGCPList;
696 : else
697 0 : return GDALPamDataset::GetGCPs();
698 : }
|