LCOV - code coverage report
Current view: directory - apps - gdalinfo.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 366 262 71.6 %
Date: 2012-12-26 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.7