#include "gdal_utils_priv.h"
#include <cmath>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <new>
#include <string>
#include <vector>
#include "commonutils.h"
#include "cpl_json_header.h"
#include "cpl_progress.h"
#include "gdal_rat.h"
#include "ogrgeojsonreader.h"
#include "ogrgeojsonwriter.h"
using std::vector;
CPL_CVSID("$Id: gdalinfo_lib.cpp ee6581953a7041956a6655c1656830f35a6739e5 2018-08-08 23:38:59 +0200 Even Rouault $")
typedef enum { GDALINFO_FORMAT_TEXT = 0, GDALINFO_FORMAT_JSON = 1
} GDALInfoFormat;
{
GDALInfoFormat eFormat;
int bComputeMinMax;
int bReportHistograms;
int bReportProj4;
int bStats;
int bApproxStats;
int bSample;
int bComputeChecksum;
int bShowGCPs;
int bShowMetadata;
int bShowRAT;
int bShowColorTable;
int bListMDD;
int bShowFileList;
char **papszExtraMDDomains;
bool bStdoutOutput;
};
static int
const char * corner_name,
double x,
double y,
bool bJson,
json_object *poCornerCoordinates,
json_object *poLongLatExtentCoordinates,
static void
bool bIsBand,
bool bJson,
json_object *poMetadata,
static void Concat(
CPLString& osRet,
bool bStdoutOutput,
static
void Concat(
CPLString& osRet,
bool bStdoutOutput,
const char* pszFormat, ... )
{
va_list args;
va_start( args, pszFormat );
if( bStdoutOutput )
{
vfprintf(stdout, pszFormat, args );
}
else
{
try
{
osTarget.
vPrintf( pszFormat, args );
osRet += osTarget;
}
catch( const std::bad_alloc& )
{
}
}
va_end( args );
}
{
if( hDataset == nullptr )
return nullptr;
if( psOptions == nullptr )
{
psOptions = psOptionsToFree;
}
json_object *poJsonObject = nullptr;
json_object *poBands = nullptr;
json_object *poMetadata = nullptr;
const bool bJson = psOptions->eFormat == GDALINFO_FORMAT_JSON;
if( bJson )
{
json_object *poDescription =
json_object *poDriverShortName =
json_object *poDriverLongName =
poJsonObject = json_object_new_object();
poBands = json_object_new_array();
poMetadata = json_object_new_object();
json_object_object_add(poJsonObject, "description", poDescription);
json_object_object_add(poJsonObject, "driverShortName",
poDriverShortName);
json_object_object_add(poJsonObject, "driverLongName",
poDriverLongName);
}
else
{
Concat( osStr, psOptions->bStdoutOutput, "Driver: %s/%s\n",
}
if( papszFileList == nullptr || *papszFileList == nullptr )
{
if( bJson )
{
json_object *poFiles = json_object_new_array();
json_object_object_add(poJsonObject, "files", poFiles);
}
else
{
Concat( osStr, psOptions->bStdoutOutput,
"Files: none associated\n" );
}
}
else
{
if( bJson )
{
if( psOptions->bShowFileList )
{
json_object *poFiles = json_object_new_array();
for( int i = 0; papszFileList[i] != nullptr; i++ )
{
json_object *poFile =
json_object_new_string(papszFileList[i]);
json_object_array_add(poFiles, poFile);
}
json_object_object_add(poJsonObject, "files", poFiles);
}
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"Files: %s\n", papszFileList[0] );
if( psOptions->bShowFileList )
{
for( int i = 1; papszFileList[i] != nullptr; i++ )
Concat(osStr, psOptions->bStdoutOutput,
" %s\n", papszFileList[i] );
}
}
}
if( bJson )
{
json_object *poSize = json_object_new_array();
json_object *poSizeX =
json_object *poSizeY =
json_object_array_add(poSize, poSizeX);
json_object_array_add(poSize, poSizeY);
json_object_object_add(poJsonObject, "size", poSize);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"Size is %d, %d\n",
}
{
json_object *poCoordinateSystem = nullptr;
if( bJson )
poCoordinateSystem = json_object_new_object();
char *pszProjection =
{
char *pszPrettyWkt = nullptr;
if( bJson )
{
json_object *poWkt = json_object_new_string(pszPrettyWkt);
json_object_object_add(poCoordinateSystem, "wkt", poWkt);
}
else
{
Concat( osStr, psOptions->bStdoutOutput,
"Coordinate System is:\n%s\n",
pszPrettyWkt );
}
}
else
{
if( bJson )
{
json_object *poWkt =
json_object_object_add(poCoordinateSystem, "wkt", poWkt);
}
else
{
Concat( osStr, psOptions->bStdoutOutput,
"Coordinate System is `%s'\n",
}
}
if ( psOptions->bReportProj4 )
{
char *pszProj4 = nullptr;
if( bJson )
{
json_object *proj4 = json_object_new_string(pszProj4);
json_object_object_add(poCoordinateSystem, "proj4", proj4);
}
else
Concat(osStr, psOptions->bStdoutOutput,
"PROJ.4 string is:\n\'%s\'\n",pszProj4);
}
if( bJson )
json_object_object_add(poJsonObject, "coordinateSystem",
poCoordinateSystem);
}
double adfGeoTransform[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
{
if( bJson )
{
json_object *poGeoTransform = json_object_new_array();
for( int i = 0; i < 6; i++ )
{
json_object *poGeoTransformCoefficient =
json_object_new_double_with_precision(adfGeoTransform[i],
16);
json_object_array_add(poGeoTransform,
poGeoTransformCoefficient);
}
json_object_object_add(poJsonObject, "geoTransform",
poGeoTransform);
}
else
{
if( adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0 )
{
Concat( osStr, psOptions->bStdoutOutput,
"Origin = (%.15f,%.15f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
Concat( osStr, psOptions->bStdoutOutput,
"Pixel Size = (%.15f,%.15f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
else
{
Concat( osStr, psOptions->bStdoutOutput, "GeoTransform =\n"
" %.16g, %.16g, %.16g\n"
" %.16g, %.16g, %.16g\n",
adfGeoTransform[0],
adfGeoTransform[1],
adfGeoTransform[2],
adfGeoTransform[3],
adfGeoTransform[4],
adfGeoTransform[5] );
}
}
}
{
json_object * const poGCPs = bJson ? json_object_new_object() : nullptr;
{
json_object *poGCPCoordinateSystem = nullptr;
char *pszProjection =
{
char *pszPrettyWkt = nullptr;
if( bJson )
{
json_object *poWkt = json_object_new_string(pszPrettyWkt);
poGCPCoordinateSystem = json_object_new_object();
json_object_object_add(poGCPCoordinateSystem, "wkt", poWkt);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"GCP Projection = \n%s\n", pszPrettyWkt );
}
}
else
{
if(bJson)
{
json_object *poWkt =
poGCPCoordinateSystem = json_object_new_object();
json_object_object_add(poGCPCoordinateSystem, "wkt", poWkt);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"GCP Projection = %s\n",
}
}
if(bJson)
json_object_object_add(poGCPs, "coordinateSystem",
poGCPCoordinateSystem);
}
json_object * const poGCPList = bJson ? json_object_new_array() : nullptr;
{
if( bJson )
{
json_object *poGCP = json_object_new_object();
json_object *poId = json_object_new_string(psGCP->
pszId);
json_object *poInfo = json_object_new_string(psGCP->
pszInfo);
json_object *poPixel =
json_object_new_double_with_precision(psGCP->
dfGCPPixel,
15);
json_object *poLine =
json_object_new_double_with_precision(psGCP->
dfGCPLine, 15);
json_object *poX =
json_object_new_double_with_precision(psGCP->
dfGCPX, 15);
json_object *poY =
json_object_new_double_with_precision(psGCP->
dfGCPY, 15);
json_object *poZ =
json_object_new_double_with_precision(psGCP->
dfGCPZ, 15);
json_object_object_add(poGCP, "id", poId);
json_object_object_add(poGCP, "info", poInfo);
json_object_object_add(poGCP, "pixel", poPixel);
json_object_object_add(poGCP, "line", poLine);
json_object_object_add(poGCP, "x", poX);
json_object_object_add(poGCP, "y", poY);
json_object_object_add(poGCP, "z", poZ);
json_object_array_add(poGCPList, poGCP);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"GCP[%3d]: Id=%s, Info=%s\n"
" (%.15g,%.15g) -> (%.15g,%.15g,%.15g)\n",
}
}
if( bJson )
{
json_object_object_add(poGCPs, "gcpList", poGCPList);
json_object_object_add(poJsonObject, "gcps", poGCPs);
}
}
GDALInfoReportMetadata( psOptions, hDataset, false,
bJson, poMetadata, osStr );
if( bJson )
{
if( psOptions->bShowMetadata )
json_object_object_add( poJsonObject, "metadata", poMetadata );
else
json_object_put(poMetadata);
}
const char *pszProjection = nullptr;
bool bTransformToWGS84 = false;
if( pszProjection != nullptr && strlen(pszProjection) > 0 )
{
if( hProj != nullptr )
{
if(bJson &&
{
bTransformToWGS84 = true;
}
else
{
if( hLatLong )
{
if( poGEOGCS )
{
const int iUnitChild =
if( iUnitChild != -1 )
}
}
}
}
if( hLatLong != nullptr )
{
}
if( hProj != nullptr )
}
{
json_object *poLinearRing = json_object_new_array();
json_object *poCornerCoordinates = json_object_new_object();
json_object *poLongLatExtent = json_object_new_object();
json_object *poLongLatExtentType = json_object_new_string("Polygon");
json_object *poLongLatExtentCoordinates = json_object_new_array();
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"upperLeft",
0.0, 0.0, bJson, poCornerCoordinates,
poLongLatExtentCoordinates, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"lowerLeft",
poCornerCoordinates, poLongLatExtentCoordinates,
osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"lowerRight",
bJson, poCornerCoordinates,
poLongLatExtentCoordinates, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"upperRight",
poCornerCoordinates, poLongLatExtentCoordinates,
osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"center",
bJson, poCornerCoordinates,
poLongLatExtentCoordinates, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"upperLeft",
0.0, 0.0, bJson, poCornerCoordinates,
poLongLatExtentCoordinates, osStr );
json_object_object_add( poJsonObject, "cornerCoordinates",
poCornerCoordinates );
json_object_object_add( poLongLatExtent, "type", poLongLatExtentType );
json_object_array_add( poLinearRing, poLongLatExtentCoordinates );
json_object_object_add( poLongLatExtent, "coordinates", poLinearRing );
json_object_object_add( poJsonObject,
bTransformToWGS84 ? "wgs84Extent": "extent", poLongLatExtent );
}
{
Concat(osStr, psOptions->bStdoutOutput, "Corner Coordinates:\n" );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"Upper Left",
0.0, 0.0, bJson, nullptr, nullptr, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"Lower Left",
nullptr, nullptr, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"Upper Right",
nullptr, nullptr, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"Lower Right",
nullptr, nullptr, osStr );
GDALInfoReportCorner( psOptions, hDataset, hTransform,
"Center",
nullptr, nullptr, osStr );
}
if( hTransform != nullptr )
{
hTransform = nullptr;
}
{
json_object *poBand = nullptr;
json_object *poBandMetadata = nullptr;
if( bJson )
{
poBand = json_object_new_object();
poBandMetadata = json_object_new_object();
}
if( psOptions->bSample )
{
vector<float> ofSample(10000, 0);
float * const pafSample = &ofSample[0];
const int nCount =
if( !bJson )
Concat( osStr, psOptions->bStdoutOutput,
"Got %d samples.\n", nCount );
}
int nBlockXSize = 0;
int nBlockYSize = 0;
if( bJson )
{
json_object *poBandNumber = json_object_new_int(iBand+1);
json_object *poBlock = json_object_new_array();
json_object *poType =
json_object_new_string(
json_object *poColorInterp =
json_object_new_string(
json_object_array_add(poBlock, json_object_new_int(nBlockXSize));
json_object_array_add(poBlock, json_object_new_int(nBlockYSize));
json_object_object_add(poBand, "band", poBandNumber);
json_object_object_add(poBand, "block", poBlock);
json_object_object_add(poBand, "type", poType);
json_object_object_add(poBand, "colorInterpretation",
poColorInterp);
}
else
{
Concat( osStr, psOptions->bStdoutOutput,
"Band %d Block=%dx%d Type=%s, ColorInterp=%s\n",
iBand + 1,
nBlockXSize, nBlockYSize,
}
{
if(bJson)
{
json_object *poBandDescription =
json_object_object_add(poBand, "description",
poBandDescription);
}
else
{
Concat( osStr, psOptions->bStdoutOutput, " Description = %s\n",
}
}
{
int bGotMin = FALSE;
int bGotMax = FALSE;
if( bGotMin || bGotMax || psOptions->bComputeMinMax )
{
if( !bJson )
Concat(osStr, psOptions->bStdoutOutput, " " );
if( bGotMin )
{
if( bJson )
{
json_object *poMin =
json_object_new_double_with_precision(dfMin, 3);
json_object_object_add(poBand, "min", poMin);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"Min=%.3f ", dfMin );
}
}
if( bGotMax )
{
if( bJson )
{
json_object *poMax =
json_object_new_double_with_precision(dfMax, 3);
json_object_object_add(poBand, "max", poMax);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"Max=%.3f ", dfMax );
}
}
if( psOptions->bComputeMinMax )
{
double adfCMinMax[2] = {0.0, 0.0};
{
if( bJson )
{
json_object *poComputedMin =
json_object_new_double_with_precision(
adfCMinMax[0], 3);
json_object *poComputedMax =
json_object_new_double_with_precision(
adfCMinMax[1], 3);
json_object_object_add(poBand, "computedMin",
poComputedMin);
json_object_object_add(poBand, "computedMax",
poComputedMax);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" Computed Min/Max=%.3f,%.3f",
adfCMinMax[0], adfCMinMax[1] );
}
}
}
if(!bJson)
Concat(osStr, psOptions->bStdoutOutput, "\n" );
}
}
double dfMinStat = 0.0;
double dfMaxStat = 0.0;
double dfMean = 0.0;
double dfStdDev = 0.0;
psOptions->bStats,
&dfMinStat, &dfMaxStat,
&dfMean, &dfStdDev );
if( eErr == CE_None )
{
if( bJson )
{
json_object *poMinimum =
json_object_new_double_with_precision(dfMinStat, 3);
json_object *poMaximum =
json_object_new_double_with_precision(dfMaxStat, 3);
json_object *poMean =
json_object_new_double_with_precision(dfMean, 3);
json_object *poStdDev =
json_object_new_double_with_precision(dfStdDev, 3);
json_object_object_add(poBand, "minimum", poMinimum);
json_object_object_add(poBand, "maximum", poMaximum);
json_object_object_add(poBand, "mean", poMean);
json_object_object_add(poBand, "stdDev", poStdDev);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" Minimum=%.3f, Maximum=%.3f, Mean=%.3f, StdDev=%.3f\n",
dfMinStat, dfMaxStat, dfMean, dfStdDev );
}
}
if( psOptions->bReportHistograms )
{
int nBucketCount = 0;
if( bJson )
&nBucketCount, &panHistogram,
TRUE, GDALDummyProgress,
nullptr );
else
&nBucketCount, &panHistogram,
TRUE, GDALTermProgress,
nullptr );
if( eErr == CE_None )
{
json_object *poHistogram = nullptr;
json_object *poBuckets = nullptr;
if( bJson )
{
json_object *poCount = json_object_new_int(nBucketCount);
json_object *poMin = json_object_new_double(dfMinStat);
json_object *poMax = json_object_new_double(dfMaxStat);
poBuckets = json_object_new_array();
poHistogram = json_object_new_object();
json_object_object_add(poHistogram, "count", poCount);
json_object_object_add(poHistogram, "min", poMin);
json_object_object_add(poHistogram, "max", poMax);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" %d buckets from %g to %g:\n ",
nBucketCount, dfMinStat, dfMaxStat );
}
for( int iBucket = 0; iBucket < nBucketCount; iBucket++ )
{
if(bJson)
{
json_object *poBucket =
json_object_new_int64(panHistogram[iBucket]);
json_object_array_add(poBuckets, poBucket);
}
else
Concat(osStr, psOptions->bStdoutOutput,
}
if( bJson )
{
json_object_object_add(poHistogram, "buckets", poBuckets);
json_object_object_add(poBand, "histogram", poHistogram);
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "\n" );
}
}
}
if ( psOptions->bComputeChecksum)
{
const int nBandChecksum =
if( bJson )
{
json_object *poChecksum = json_object_new_int(nBandChecksum);
json_object_object_add(poBand, "checksum", poChecksum);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" Checksum=%d\n", nBandChecksum );
}
}
int bGotNodata = FALSE;
if( bGotNodata )
{
if( CPLIsNan(dfNoData) )
{
if( bJson )
{
json_object *poNoDataValue = json_object_new_string("nan");
json_object_object_add(poBand, "noDataValue",
poNoDataValue);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" NoData Value=nan\n" );
}
}
else
{
if(bJson)
{
json_object *poNoDataValue =
json_object_new_double_with_precision(dfNoData, 18);
json_object_object_add(poBand, "noDataValue",
poNoDataValue);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" NoData Value=%.18g\n", dfNoData );
}
}
}
{
json_object *poOverviews = nullptr;
if( bJson )
poOverviews = json_object_new_array();
else
Concat(osStr, psOptions->bStdoutOutput, " Overviews: " );
for( int iOverview = 0;
iOverview++ )
{
if( !bJson )
if( iOverview != 0 )
Concat(osStr, psOptions->bStdoutOutput, ", " );
if (hOverview != nullptr)
{
if(bJson)
{
json_object *poOverviewSize = json_object_new_array();
json_object *poOverviewSizeX =
json_object_new_int(
json_object *poOverviewSizeY =
json_object_new_int(
json_object *poOverview = json_object_new_object();
json_object_array_add( poOverviewSize,
poOverviewSizeX );
json_object_array_add( poOverviewSize,
poOverviewSizeY );
json_object_object_add( poOverview, "size",
poOverviewSize );
if(psOptions->bComputeChecksum)
{
const int nOverviewChecksum =
hOverview, 0, 0,
json_object *poOverviewChecksum =
json_object_new_int(nOverviewChecksum);
json_object_object_add(poOverview, "checksum",
poOverviewChecksum);
}
json_object_array_add(poOverviews, poOverview);
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "%dx%d",
}
const char *pszResampling =
if( pszResampling != nullptr && !bJson
Concat(osStr, psOptions->bStdoutOutput, "*" );
}
else
{
if(!bJson)
Concat(osStr, psOptions->bStdoutOutput, "(null)" );
}
}
if(bJson)
json_object_object_add(poBand, "overviews", poOverviews);
else
Concat(osStr, psOptions->bStdoutOutput, "\n" );
if ( psOptions->bComputeChecksum && !bJson )
{
Concat(osStr, psOptions->bStdoutOutput,
" Overviews checksum: " );
for( int iOverview = 0;
iOverview++ )
{
if( iOverview != 0 )
Concat(osStr, psOptions->bStdoutOutput, ", " );
if (hOverview)
{
Concat(osStr, psOptions->bStdoutOutput, "%d",
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "(null)" );
}
}
Concat(osStr, psOptions->bStdoutOutput, "\n" );
}
}
{
Concat(osStr, psOptions->bStdoutOutput,
" Overviews: arbitrary\n" );
}
{
json_object *poMask = nullptr;
json_object *poFlags = nullptr;
json_object *poMaskOverviews = nullptr;
if(bJson)
{
poMask = json_object_new_object();
poFlags = json_object_new_array();
}
else
Concat(osStr, psOptions->bStdoutOutput, " Mask Flags: " );
{
if(bJson)
{
json_object *poFlag =
json_object_new_string( "PER_DATASET" );
json_object_array_add( poFlags, poFlag );
}
else
Concat(osStr, psOptions->bStdoutOutput, "PER_DATASET " );
}
{
if(bJson)
{
json_object *poFlag = json_object_new_string( "ALPHA" );
json_object_array_add( poFlags, poFlag );
}
else
Concat(osStr, psOptions->bStdoutOutput, "ALPHA " );
}
{
if(bJson)
{
json_object *poFlag = json_object_new_string( "NODATA" );
json_object_array_add( poFlags, poFlag );
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "NODATA " );
}
}
if(bJson)
json_object_object_add( poMask, "flags", poFlags );
else
Concat(osStr, psOptions->bStdoutOutput, "\n" );
if(bJson)
poMaskOverviews = json_object_new_array();
if( hMaskBand != nullptr &&
{
if(!bJson)
Concat(osStr, psOptions->bStdoutOutput,
" Overviews of mask band: " );
for( int iOverview = 0;
iOverview++ )
{
if( !hOverview )
break;
json_object *poMaskOverview = nullptr;
json_object *poMaskOverviewSize = nullptr;
if(bJson)
{
poMaskOverview = json_object_new_object();
poMaskOverviewSize = json_object_new_array();
}
else
{
if( iOverview != 0 )
Concat(osStr, psOptions->bStdoutOutput, ", " );
}
if(bJson)
{
json_object *poMaskOverviewSizeX =
json_object_new_int(
json_object *poMaskOverviewSizeY =
json_object_new_int(
json_object_array_add(poMaskOverviewSize,
poMaskOverviewSizeX);
json_object_array_add(poMaskOverviewSize,
poMaskOverviewSizeY);
json_object_object_add(poMaskOverview, "size",
poMaskOverviewSize);
json_object_array_add(poMaskOverviews, poMaskOverview);
}
else
{
Concat( osStr, psOptions->bStdoutOutput, "%dx%d",
}
}
if( !bJson )
Concat(osStr, psOptions->bStdoutOutput, "\n" );
}
if(bJson)
{
json_object_object_add(poMask, "overviews", poMaskOverviews);
json_object_object_add(poBand, "mask", poMask);
}
}
{
if( bJson )
{
json_object *poUnit =
json_object_object_add(poBand, "unit", poUnit);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
}
}
{
json_object *poCategories = nullptr;
if( bJson )
poCategories = json_object_new_array();
else
Concat(osStr, psOptions->bStdoutOutput, " Categories:\n" );
for( int i = 0; papszCategories[i] != nullptr; i++ )
{
if(bJson)
{
json_object *poCategoryName =
json_object_new_string(papszCategories[i]);
json_object_array_add(poCategories, poCategoryName);
}
else
Concat(osStr, psOptions->bStdoutOutput,
" %3d: %s\n", i, papszCategories[i] );
}
if(bJson)
json_object_object_add(poBand, "categories", poCategories);
}
int bSuccess = FALSE;
{
if( bJson )
{
json_object *poOffset = json_object_new_double_with_precision(
json_object *poScale = json_object_new_double_with_precision(
json_object_object_add(poBand, "offset", poOffset);
json_object_object_add(poBand, "scale", poScale);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" Offset: %.15g, Scale:%.15g\n",
}
}
GDALInfoReportMetadata( psOptions, hBand, true, bJson,
poBandMetadata, osStr );
if( bJson )
{
if (psOptions->bShowMetadata)
json_object_object_add( poBand, "metadata", poBandMetadata );
else
json_object_put(poBandMetadata);
}
{
if( !bJson )
Concat( osStr, psOptions->bStdoutOutput,
" Color Table (%s with %d entries)\n",
if (psOptions->bShowColorTable)
{
json_object *poEntries = nullptr;
if( bJson )
{
json_object *poPalette =
json_object *poCount =
json_object *poColorTable = json_object_new_object();
json_object_object_add(poColorTable, "palette", poPalette);
json_object_object_add(poColorTable, "count", poCount);
poEntries = json_object_new_array();
json_object_object_add(poColorTable, "entries", poEntries);
json_object_object_add(poBand, "colorTable", poColorTable);
}
{
if(bJson)
{
json_object *poEntry = json_object_new_array();
json_object *poC1 = json_object_new_int(sEntry.
c1);
json_object *poC2 = json_object_new_int(sEntry.
c2);
json_object *poC3 = json_object_new_int(sEntry.
c3);
json_object *poC4 = json_object_new_int(sEntry.
c4);
json_object_array_add(poEntry, poC1);
json_object_array_add(poEntry, poC2);
json_object_array_add(poEntry, poC3);
json_object_array_add(poEntry, poC4);
json_object_array_add(poEntries, poEntry);
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
" %3d: %d,%d,%d,%d\n",
i,
}
}
}
}
{
if( bJson )
{
json_object *poRAT =
json_object_object_add( poJsonObject, "rat", poRAT );
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "%s\n", pszXMLText );
}
}
if(bJson)
json_object_array_add(poBands, poBand);
}
if(bJson)
{
json_object_object_add(poJsonObject, "bands", poBands);
Concat(osStr, psOptions->bStdoutOutput, "%s",
json_object_to_json_string_ext(poJsonObject,
JSON_C_TO_STRING_PRETTY));
json_object_put(poJsonObject);
}
if( psOptionsToFree != nullptr )
}
static int
const char * corner_name,
double x,
double y,
bool bJson,
json_object *poCornerCoordinates,
json_object *poLongLatExtentCoordinates,
{
if(!bJson)
Concat(osStr, psOptions->bStdoutOutput, "%-11s ", corner_name );
double adfGeoTransform[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
double dfGeoX = 0.0;
double dfGeoY = 0.0;
{
dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x
+ adfGeoTransform[2] * y;
dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x
+ adfGeoTransform[5] * y;
}
else
{
if( bJson )
{
json_object * const poCorner = json_object_new_array();
json_object * const poX =
json_object_new_double_with_precision( x, 1 );
json_object * const poY =
json_object_new_double_with_precision( y, 1 );
json_object_array_add( poCorner, poX );
json_object_array_add( poCorner, poY );
json_object_object_add( poCornerCoordinates, corner_name,
poCorner );
}
else
{
Concat(osStr, psOptions->bStdoutOutput, "(%7.1f,%7.1f)\n", x, y );
}
return FALSE;
}
if( std::abs(dfGeoX) < 181 && std::abs(dfGeoY) < 91 )
{
if(bJson)
{
json_object * const poCorner = json_object_new_array();
json_object * const poX =
json_object_new_double_with_precision( dfGeoX, 7 );
json_object * const poY =
json_object_new_double_with_precision( dfGeoY, 7 );
json_object_array_add( poCorner, poX );
json_object_array_add( poCorner, poY );
json_object_object_add( poCornerCoordinates, corner_name,
poCorner );
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"(%12.7f,%12.7f) ", dfGeoX, dfGeoY );
}
}
else
{
if(bJson)
{
json_object * const poCorner = json_object_new_array();
json_object * const poX =
json_object_new_double_with_precision( dfGeoX, 3 );
json_object * const poY =
json_object_new_double_with_precision( dfGeoY, 3 );
json_object_array_add( poCorner, poX );
json_object_array_add( poCorner, poY );
json_object_object_add( poCornerCoordinates, corner_name,
poCorner );
}
else
{
Concat(osStr, psOptions->bStdoutOutput,
"(%12.3f,%12.3f) ", dfGeoX, dfGeoY );
}
}
if(bJson)
{
double dfZ = 0.0;
if( hTransform !=
nullptr && !
EQUAL( corner_name,
"center" )
{
json_object * const poCorner = json_object_new_array();
json_object * const poX =
json_object_new_double_with_precision( dfGeoX, 7 );
json_object * const poY =
json_object_new_double_with_precision( dfGeoY, 7 );
json_object_array_add( poCorner, poX );
json_object_array_add( poCorner, poY );
json_object_array_add( poLongLatExtentCoordinates , poCorner );
}
}
else
{
double dfZ = 0.0;
if( hTransform != nullptr
{
Concat(osStr, psOptions->bStdoutOutput,
Concat(osStr, psOptions->bStdoutOutput,
}
Concat(osStr, psOptions->bStdoutOutput, "\n" );
}
return TRUE;
}
const char *pszDomain,
const char *pszDisplayedname,
const char *pszIndent,
int bJsonOutput,
json_object *poMetadata,
{
const bool bIsxml =
pszDomain != nullptr &&
const bool bMDIsJson =
pszDomain != nullptr &&
if( papszMetadata != nullptr && *papszMetadata != nullptr )
{
json_object *poDomain =
(bJsonOutput && !bIsxml && !bMDIsJson) ?
json_object_new_object() : nullptr;
if( !bJsonOutput )
Concat( osStr, psOptions->bStdoutOutput, "%s%s:\n", pszIndent,
pszDisplayedname );
json_object *poValue = nullptr;
for( int i = 0; papszMetadata[i] != nullptr; i++ )
{
if( bJsonOutput )
{
if( bIsxml )
{
poValue = json_object_new_string( papszMetadata[i] );
break;
}
else if( bMDIsJson )
{
OGRJSonParse(papszMetadata[i], &poValue, true);
break;
}
else
{
char *pszKey = nullptr;
const char *pszValue =
if( pszKey )
{
poValue = json_object_new_string( pszValue );
json_object_object_add( poDomain, pszKey, poValue );
}
}
}
else
{
if (bIsxml || bMDIsJson)
Concat(osStr, psOptions->bStdoutOutput,
"%s%s\n", pszIndent, papszMetadata[i] );
else
Concat(osStr, psOptions->bStdoutOutput,
"%s %s\n", pszIndent, papszMetadata[i] );
}
}
if(bJsonOutput)
{
if(bIsxml || bMDIsJson)
{
json_object_object_add( poMetadata, pszDomain, poValue );
}
else
{
if(pszDomain == nullptr)
json_object_object_add( poMetadata, "", poDomain );
else
json_object_object_add( poMetadata, pszDomain, poDomain );
}
}
}
}
bool bIsBand,
bool bJson,
json_object *poMetadata,
{
const char* const pszIndent = bIsBand ? " " : "";
if( psOptions->bListMDD )
{
char** papszIter = papszMDDList;
json_object *poMDD = nullptr;
json_object * const poListMDD = bJson ? json_object_new_array() : nullptr;
if( papszMDDList != nullptr )
{
if( !bJson )
Concat(osStr, psOptions->bStdoutOutput,
"%sMetadata domains:\n", pszIndent );
}
while( papszIter != nullptr && *papszIter != nullptr )
{
if(
EQUAL(*papszIter,
"") )
{
if( bJson )
poMDD = json_object_new_string( *papszIter );
else
Concat(osStr, psOptions->bStdoutOutput,
"%s (default)\n", pszIndent);
}
else
{
if( bJson )
poMDD = json_object_new_string( *papszIter );
else
Concat(osStr, psOptions->bStdoutOutput,
"%s %s\n", pszIndent, *papszIter );
}
if( bJson )
json_object_array_add( poListMDD, poMDD );
papszIter ++;
}
if( bJson )
json_object_object_add( poMetadata, "metadataDomains", poListMDD );
}
if (!psOptions->bShowMetadata)
return;
GDALInfoPrintMetadata( psOptions, hObject, nullptr, "Metadata",
pszIndent, bJson, poMetadata, osStr );
if( psOptions->papszExtraMDDomains != nullptr )
{
char **papszExtraMDDomainsExpanded = nullptr;
if(
EQUAL(psOptions->papszExtraMDDomains[0],
"all") &&
psOptions->papszExtraMDDomains[1] == nullptr )
{
char * const * papszIter = papszMDDList;
while( papszIter != nullptr && *papszIter != nullptr )
{
if( !
EQUAL(*papszIter,
"") &&
!
EQUAL(*papszIter,
"IMAGE_STRUCTURE") &&
!
EQUAL(*papszIter,
"SUBDATASETS") &&
!
EQUAL(*papszIter,
"GEOLOCATION") &&
!
EQUAL(*papszIter,
"RPC") )
{
papszExtraMDDomainsExpanded =
}
papszIter ++;
}
}
else
{
papszExtraMDDomainsExpanded =
}
for( int iMDD = 0; papszExtraMDDomainsExpanded != nullptr &&
papszExtraMDDomainsExpanded[iMDD] != nullptr; iMDD++ )
{
if(bJson)
{
GDALInfoPrintMetadata(
psOptions, hObject, papszExtraMDDomainsExpanded[iMDD],
papszExtraMDDomainsExpanded[iMDD], pszIndent, bJson,
poMetadata, osStr );
}
else
{
"Metadata (" +
CPLString(papszExtraMDDomainsExpanded[iMDD]) +
")";
GDALInfoPrintMetadata(
psOptions, hObject, papszExtraMDDomainsExpanded[iMDD],
osDisplayedname.c_str(), pszIndent, bJson, poMetadata,
osStr );
}
}
}
GDALInfoPrintMetadata( psOptions, hObject, "IMAGE_STRUCTURE",
"Image Structure Metadata", pszIndent, bJson,
poMetadata, osStr );
if (!bIsBand)
{
GDALInfoPrintMetadata( psOptions, hObject, "SUBDATASETS", "Subdatasets",
pszIndent, bJson, poMetadata, osStr );
GDALInfoPrintMetadata( psOptions, hObject, "GEOLOCATION", "Geolocation",
pszIndent, bJson, poMetadata, osStr );
GDALInfoPrintMetadata( psOptions, hObject, "RPC", "RPC Metadata",
pszIndent, bJson, poMetadata, osStr );
}
}
char** papszArgv,
{
bool bGotFilename = false;
psOptions->eFormat = GDALINFO_FORMAT_TEXT;
psOptions->bComputeMinMax = FALSE;
psOptions->bReportHistograms = FALSE;
psOptions->bReportProj4 = FALSE;
psOptions->bStats = FALSE;
psOptions->bApproxStats = TRUE;
psOptions->bSample = FALSE;
psOptions->bComputeChecksum = FALSE;
psOptions->bShowGCPs = TRUE;
psOptions->bShowMetadata = TRUE;
psOptions->bShowRAT = TRUE;
psOptions->bShowColorTable = TRUE;
psOptions->bListMDD = FALSE;
psOptions->bShowFileList = TRUE;
for( int i = 0; papszArgv != nullptr && papszArgv[i] != nullptr; i++ )
{
if(
EQUAL(papszArgv[i],
"-json") )
psOptions->eFormat = GDALINFO_FORMAT_JSON;
else if(
EQUAL(papszArgv[i],
"-mm") )
psOptions->bComputeMinMax = TRUE;
else if(
EQUAL(papszArgv[i],
"-hist") )
psOptions->bReportHistograms = TRUE;
else if(
EQUAL(papszArgv[i],
"-proj4") )
psOptions->bReportProj4 = TRUE;
else if(
EQUAL(papszArgv[i],
"-stats") )
{
psOptions->bStats = TRUE;
psOptions->bApproxStats = FALSE;
}
else if(
EQUAL(papszArgv[i],
"-approx_stats") )
{
psOptions->bStats = TRUE;
psOptions->bApproxStats = TRUE;
}
else if(
EQUAL(papszArgv[i],
"-sample") )
psOptions->bSample = TRUE;
else if(
EQUAL(papszArgv[i],
"-checksum") )
psOptions->bComputeChecksum = TRUE;
else if(
EQUAL(papszArgv[i],
"-nogcp") )
psOptions->bShowGCPs = FALSE;
else if(
EQUAL(papszArgv[i],
"-nomd") )
psOptions->bShowMetadata = FALSE;
else if(
EQUAL(papszArgv[i],
"-norat") )
psOptions->bShowRAT = FALSE;
else if(
EQUAL(papszArgv[i],
"-noct") )
psOptions->bShowColorTable = FALSE;
else if(
EQUAL(papszArgv[i],
"-listmdd") )
psOptions->bListMDD = TRUE;
else if(
EQUAL(papszArgv[i],
"-stdout") )
psOptions->bStdoutOutput = true;
else if(
EQUAL(papszArgv[i],
"-mdd") && papszArgv[i+1] != nullptr )
{
psOptions->papszExtraMDDomains, papszArgv[++i] );
}
else if(
EQUAL(papszArgv[i],
"-oo") && papszArgv[i+1] !=
nullptr )
{
i++;
if( psOptionsForBinary )
{
psOptionsForBinary->papszOpenOptions, papszArgv[i] );
}
}
else if(
EQUAL(papszArgv[i],
"-nofl") )
psOptions->bShowFileList = FALSE;
else if(
EQUAL(papszArgv[i],
"-sd") && papszArgv[i+1] !=
nullptr )
{
i++;
if( psOptionsForBinary )
{
psOptionsForBinary->nSubdataset = atoi(papszArgv[i]);
}
}
else if( papszArgv[i][0] == '-' )
{
"Unknown option name '%s'", papszArgv[i]);
return nullptr;
}
else if( !bGotFilename )
{
bGotFilename = true;
if( psOptionsForBinary )
psOptionsForBinary->pszFilename =
CPLStrdup(papszArgv[i]);
}
else
{
"Too many command options '%s'", papszArgv[i]);
return nullptr;
}
}
return psOptions;
}
{
if( psOptions != nullptr )
{
}
}