LTP GCOV extension - code coverage report
Current view: directory - apps - gdalinfo.c
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 307
Code covered: 73.9 % Executed lines: 227

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

Generated by: LTP GCOV extension version 1.5