LCOV - code coverage report
Current view: directory - apps - gdalinfo.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 314 203 64.6 %
Date: 2010-01-09 Functions: 3 2 66.7 %

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

Generated by: LCOV version 1.7