/************************************************************************/
public static void main(String[] args) {
{
Dataset hDataset;
Band hBand;
int i, iBand;
double[] adfGeoTransform = new double[6];
Driver hDriver;
Vector papszMetadata;
boolean bComputeMinMax = false, bSample = false;
boolean bShowGCPs = true, bShowMetadata = true;
boolean bStats = false, bApproxStats = true;
boolean bShowColorTable = true, bComputeChecksum = false;
boolean bReportHistograms = false;
boolean bShowRAT = true;
String pszFilename = null;
Vector papszFileList;
Vector papszExtraMDDomains = new Vector();
gdal.AllRegister();
args = gdal.GeneralCmdLineProcessor(args);
if (args.length < 1) {
Usage();
System.exit(0);
}
/* -------------------------------------------------------------------- */
/* Parse arguments. */
/* -------------------------------------------------------------------- */
for (i = 0; i < args.length; i++) {
if (args[i].equals("-mm"))
bComputeMinMax = true;
else if (args[i].equals("-hist"))
bReportHistograms = true;
else if (args[i].equals("-stats"))
{
bStats = true;
bApproxStats = false;
}
else if (args[i].equals("-approx_stats"))
{
bStats = true;
bApproxStats = true;
}
else if (args[i].equals("-nogcp"))
bShowGCPs = false;
else if( args[i].equals("-noct"))
bShowColorTable = false;
else if (args[i].equals("-nomd"))
bShowMetadata = false;
else if (args[i].equals("-norat"))
bShowRAT = false;
else if (args[i].equals("-checksum"))
bComputeChecksum = true;
else if (args[i].equals("-mdd") && i + 1 < args.length)
papszExtraMDDomains.addElement(args[++i]);
else if (args[i].startsWith("-"))
Usage();
else if (pszFilename == null)
pszFilename = args[i];
else
Usage();
}
if (pszFilename == null)
Usage();
/* -------------------------------------------------------------------- */
/* Open dataset. */
/* -------------------------------------------------------------------- */
hDataset = gdal.Open(pszFilename, gdalconstConstants.GA_ReadOnly);
if (hDataset == null) {
System.err
.println("GDALOpen failed - " + gdal.GetLastErrorNo());
System.err.println(gdal.GetLastErrorMsg());
//gdal.DumpOpenDatasets( stderr );
//gdal.DestroyDriverManager();
//gdal.DumpSharedList( null );
System.exit(1);
}
/* -------------------------------------------------------------------- */
/* Report general info. */
/* -------------------------------------------------------------------- */
hDriver = hDataset.GetDriver();
System.out.println("Driver: " + hDriver.getShortName() + "/"
+ hDriver.getLongName());
papszFileList = hDataset.GetFileList( );
if( papszFileList.size() == 0 )
{
System.out.println( "Files: none associated" );
}
else
{
Enumeration e = papszFileList.elements();
System.out.println( "Files: " + (String)e.nextElement() );
while(e.hasMoreElements())
System.out.println( " " + (String)e.nextElement() );
}
System.out.println("Size is " + hDataset.getRasterXSize() + ", "
+ hDataset.getRasterYSize());
/* -------------------------------------------------------------------- */
/* Report projection. */
/* -------------------------------------------------------------------- */
if (hDataset.GetProjectionRef() != null) {
SpatialReference hSRS;
String pszProjection;
pszProjection = hDataset.GetProjectionRef();
hSRS = new SpatialReference(pszProjection);
if (hSRS != null && pszProjection.length() != 0) {
String[] pszPrettyWkt = new String[1];
hSRS.ExportToPrettyWkt(pszPrettyWkt, 0);
System.out.println("Coordinate System is:");
System.out.println(pszPrettyWkt[0]);
//gdal.CPLFree( pszPrettyWkt );
} else
System.out.println("Coordinate System is `"
+ hDataset.GetProjectionRef() + "'");
hSRS.delete();
}
/* -------------------------------------------------------------------- */
/* Report Geotransform. */
/* -------------------------------------------------------------------- */
hDataset.GetGeoTransform(adfGeoTransform);
{
if (adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0) {
System.out.println("Origin = (" + adfGeoTransform[0] + ","
+ adfGeoTransform[3] + ")");
System.out.println("Pixel Size = (" + adfGeoTransform[1]
+ "," + adfGeoTransform[5] + ")");
} else {
System.out.println("GeoTransform =");
System.out.println(" " + adfGeoTransform[0] + ", "
+ adfGeoTransform[1] + ", " + adfGeoTransform[2]);
System.out.println(" " + adfGeoTransform[3] + ", "
+ adfGeoTransform[4] + ", " + adfGeoTransform[5]);
}
}
/* -------------------------------------------------------------------- */
/* Report GCPs. */
/* -------------------------------------------------------------------- */
if (bShowGCPs && hDataset.GetGCPCount() > 0) {
System.out.println("GCP Projection = "
+ hDataset.GetGCPProjection());
int count = 0;
Vector GCPs = new Vector();
hDataset.GetGCPs(GCPs);
Enumeration e = GCPs.elements();
while (e.hasMoreElements()) {
GCP gcp = (GCP) e.nextElement();
System.out.println("GCP[" + (count++) + "]: Id="
+ gcp.getId() + ", Info=" + gcp.getInfo());
System.out.println(" (" + gcp.getGCPPixel() + ","
+ gcp.getGCPLine() + ") (" + gcp.getGCPX() + ","
+ gcp.getGCPY() + "," + gcp.getGCPZ() + ")");
}
}
/* -------------------------------------------------------------------- */
/* Report metadata. */
/* -------------------------------------------------------------------- */
papszMetadata = hDataset.GetMetadata_List("");
if (bShowMetadata && papszMetadata.size() > 0) {
Enumeration keys = papszMetadata.elements();
System.out.println("Metadata:");
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
Enumeration eExtraMDDDomains = papszExtraMDDomains.elements();
while(eExtraMDDDomains.hasMoreElements())
{
String pszDomain = (String)eExtraMDDDomains.nextElement();
papszMetadata = hDataset.GetMetadata_List(pszDomain);
if( bShowMetadata && papszMetadata.size() > 0 )
{
Enumeration keys = papszMetadata.elements();
System.out.println("Metadata (" + pszDomain + "):");
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
}
/* -------------------------------------------------------------------- */
/* Report "IMAGE_STRUCTURE" metadata. */
/* -------------------------------------------------------------------- */
papszMetadata = hDataset.GetMetadata_List("IMAGE_STRUCTURE" );
if( bShowMetadata && papszMetadata.size() > 0) {
Enumeration keys = papszMetadata.elements();
System.out.println("Image Structure Metadata:");
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
/* -------------------------------------------------------------------- */
/* Report subdatasets. */
/* -------------------------------------------------------------------- */
papszMetadata = hDataset.GetMetadata_List("SUBDATASETS");
if (papszMetadata.size() > 0) {
System.out.println("Subdatasets:");
Enumeration keys = papszMetadata.elements();
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
/* -------------------------------------------------------------------- */
/* Report geolocation. */
/* -------------------------------------------------------------------- */
papszMetadata = hDataset.GetMetadata_List("GEOLOCATION" );
if (papszMetadata.size() > 0) {
System.out.println( "Geolocation:" );
Enumeration keys = papszMetadata.elements();
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
/* -------------------------------------------------------------------- */
/* Report RPCs */
/* -------------------------------------------------------------------- */
papszMetadata = hDataset.GetMetadata_List("RPC" );
if (papszMetadata.size() > 0) {
System.out.println( "RPC Metadata:" );
Enumeration keys = papszMetadata.elements();
while (keys.hasMoreElements()) {
System.out.println(" " + (String) keys.nextElement());
}
}
/* -------------------------------------------------------------------- */
/* Report corners. */
/* -------------------------------------------------------------------- */
System.out.println("Corner Coordinates:");
GDALInfoReportCorner(hDataset, "Upper Left ", 0.0, 0.0);
GDALInfoReportCorner(hDataset, "Lower Left ", 0.0, hDataset
.getRasterYSize());
GDALInfoReportCorner(hDataset, "Upper Right", hDataset
.getRasterXSize(), 0.0);
GDALInfoReportCorner(hDataset, "Lower Right", hDataset
.getRasterXSize(), hDataset.getRasterYSize());
GDALInfoReportCorner(hDataset, "Center ",
hDataset.getRasterXSize() / 2.0,
hDataset.getRasterYSize() / 2.0);
/* ==================================================================== */
/* Loop over bands. */
/* ==================================================================== */
for (iBand = 0; iBand < hDataset.getRasterCount(); iBand++) {
Double[] pass1 = new Double[1], pass2 = new Double[1];
double[] adfCMinMax = new double[2];
ColorTable hTable;
hBand = hDataset.GetRasterBand(iBand + 1);
/*if( bSample )
{
float[] afSample = new float[10000];
int nCount;
nCount = hBand.GetRandomRasterSample( 10000, afSample );
System.out.println( "Got " + nCount + " samples." );
}*/
int[] blockXSize = new int[1];
int[] blockYSize = new int[1];
hBand.GetBlockSize(blockXSize, blockYSize);
System.out.println("Band "
+ (iBand+1)
+ " Block="
+ blockXSize[0] + "x" + blockYSize[0]
+ " Type="
+ gdal.GetDataTypeName(hBand.getDataType())
+ ", ColorInterp="
+ gdal.GetColorInterpretationName(hBand
.GetRasterColorInterpretation()));
String hBandDesc = hBand.GetDescription();
if (hBandDesc != null && hBandDesc.length() > 0)
System.out.println(" Description = " + hBandDesc);
hBand.GetMinimum(pass1);
hBand.GetMaximum(pass2);
if(pass1[0] != null || pass2[0] != null || bComputeMinMax) {
System.out.print( " " );
if( pass1[0] != null )
System.out.print( "Min=" + pass1[0] + " ");
if( pass2[0] != null )
System.out.print( "Max=" + pass2[0] + " ");
if( bComputeMinMax )
{
hBand.ComputeRasterMinMax(adfCMinMax, 0);
System.out.print( " Computed Min/Max=" + adfCMinMax[0]
+ "," + adfCMinMax[1]);
}
System.out.print( "\n" );
}
double dfMin[] = new double[1];
double dfMax[] = new double[1];
double dfMean[] = new double[1];
double dfStdDev[] = new double[1];
if( hBand.GetStatistics( bApproxStats, bStats,
dfMin, dfMax, dfMean, dfStdDev ) == gdalconstConstants.CE_None )
{
System.out.println( " Minimum=" + dfMin[0] + ", Maximum=" + dfMax[0] +
", Mean=" + dfMean[0] + ", StdDev=" + dfStdDev[0] );
}
if( bReportHistograms )
{
int[][] panHistogram = new int[1][];
int eErr = hBand.GetDefaultHistogram(dfMin, dfMax, panHistogram, true, new TermProgressCallback());
if( eErr == gdalconstConstants.CE_None )
{
int iBucket;
int nBucketCount = panHistogram[0].length;
System.out.print( " " + nBucketCount + " buckets from " +
dfMin[0] + " to " + dfMax[0] + ":\n " );
for( iBucket = 0; iBucket < nBucketCount; iBucket++ )
System.out.print( panHistogram[0][iBucket] + " ");
System.out.print( "\n" );
}
}
if ( bComputeChecksum)
{
System.out.println( " Checksum=" + hBand.Checksum());
}
hBand.GetNoDataValue(pass1);
if(pass1[0] != null)
{
System.out.println(" NoData Value=" + pass1[0]);
}
if (hBand.GetOverviewCount() > 0) {
int iOverview;
System.out.print(" Overviews: ");
for (iOverview = 0; iOverview < hBand.GetOverviewCount(); iOverview++) {
Band hOverview;
if (iOverview != 0)
System.out.print(", ");
hOverview = hBand.GetOverview(iOverview);
System.out.print(hOverview.getXSize() + "x"
+ hOverview.getYSize());
}
System.out.print("\n");
if ( bComputeChecksum)
{
System.out.print( " Overviews checksum: " );
for( iOverview = 0;
iOverview < hBand.GetOverviewCount();
iOverview++ )
{
Band hOverview;
if( iOverview != 0 )
System.out.print( ", " );
hOverview = hBand.GetOverview(iOverview);
System.out.print( hOverview.Checksum());
}
System.out.print( "\n" );
}
}
if( hBand.HasArbitraryOverviews() )
{
System.out.println( " Overviews: arbitrary" );
}
int nMaskFlags = hBand.GetMaskFlags( );
if( (nMaskFlags & (gdalconstConstants.GMF_NODATA|gdalconstConstants.GMF_ALL_VALID)) == 0 )
{
Band hMaskBand = hBand.GetMaskBand() ;
System.out.print( " Mask Flags: " );
if( (nMaskFlags & gdalconstConstants.GMF_PER_DATASET) != 0 )
System.out.print( "PER_DATASET " );
if( (nMaskFlags & gdalconstConstants.GMF_ALPHA) != 0 )
System.out.print( "ALPHA " );
if( (nMaskFlags & gdalconstConstants.GMF_NODATA) != 0 )
System.out.print( "NODATA " );
if( (nMaskFlags & gdalconstConstants.GMF_ALL_VALID) != 0 )
System.out.print( "ALL_VALID " );
System.out.print( "\n" );
if( hMaskBand != null &&
hMaskBand.GetOverviewCount() > 0 )
{
int iOverview;
System.out.print( " Overviews of mask band: " );
for( iOverview = 0;
iOverview < hMaskBand.GetOverviewCount();
iOverview++ )
{
Band hOverview;
if( iOverview != 0 )
System.out.print( ", " );
hOverview = hMaskBand.GetOverview( iOverview );
System.out.print(
hOverview.getXSize() + "x" +
hOverview.getYSize() );
}
System.out.print( "\n" );
}
}