LCOV - code coverage report
Current view: directory - apps - gdalinfo.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 354 266 75.1 %
Date: 2012-04-28 Functions: 3 2 66.7 %

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

Generated by: LCOV version 1.7