1 : /******************************************************************************
2 : * $Id: gdalinfo.c 25582 2013-01-29 21:13:43Z rouault $
3 : *
4 : * Project: GDAL Utilities
5 : * Purpose: Commandline application to list info about a file.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : * ****************************************************************************
9 : * Copyright (c) 1998, 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 : #include "gdal.h"
31 : #include "gdal_alg.h"
32 : #include "ogr_srs_api.h"
33 : #include "cpl_string.h"
34 : #include "cpl_conv.h"
35 : #include "cpl_multiproc.h"
36 : #include "commonutils.h"
37 :
38 : CPL_CVSID("$Id: gdalinfo.c 25582 2013-01-29 21:13:43Z rouault $");
39 :
40 : static int
41 : GDALInfoReportCorner( GDALDatasetH hDataset,
42 : OGRCoordinateTransformationH hTransform,
43 : const char * corner_name,
44 : double x, double y );
45 :
46 : /************************************************************************/
47 : /* Usage() */
48 : /************************************************************************/
49 :
50 0 : void Usage(const char* pszErrorMsg)
51 :
52 : {
53 0 : printf( "Usage: gdalinfo [--help-general] [-mm] [-stats] [-hist] [-nogcp] [-nomd]\n"
54 : " [-norat] [-noct] [-nofl] [-checksum] [-proj4] [-mdd domain]*\n"
55 : " [-sd subdataset] datasetname\n" );
56 :
57 0 : if( pszErrorMsg != NULL )
58 0 : fprintf(stderr, "\nFAILURE: %s\n", pszErrorMsg);
59 :
60 0 : exit( 1 );
61 : }
62 :
63 : /************************************************************************/
64 : /* main() */
65 : /************************************************************************/
66 :
67 : #define CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(nExtraArg) \
68 : do { if (i + nExtraArg >= argc) \
69 : Usage(CPLSPrintf("%s option requires %d argument(s)", argv[i], nExtraArg)); } while(0)
70 :
71 36 : int main( int argc, char ** argv )
72 :
73 : {
74 36 : GDALDatasetH hDataset = NULL;
75 36 : GDALRasterBandH hBand = NULL;
76 : int i, iBand;
77 : double adfGeoTransform[6];
78 : GDALDriverH hDriver;
79 : char **papszMetadata;
80 36 : int bComputeMinMax = FALSE, bSample = FALSE;
81 36 : int bShowGCPs = TRUE, bShowMetadata = TRUE, bShowRAT=TRUE;
82 36 : int bStats = FALSE, bApproxStats = TRUE, iMDD;
83 36 : int bShowColorTable = TRUE, bComputeChecksum = FALSE;
84 36 : int bReportHistograms = FALSE;
85 36 : int bReportProj4 = FALSE;
86 36 : int nSubdataset = -1;
87 36 : const char *pszFilename = NULL;
88 36 : char **papszExtraMDDomains = NULL, **papszFileList;
89 36 : const char *pszProjection = NULL;
90 36 : OGRCoordinateTransformationH hTransform = NULL;
91 36 : int bShowFileList = TRUE;
92 :
93 : /* Check that we are running against at least GDAL 1.5 */
94 : /* Note to developers : if we use newer API, please change the requirement */
95 36 : if (atoi(GDALVersionInfo("VERSION_NUM")) < 1500)
96 : {
97 0 : fprintf(stderr, "At least, GDAL >= 1.5.0 is required for this version of %s, "
98 : "which was compiled against GDAL %s\n", argv[0], GDAL_RELEASE_NAME);
99 0 : exit(1);
100 : }
101 :
102 36 : EarlySetConfigOptions(argc, argv);
103 :
104 36 : GDALAllRegister();
105 :
106 36 : argc = GDALGeneralCmdLineProcessor( argc, &argv, 0 );
107 36 : if( argc < 1 )
108 13 : exit( -argc );
109 :
110 : /* -------------------------------------------------------------------- */
111 : /* Parse arguments. */
112 : /* -------------------------------------------------------------------- */
113 53 : for( i = 1; i < argc; i++ )
114 : {
115 31 : if( EQUAL(argv[i], "--utility_version") )
116 : {
117 1 : printf("%s was compiled against GDAL %s and is running against GDAL %s\n",
118 : argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME"));
119 1 : return 0;
120 : }
121 30 : else if( EQUAL(argv[i],"--help") )
122 0 : Usage(NULL);
123 30 : else if( EQUAL(argv[i], "-mm") )
124 1 : bComputeMinMax = TRUE;
125 29 : else if( EQUAL(argv[i], "-hist") )
126 1 : bReportHistograms = TRUE;
127 28 : else if( EQUAL(argv[i], "-proj4") )
128 0 : bReportProj4 = TRUE;
129 28 : else if( EQUAL(argv[i], "-stats") )
130 : {
131 1 : bStats = TRUE;
132 1 : bApproxStats = FALSE;
133 : }
134 27 : else if( EQUAL(argv[i], "-approx_stats") )
135 : {
136 0 : bStats = TRUE;
137 0 : bApproxStats = TRUE;
138 : }
139 27 : else if( EQUAL(argv[i], "-sample") )
140 0 : bSample = TRUE;
141 27 : else if( EQUAL(argv[i], "-checksum") )
142 1 : bComputeChecksum = TRUE;
143 26 : else if( EQUAL(argv[i], "-nogcp") )
144 1 : bShowGCPs = FALSE;
145 25 : else if( EQUAL(argv[i], "-nomd") )
146 1 : bShowMetadata = FALSE;
147 24 : else if( EQUAL(argv[i], "-norat") )
148 0 : bShowRAT = FALSE;
149 24 : else if( EQUAL(argv[i], "-noct") )
150 1 : bShowColorTable = FALSE;
151 23 : else if( EQUAL(argv[i], "-mdd") )
152 : {
153 1 : CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
154 2 : papszExtraMDDomains = CSLAddString( papszExtraMDDomains,
155 2 : argv[++i] );
156 : }
157 22 : else if( EQUAL(argv[i], "-nofl") )
158 0 : bShowFileList = FALSE;
159 22 : else if( EQUAL(argv[i], "-sd") )
160 : {
161 0 : CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
162 0 : nSubdataset = atoi(argv[++i]);
163 : }
164 22 : else if( argv[i][0] == '-' )
165 0 : Usage(CPLSPrintf("Unkown option name '%s'", argv[i]));
166 22 : else if( pszFilename == NULL )
167 22 : pszFilename = argv[i];
168 : else
169 0 : Usage("Too many command options.");
170 : }
171 :
172 22 : if( pszFilename == NULL )
173 0 : Usage("No datasource specified.");
174 :
175 : /* -------------------------------------------------------------------- */
176 : /* Open dataset. */
177 : /* -------------------------------------------------------------------- */
178 22 : hDataset = GDALOpen( pszFilename, GA_ReadOnly );
179 :
180 22 : if( hDataset == NULL )
181 : {
182 0 : fprintf( stderr,
183 : "gdalinfo failed - unable to open '%s'.\n",
184 : pszFilename );
185 :
186 : /* -------------------------------------------------------------------- */
187 : /* If argument is a VSIFILE, then print its contents */
188 : /* -------------------------------------------------------------------- */
189 0 : if ( strncmp( pszFilename, "/vsizip/", 8 ) == 0 ||
190 0 : strncmp( pszFilename, "/vsitar/", 8 ) == 0 )
191 : {
192 0 : papszFileList = VSIReadDirRecursive( pszFilename );
193 0 : if ( papszFileList )
194 : {
195 0 : int nCount = CSLCount( papszFileList );
196 0 : fprintf( stdout,
197 : "Unable to open source `%s' directly.\n"
198 : "The archive contains %d files:\n",
199 : pszFilename, nCount );
200 0 : for ( i = 0; i < nCount; i++ )
201 : {
202 0 : fprintf( stdout, " %s/%s\n", pszFilename, papszFileList[i] );
203 : }
204 0 : CSLDestroy( papszFileList );
205 0 : papszFileList = NULL;
206 : }
207 : }
208 :
209 0 : CSLDestroy( argv );
210 0 : CSLDestroy( papszExtraMDDomains );
211 :
212 0 : GDALDumpOpenDatasets( stderr );
213 :
214 0 : GDALDestroyDriverManager();
215 :
216 0 : CPLDumpSharedList( NULL );
217 :
218 0 : exit( 1 );
219 : }
220 :
221 : /* -------------------------------------------------------------------- */
222 : /* Read specified subdataset if requested. */
223 : /* -------------------------------------------------------------------- */
224 22 : if ( nSubdataset > 0 )
225 : {
226 0 : char **papszSubdatasets = GDALGetMetadata( hDataset, "SUBDATASETS" );
227 0 : int nSubdatasets = CSLCount( papszSubdatasets );
228 :
229 0 : if ( nSubdatasets > 0 && nSubdataset <= nSubdatasets )
230 : {
231 : char szKeyName[1024];
232 : char *pszSubdatasetName;
233 :
234 0 : snprintf( szKeyName, sizeof(szKeyName),
235 : "SUBDATASET_%d_NAME", nSubdataset );
236 0 : szKeyName[sizeof(szKeyName) - 1] = '\0';
237 0 : pszSubdatasetName =
238 0 : CPLStrdup( CSLFetchNameValue( papszSubdatasets, szKeyName ) );
239 0 : GDALClose( hDataset );
240 0 : hDataset = GDALOpen( pszSubdatasetName, GA_ReadOnly );
241 0 : CPLFree( pszSubdatasetName );
242 : }
243 : else
244 : {
245 0 : fprintf( stderr,
246 : "gdalinfo warning: subdataset %d of %d requested. "
247 : "Reading the main dataset.\n",
248 : nSubdataset, nSubdatasets );
249 :
250 : }
251 : }
252 :
253 : /* -------------------------------------------------------------------- */
254 : /* Report general info. */
255 : /* -------------------------------------------------------------------- */
256 22 : hDriver = GDALGetDatasetDriver( hDataset );
257 22 : printf( "Driver: %s/%s\n",
258 : GDALGetDriverShortName( hDriver ),
259 : GDALGetDriverLongName( hDriver ) );
260 :
261 22 : papszFileList = GDALGetFileList( hDataset );
262 22 : if( CSLCount(papszFileList) == 0 )
263 : {
264 0 : printf( "Files: none associated\n" );
265 : }
266 : else
267 : {
268 22 : printf( "Files: %s\n", papszFileList[0] );
269 22 : if( bShowFileList )
270 : {
271 30 : for( i = 1; papszFileList[i] != NULL; i++ )
272 8 : printf( " %s\n", papszFileList[i] );
273 : }
274 : }
275 22 : CSLDestroy( papszFileList );
276 :
277 22 : printf( "Size is %d, %d\n",
278 : GDALGetRasterXSize( hDataset ),
279 : GDALGetRasterYSize( hDataset ) );
280 :
281 : /* -------------------------------------------------------------------- */
282 : /* Report projection. */
283 : /* -------------------------------------------------------------------- */
284 22 : if( GDALGetProjectionRef( hDataset ) != NULL )
285 : {
286 : OGRSpatialReferenceH hSRS;
287 : char *pszProjection;
288 :
289 22 : pszProjection = (char *) GDALGetProjectionRef( hDataset );
290 :
291 22 : hSRS = OSRNewSpatialReference(NULL);
292 22 : if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None )
293 : {
294 18 : char *pszPrettyWkt = NULL;
295 :
296 18 : OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE );
297 18 : printf( "Coordinate System is:\n%s\n", pszPrettyWkt );
298 18 : CPLFree( pszPrettyWkt );
299 : }
300 : else
301 4 : printf( "Coordinate System is `%s'\n",
302 : GDALGetProjectionRef( hDataset ) );
303 :
304 22 : if ( bReportProj4 )
305 : {
306 0 : char *pszProj4 = NULL;
307 0 : OSRExportToProj4( hSRS, &pszProj4 );
308 0 : printf("PROJ.4 string is:\n\'%s\'\n",pszProj4);
309 0 : CPLFree( pszProj4 );
310 : }
311 :
312 22 : OSRDestroySpatialReference( hSRS );
313 : }
314 :
315 : /* -------------------------------------------------------------------- */
316 : /* Report Geotransform. */
317 : /* -------------------------------------------------------------------- */
318 22 : if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
319 : {
320 34 : if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 )
321 : {
322 16 : printf( "Origin = (%.15f,%.15f)\n",
323 : adfGeoTransform[0], adfGeoTransform[3] );
324 :
325 16 : printf( "Pixel Size = (%.15f,%.15f)\n",
326 : adfGeoTransform[1], adfGeoTransform[5] );
327 : }
328 : else
329 2 : printf( "GeoTransform =\n"
330 : " %.16g, %.16g, %.16g\n"
331 : " %.16g, %.16g, %.16g\n",
332 : adfGeoTransform[0],
333 : adfGeoTransform[1],
334 : adfGeoTransform[2],
335 : adfGeoTransform[3],
336 : adfGeoTransform[4],
337 : adfGeoTransform[5] );
338 : }
339 :
340 : /* -------------------------------------------------------------------- */
341 : /* Report GCPs. */
342 : /* -------------------------------------------------------------------- */
343 22 : if( bShowGCPs && GDALGetGCPCount( hDataset ) > 0 )
344 : {
345 1 : if (GDALGetGCPProjection(hDataset) != NULL)
346 : {
347 : OGRSpatialReferenceH hSRS;
348 : char *pszProjection;
349 :
350 1 : pszProjection = (char *) GDALGetGCPProjection( hDataset );
351 :
352 1 : hSRS = OSRNewSpatialReference(NULL);
353 1 : if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None )
354 : {
355 1 : char *pszPrettyWkt = NULL;
356 :
357 1 : OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE );
358 1 : printf( "GCP Projection = \n%s\n", pszPrettyWkt );
359 1 : CPLFree( pszPrettyWkt );
360 : }
361 : else
362 0 : printf( "GCP Projection = %s\n",
363 : GDALGetGCPProjection( hDataset ) );
364 :
365 1 : OSRDestroySpatialReference( hSRS );
366 : }
367 :
368 5 : for( i = 0; i < GDALGetGCPCount(hDataset); i++ )
369 : {
370 : const GDAL_GCP *psGCP;
371 :
372 4 : psGCP = GDALGetGCPs( hDataset ) + i;
373 :
374 4 : printf( "GCP[%3d]: Id=%s, Info=%s\n"
375 : " (%.15g,%.15g) -> (%.15g,%.15g,%.15g)\n",
376 : i, psGCP->pszId, psGCP->pszInfo,
377 : psGCP->dfGCPPixel, psGCP->dfGCPLine,
378 : psGCP->dfGCPX, psGCP->dfGCPY, psGCP->dfGCPZ );
379 : }
380 : }
381 :
382 : /* -------------------------------------------------------------------- */
383 : /* Report metadata. */
384 : /* -------------------------------------------------------------------- */
385 22 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, NULL ) : NULL;
386 22 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
387 : {
388 14 : printf( "Metadata:\n" );
389 176 : for( i = 0; papszMetadata[i] != NULL; i++ )
390 : {
391 162 : printf( " %s\n", papszMetadata[i] );
392 : }
393 : }
394 :
395 23 : for( iMDD = 0; bShowMetadata && iMDD < CSLCount(papszExtraMDDomains); iMDD++ )
396 : {
397 1 : papszMetadata = GDALGetMetadata( hDataset, papszExtraMDDomains[iMDD] );
398 1 : if( CSLCount(papszMetadata) > 0 )
399 : {
400 1 : printf( "Metadata (%s):\n", papszExtraMDDomains[iMDD]);
401 2 : for( i = 0; papszMetadata[i] != NULL; i++ )
402 : {
403 1 : if (EQUALN(papszExtraMDDomains[iMDD], "xml:", 4))
404 0 : printf( "%s\n", papszMetadata[i] );
405 : else
406 1 : printf( " %s\n", papszMetadata[i] );
407 : }
408 : }
409 : }
410 :
411 : /* -------------------------------------------------------------------- */
412 : /* Report "IMAGE_STRUCTURE" metadata. */
413 : /* -------------------------------------------------------------------- */
414 22 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "IMAGE_STRUCTURE" ) : NULL;
415 22 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
416 : {
417 14 : printf( "Image Structure Metadata:\n" );
418 28 : for( i = 0; papszMetadata[i] != NULL; i++ )
419 : {
420 14 : printf( " %s\n", papszMetadata[i] );
421 : }
422 : }
423 :
424 : /* -------------------------------------------------------------------- */
425 : /* Report subdatasets. */
426 : /* -------------------------------------------------------------------- */
427 22 : papszMetadata = GDALGetMetadata( hDataset, "SUBDATASETS" );
428 22 : if( CSLCount(papszMetadata) > 0 )
429 : {
430 0 : printf( "Subdatasets:\n" );
431 0 : for( i = 0; papszMetadata[i] != NULL; i++ )
432 : {
433 0 : printf( " %s\n", papszMetadata[i] );
434 : }
435 : }
436 :
437 : /* -------------------------------------------------------------------- */
438 : /* Report geolocation. */
439 : /* -------------------------------------------------------------------- */
440 22 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "GEOLOCATION" ) : NULL;
441 22 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
442 : {
443 0 : printf( "Geolocation:\n" );
444 0 : for( i = 0; papszMetadata[i] != NULL; i++ )
445 : {
446 0 : printf( " %s\n", papszMetadata[i] );
447 : }
448 : }
449 :
450 : /* -------------------------------------------------------------------- */
451 : /* Report RPCs */
452 : /* -------------------------------------------------------------------- */
453 22 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hDataset, "RPC" ) : NULL;
454 22 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
455 : {
456 0 : printf( "RPC Metadata:\n" );
457 0 : for( i = 0; papszMetadata[i] != NULL; i++ )
458 : {
459 0 : printf( " %s\n", papszMetadata[i] );
460 : }
461 : }
462 :
463 : /* -------------------------------------------------------------------- */
464 : /* Setup projected to lat/long transform if appropriate. */
465 : /* -------------------------------------------------------------------- */
466 22 : if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
467 18 : pszProjection = GDALGetProjectionRef(hDataset);
468 :
469 22 : if( pszProjection != NULL && strlen(pszProjection) > 0 )
470 : {
471 18 : OGRSpatialReferenceH hProj, hLatLong = NULL;
472 :
473 18 : hProj = OSRNewSpatialReference( pszProjection );
474 18 : if( hProj != NULL )
475 18 : hLatLong = OSRCloneGeogCS( hProj );
476 :
477 18 : if( hLatLong != NULL )
478 : {
479 16 : CPLPushErrorHandler( CPLQuietErrorHandler );
480 16 : hTransform = OCTNewCoordinateTransformation( hProj, hLatLong );
481 16 : CPLPopErrorHandler();
482 :
483 16 : OSRDestroySpatialReference( hLatLong );
484 : }
485 :
486 18 : if( hProj != NULL )
487 18 : OSRDestroySpatialReference( hProj );
488 : }
489 :
490 : /* -------------------------------------------------------------------- */
491 : /* Report corners. */
492 : /* -------------------------------------------------------------------- */
493 22 : printf( "Corner Coordinates:\n" );
494 22 : GDALInfoReportCorner( hDataset, hTransform, "Upper Left",
495 : 0.0, 0.0 );
496 22 : GDALInfoReportCorner( hDataset, hTransform, "Lower Left",
497 22 : 0.0, GDALGetRasterYSize(hDataset));
498 22 : GDALInfoReportCorner( hDataset, hTransform, "Upper Right",
499 22 : GDALGetRasterXSize(hDataset), 0.0 );
500 44 : GDALInfoReportCorner( hDataset, hTransform, "Lower Right",
501 22 : GDALGetRasterXSize(hDataset),
502 22 : GDALGetRasterYSize(hDataset) );
503 22 : GDALInfoReportCorner( hDataset, hTransform, "Center",
504 : GDALGetRasterXSize(hDataset)/2.0,
505 : GDALGetRasterYSize(hDataset)/2.0 );
506 :
507 22 : if( hTransform != NULL )
508 : {
509 16 : OCTDestroyCoordinateTransformation( hTransform );
510 16 : hTransform = NULL;
511 : }
512 :
513 : /* ==================================================================== */
514 : /* Loop over bands. */
515 : /* ==================================================================== */
516 50 : for( iBand = 0; iBand < GDALGetRasterCount( hDataset ); iBand++ )
517 : {
518 : double dfMin, dfMax, adfCMinMax[2], dfNoData;
519 : int bGotMin, bGotMax, bGotNodata, bSuccess;
520 : int nBlockXSize, nBlockYSize, nMaskFlags;
521 : double dfMean, dfStdDev;
522 : GDALColorTableH hTable;
523 : CPLErr eErr;
524 :
525 28 : hBand = GDALGetRasterBand( hDataset, iBand+1 );
526 :
527 28 : if( bSample )
528 : {
529 : float afSample[10000];
530 : int nCount;
531 :
532 0 : nCount = GDALGetRandomRasterSample( hBand, 10000, afSample );
533 0 : printf( "Got %d samples.\n", nCount );
534 : }
535 :
536 28 : GDALGetBlockSize( hBand, &nBlockXSize, &nBlockYSize );
537 28 : printf( "Band %d Block=%dx%d Type=%s, ColorInterp=%s\n", iBand+1,
538 : nBlockXSize, nBlockYSize,
539 : GDALGetDataTypeName(
540 : GDALGetRasterDataType(hBand)),
541 : GDALGetColorInterpretationName(
542 : GDALGetRasterColorInterpretation(hBand)) );
543 :
544 56 : if( GDALGetDescription( hBand ) != NULL
545 56 : && strlen(GDALGetDescription( hBand )) > 0 )
546 1 : printf( " Description = %s\n", GDALGetDescription(hBand) );
547 :
548 28 : dfMin = GDALGetRasterMinimum( hBand, &bGotMin );
549 28 : dfMax = GDALGetRasterMaximum( hBand, &bGotMax );
550 28 : if( bGotMin || bGotMax || bComputeMinMax )
551 : {
552 6 : printf( " " );
553 6 : if( bGotMin )
554 5 : printf( "Min=%.3f ", dfMin );
555 6 : if( bGotMax )
556 5 : printf( "Max=%.3f ", dfMax );
557 :
558 6 : if( bComputeMinMax )
559 : {
560 1 : CPLErrorReset();
561 1 : GDALComputeRasterMinMax( hBand, FALSE, adfCMinMax );
562 1 : if (CPLGetLastErrorType() == CE_None)
563 : {
564 1 : printf( " Computed Min/Max=%.3f,%.3f",
565 : adfCMinMax[0], adfCMinMax[1] );
566 : }
567 : }
568 :
569 6 : printf( "\n" );
570 : }
571 :
572 28 : eErr = GDALGetRasterStatistics( hBand, bApproxStats, bStats,
573 : &dfMin, &dfMax, &dfMean, &dfStdDev );
574 28 : if( eErr == CE_None )
575 : {
576 6 : printf( " Minimum=%.3f, Maximum=%.3f, Mean=%.3f, StdDev=%.3f\n",
577 : dfMin, dfMax, dfMean, dfStdDev );
578 : }
579 :
580 28 : if( bReportHistograms )
581 : {
582 1 : int nBucketCount, *panHistogram = NULL;
583 :
584 1 : eErr = GDALGetDefaultHistogram( hBand, &dfMin, &dfMax,
585 : &nBucketCount, &panHistogram,
586 : TRUE, GDALTermProgress, NULL );
587 1 : if( eErr == CE_None )
588 : {
589 : int iBucket;
590 :
591 1 : printf( " %d buckets from %g to %g:\n ",
592 : nBucketCount, dfMin, dfMax );
593 257 : for( iBucket = 0; iBucket < nBucketCount; iBucket++ )
594 256 : printf( "%d ", panHistogram[iBucket] );
595 1 : printf( "\n" );
596 1 : CPLFree( panHistogram );
597 : }
598 : }
599 :
600 28 : if ( bComputeChecksum)
601 : {
602 1 : printf( " Checksum=%d\n",
603 : GDALChecksumImage(hBand, 0, 0,
604 : GDALGetRasterXSize(hDataset),
605 : GDALGetRasterYSize(hDataset)));
606 : }
607 :
608 28 : dfNoData = GDALGetRasterNoDataValue( hBand, &bGotNodata );
609 28 : if( bGotNodata )
610 : {
611 0 : if (CPLIsNan(dfNoData))
612 0 : printf( " NoData Value=nan\n" );
613 : else
614 0 : printf( " NoData Value=%.18g\n", dfNoData );
615 : }
616 :
617 28 : if( GDALGetOverviewCount(hBand) > 0 )
618 : {
619 : int iOverview;
620 :
621 9 : printf( " Overviews: " );
622 27 : for( iOverview = 0;
623 18 : iOverview < GDALGetOverviewCount(hBand);
624 9 : iOverview++ )
625 : {
626 : GDALRasterBandH hOverview;
627 9 : const char *pszResampling = NULL;
628 :
629 9 : if( iOverview != 0 )
630 0 : printf( ", " );
631 :
632 9 : hOverview = GDALGetOverview( hBand, iOverview );
633 9 : if (hOverview != NULL)
634 : {
635 9 : printf( "%dx%d",
636 : GDALGetRasterBandXSize( hOverview ),
637 : GDALGetRasterBandYSize( hOverview ) );
638 :
639 9 : pszResampling =
640 9 : GDALGetMetadataItem( hOverview, "RESAMPLING", "" );
641 :
642 9 : if( pszResampling != NULL
643 0 : && EQUALN(pszResampling,"AVERAGE_BIT2",12) )
644 0 : printf( "*" );
645 : }
646 : else
647 0 : printf( "(null)" );
648 : }
649 9 : printf( "\n" );
650 :
651 9 : if ( bComputeChecksum)
652 : {
653 0 : printf( " Overviews checksum: " );
654 0 : for( iOverview = 0;
655 0 : iOverview < GDALGetOverviewCount(hBand);
656 0 : iOverview++ )
657 : {
658 : GDALRasterBandH hOverview;
659 :
660 0 : if( iOverview != 0 )
661 0 : printf( ", " );
662 :
663 0 : hOverview = GDALGetOverview( hBand, iOverview );
664 0 : if (hOverview)
665 0 : printf( "%d",
666 : GDALChecksumImage(hOverview, 0, 0,
667 : GDALGetRasterBandXSize(hOverview),
668 : GDALGetRasterBandYSize(hOverview)));
669 : else
670 0 : printf( "(null)" );
671 : }
672 0 : printf( "\n" );
673 : }
674 : }
675 :
676 28 : if( GDALHasArbitraryOverviews( hBand ) )
677 : {
678 8 : printf( " Overviews: arbitrary\n" );
679 : }
680 :
681 28 : nMaskFlags = GDALGetMaskFlags( hBand );
682 28 : if( (nMaskFlags & (GMF_NODATA|GMF_ALL_VALID)) == 0 )
683 : {
684 0 : GDALRasterBandH hMaskBand = GDALGetMaskBand(hBand) ;
685 :
686 0 : printf( " Mask Flags: " );
687 0 : if( nMaskFlags & GMF_PER_DATASET )
688 0 : printf( "PER_DATASET " );
689 0 : if( nMaskFlags & GMF_ALPHA )
690 0 : printf( "ALPHA " );
691 0 : if( nMaskFlags & GMF_NODATA )
692 0 : printf( "NODATA " );
693 0 : if( nMaskFlags & GMF_ALL_VALID )
694 0 : printf( "ALL_VALID " );
695 0 : printf( "\n" );
696 :
697 0 : if( hMaskBand != NULL &&
698 0 : GDALGetOverviewCount(hMaskBand) > 0 )
699 : {
700 : int iOverview;
701 :
702 0 : printf( " Overviews of mask band: " );
703 0 : for( iOverview = 0;
704 0 : iOverview < GDALGetOverviewCount(hMaskBand);
705 0 : iOverview++ )
706 : {
707 : GDALRasterBandH hOverview;
708 :
709 0 : if( iOverview != 0 )
710 0 : printf( ", " );
711 :
712 0 : hOverview = GDALGetOverview( hMaskBand, iOverview );
713 0 : printf( "%dx%d",
714 : GDALGetRasterBandXSize( hOverview ),
715 : GDALGetRasterBandYSize( hOverview ) );
716 : }
717 0 : printf( "\n" );
718 : }
719 : }
720 :
721 28 : if( strlen(GDALGetRasterUnitType(hBand)) > 0 )
722 : {
723 0 : printf( " Unit Type: %s\n", GDALGetRasterUnitType(hBand) );
724 : }
725 :
726 28 : if( GDALGetRasterCategoryNames(hBand) != NULL )
727 : {
728 0 : char **papszCategories = GDALGetRasterCategoryNames(hBand);
729 : int i;
730 :
731 0 : printf( " Categories:\n" );
732 0 : for( i = 0; papszCategories[i] != NULL; i++ )
733 0 : printf( " %3d: %s\n", i, papszCategories[i] );
734 : }
735 :
736 56 : if( GDALGetRasterScale( hBand, &bSuccess ) != 1.0
737 56 : || GDALGetRasterOffset( hBand, &bSuccess ) != 0.0 )
738 0 : printf( " Offset: %.15g, Scale:%.15g\n",
739 : GDALGetRasterOffset( hBand, &bSuccess ),
740 : GDALGetRasterScale( hBand, &bSuccess ) );
741 :
742 28 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, NULL ) : NULL;
743 28 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
744 : {
745 7 : printf( " Metadata:\n" );
746 39 : for( i = 0; papszMetadata[i] != NULL; i++ )
747 : {
748 32 : printf( " %s\n", papszMetadata[i] );
749 : }
750 : }
751 :
752 28 : papszMetadata = (bShowMetadata) ? GDALGetMetadata( hBand, "IMAGE_STRUCTURE" ) : NULL;
753 28 : if( bShowMetadata && CSLCount(papszMetadata) > 0 )
754 : {
755 9 : printf( " Image Structure Metadata:\n" );
756 18 : for( i = 0; papszMetadata[i] != NULL; i++ )
757 : {
758 9 : printf( " %s\n", papszMetadata[i] );
759 : }
760 : }
761 :
762 30 : if( GDALGetRasterColorInterpretation(hBand) == GCI_PaletteIndex
763 30 : && (hTable = GDALGetRasterColorTable( hBand )) != NULL )
764 : {
765 : int i;
766 :
767 2 : printf( " Color Table (%s with %d entries)\n",
768 : GDALGetPaletteInterpretationName(
769 : GDALGetPaletteInterpretation( hTable )),
770 : GDALGetColorEntryCount( hTable ) );
771 :
772 2 : if (bShowColorTable)
773 : {
774 17 : for( i = 0; i < GDALGetColorEntryCount( hTable ); i++ )
775 : {
776 : GDALColorEntry sEntry;
777 :
778 16 : GDALGetColorEntryAsRGB( hTable, i, &sEntry );
779 64 : printf( " %3d: %d,%d,%d,%d\n",
780 : i,
781 16 : sEntry.c1,
782 16 : sEntry.c2,
783 16 : sEntry.c3,
784 16 : sEntry.c4 );
785 : }
786 : }
787 : }
788 :
789 28 : if( bShowRAT && GDALGetDefaultRAT( hBand ) != NULL )
790 : {
791 1 : GDALRasterAttributeTableH hRAT = GDALGetDefaultRAT( hBand );
792 :
793 1 : GDALRATDumpReadable( hRAT, NULL );
794 : }
795 : }
796 :
797 22 : GDALClose( hDataset );
798 :
799 22 : CSLDestroy( papszExtraMDDomains );
800 22 : CSLDestroy( argv );
801 :
802 22 : GDALDumpOpenDatasets( stderr );
803 :
804 22 : GDALDestroyDriverManager();
805 :
806 22 : CPLDumpSharedList( NULL );
807 22 : CPLCleanupTLS();
808 :
809 22 : exit( 0 );
810 : }
811 :
812 : /************************************************************************/
813 : /* GDALInfoReportCorner() */
814 : /************************************************************************/
815 :
816 : static int
817 110 : GDALInfoReportCorner( GDALDatasetH hDataset,
818 : OGRCoordinateTransformationH hTransform,
819 : const char * corner_name,
820 : double x, double y )
821 :
822 : {
823 : double dfGeoX, dfGeoY;
824 : double adfGeoTransform[6];
825 :
826 110 : printf( "%-11s ", corner_name );
827 :
828 : /* -------------------------------------------------------------------- */
829 : /* Transform the point into georeferenced coordinates. */
830 : /* -------------------------------------------------------------------- */
831 110 : if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
832 : {
833 180 : dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x
834 90 : + adfGeoTransform[2] * y;
835 180 : dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x
836 90 : + adfGeoTransform[5] * y;
837 : }
838 :
839 : else
840 : {
841 20 : printf( "(%7.1f,%7.1f)\n", x, y );
842 20 : return FALSE;
843 : }
844 :
845 : /* -------------------------------------------------------------------- */
846 : /* Report the georeferenced coordinates. */
847 : /* -------------------------------------------------------------------- */
848 100 : if( ABS(dfGeoX) < 181 && ABS(dfGeoY) < 91 )
849 : {
850 10 : printf( "(%12.7f,%12.7f) ", dfGeoX, dfGeoY );
851 : }
852 : else
853 : {
854 80 : printf( "(%12.3f,%12.3f) ", dfGeoX, dfGeoY );
855 : }
856 :
857 : /* -------------------------------------------------------------------- */
858 : /* Transform to latlong and report. */
859 : /* -------------------------------------------------------------------- */
860 170 : if( hTransform != NULL
861 80 : && OCTTransform(hTransform,1,&dfGeoX,&dfGeoY,NULL) )
862 : {
863 :
864 80 : printf( "(%s,", GDALDecToDMS( dfGeoX, "Long", 2 ) );
865 80 : printf( "%s)", GDALDecToDMS( dfGeoY, "Lat", 2 ) );
866 : }
867 :
868 90 : printf( "\n" );
869 :
870 90 : return TRUE;
871 : }
|