1 /****************************************************************************** 2 * $Id: gdalinfo.java f070adf64950cae1c6cc86b104ba835c29df06b1 2016-08-28 06:06:11Z Kurt Schwehr $ 3 * 4 * Name: gdalinfo.java 5 * Project: GDAL SWIG Interface 6 * Purpose: Java port of gdalinfo application 7 * Author: Benjamin Collins, The MITRE Corporation 8 * 9 * **************************************************************************** 10 * Copyright (c) 2009, Even Rouault 11 * Copyright (c) 1998, Frank Warmerdam 12 * Copyright (c) 2006, The MITRE Corporation 13 * 14 * Permission is hereby granted, free of charge, to any person obtaining a 15 * copy of this software and associated documentation files (the "Software"), 16 * to deal in the Software without restriction, including without limitation 17 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 18 * and/or sell copies of the Software, and to permit persons to whom the 19 * Software is furnished to do so, subject to the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be included 22 * in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 30 * DEALINGS IN THE SOFTWARE. 31 ****************************************************************************/ 32 33 34 import java.util.Enumeration; 35 import java.util.Hashtable; 36 import java.util.Vector; 37 38 import org.gdal.gdal.Band; 39 import org.gdal.gdal.ColorTable; 40 import org.gdal.gdal.Dataset; 41 import org.gdal.gdal.Driver; 42 import org.gdal.gdal.GCP; 43 import org.gdal.gdal.gdal; 44 import org.gdal.gdal.TermProgressCallback; 45 import org.gdal.gdal.RasterAttributeTable; 46 import org.gdal.gdalconst.gdalconstConstants; 47 import org.gdal.osr.CoordinateTransformation; 48 import org.gdal.osr.SpatialReference; 49 50 public class gdalinfo { 51 52 /************************************************************************/ 53 /* Usage() */ 54 /************************************************************************/ 55 Usage()56 public static void Usage() 57 58 { 59 System.out 60 .println("Usage: gdalinfo [--help-general] [-mm] [-stats] [-hist] [-nogcp] [-nomd]\n" 61 + " [-norat] [-noct] [-mdd domain]* [-checksum] datasetname"); 62 System.exit(1); 63 } 64 65 /************************************************************************/ 66 /* main() */ 67 /************************************************************************/ 68 main(String[] args)69 public static void main(String[] args) { 70 { 71 Dataset hDataset; 72 Band hBand; 73 int i, iBand; 74 double[] adfGeoTransform = new double[6]; 75 Driver hDriver; 76 Vector papszMetadata; 77 boolean bComputeMinMax = false; 78 /* boolean bSample = false; */ 79 boolean bShowGCPs = true, bShowMetadata = true; 80 boolean bStats = false, bApproxStats = true; 81 boolean bShowColorTable = true, bComputeChecksum = false; 82 boolean bReportHistograms = false; 83 boolean bShowRAT = true; 84 String pszFilename = null; 85 Vector papszFileList; 86 Vector papszExtraMDDomains = new Vector(); 87 88 gdal.AllRegister(); 89 90 args = gdal.GeneralCmdLineProcessor(args); 91 92 if (args.length < 1) { 93 Usage(); 94 System.exit(0); 95 } 96 /* -------------------------------------------------------------------- */ 97 /* Parse arguments. */ 98 /* -------------------------------------------------------------------- */ 99 for (i = 0; i < args.length; i++) { 100 if (args[i].equals("-mm")) 101 bComputeMinMax = true; 102 else if (args[i].equals("-hist")) 103 bReportHistograms = true; 104 else if (args[i].equals("-stats")) 105 { 106 bStats = true; 107 bApproxStats = false; 108 } 109 else if (args[i].equals("-approx_stats")) 110 { 111 bStats = true; 112 bApproxStats = true; 113 } 114 else if (args[i].equals("-nogcp")) 115 bShowGCPs = false; 116 else if( args[i].equals("-noct")) 117 bShowColorTable = false; 118 else if (args[i].equals("-nomd")) 119 bShowMetadata = false; 120 else if (args[i].equals("-norat")) 121 bShowRAT = false; 122 else if (args[i].equals("-checksum")) 123 bComputeChecksum = true; 124 else if (args[i].equals("-mdd") && i + 1 < args.length) 125 papszExtraMDDomains.addElement(args[++i]); 126 else if (args[i].startsWith("-")) 127 Usage(); 128 else if (pszFilename == null) 129 pszFilename = args[i]; 130 else 131 Usage(); 132 } 133 if (pszFilename == null) 134 Usage(); 135 136 /* -------------------------------------------------------------------- */ 137 /* Open dataset. */ 138 /* -------------------------------------------------------------------- */ 139 hDataset = gdal.Open(pszFilename, gdalconstConstants.GA_ReadOnly); 140 141 if (hDataset == null) { 142 System.err 143 .println("GDALOpen failed - " + gdal.GetLastErrorNo()); 144 System.err.println(gdal.GetLastErrorMsg()); 145 146 //gdal.DumpOpenDatasets( stderr ); 147 148 //gdal.DestroyDriverManager(); 149 150 //gdal.DumpSharedList( null ); 151 152 System.exit(1); 153 } 154 155 /* -------------------------------------------------------------------- */ 156 /* Report general info. */ 157 /* -------------------------------------------------------------------- */ 158 hDriver = hDataset.GetDriver(); 159 System.out.println("Driver: " + hDriver.getShortName() + "/" 160 + hDriver.getLongName()); 161 162 papszFileList = hDataset.GetFileList( ); 163 if( papszFileList.size() == 0 ) 164 { 165 System.out.println( "Files: none associated" ); 166 } 167 else 168 { 169 Enumeration e = papszFileList.elements(); 170 System.out.println( "Files: " + (String)e.nextElement() ); 171 while(e.hasMoreElements()) 172 System.out.println( " " + (String)e.nextElement() ); 173 } 174 175 System.out.println("Size is " + hDataset.getRasterXSize() + ", " 176 + hDataset.getRasterYSize()); 177 178 /* -------------------------------------------------------------------- */ 179 /* Report projection. */ 180 /* -------------------------------------------------------------------- */ 181 if (hDataset.GetProjectionRef() != null) { 182 SpatialReference hSRS; 183 String pszProjection; 184 185 pszProjection = hDataset.GetProjectionRef(); 186 187 hSRS = new SpatialReference(pszProjection); 188 if (hSRS != null && pszProjection.length() != 0) { 189 String[] pszPrettyWkt = new String[1]; 190 191 hSRS.ExportToPrettyWkt(pszPrettyWkt, 0); 192 System.out.println("Coordinate System is:"); 193 System.out.println(pszPrettyWkt[0]); 194 //gdal.CPLFree( pszPrettyWkt ); 195 } else 196 System.out.println("Coordinate System is `" 197 + hDataset.GetProjectionRef() + "'"); 198 199 hSRS.delete(); 200 } 201 202 /* -------------------------------------------------------------------- */ 203 /* Report Geotransform. */ 204 /* -------------------------------------------------------------------- */ 205 hDataset.GetGeoTransform(adfGeoTransform); 206 { 207 if (adfGeoTransform[2] == 0.0 && adfGeoTransform[4] == 0.0) { 208 System.out.println("Origin = (" + adfGeoTransform[0] + "," 209 + adfGeoTransform[3] + ")"); 210 211 System.out.println("Pixel Size = (" + adfGeoTransform[1] 212 + "," + adfGeoTransform[5] + ")"); 213 } else { 214 System.out.println("GeoTransform ="); 215 System.out.println(" " + adfGeoTransform[0] + ", " 216 + adfGeoTransform[1] + ", " + adfGeoTransform[2]); 217 System.out.println(" " + adfGeoTransform[3] + ", " 218 + adfGeoTransform[4] + ", " + adfGeoTransform[5]); 219 } 220 } 221 222 /* -------------------------------------------------------------------- */ 223 /* Report GCPs. */ 224 /* -------------------------------------------------------------------- */ 225 if (bShowGCPs && hDataset.GetGCPCount() > 0) { 226 System.out.println("GCP Projection = " 227 + hDataset.GetGCPProjection()); 228 229 int count = 0; 230 Vector GCPs = new Vector(); 231 hDataset.GetGCPs(GCPs); 232 233 Enumeration e = GCPs.elements(); 234 while (e.hasMoreElements()) { 235 GCP gcp = (GCP) e.nextElement(); 236 System.out.println("GCP[" + (count++) + "]: Id=" 237 + gcp.getId() + ", Info=" + gcp.getInfo()); 238 System.out.println(" (" + gcp.getGCPPixel() + "," 239 + gcp.getGCPLine() + ") (" + gcp.getGCPX() + "," 240 + gcp.getGCPY() + "," + gcp.getGCPZ() + ")"); 241 } 242 243 } 244 245 /* -------------------------------------------------------------------- */ 246 /* Report metadata. */ 247 /* -------------------------------------------------------------------- */ 248 papszMetadata = hDataset.GetMetadata_List(""); 249 if (bShowMetadata && papszMetadata.size() > 0) { 250 Enumeration keys = papszMetadata.elements(); 251 System.out.println("Metadata:"); 252 while (keys.hasMoreElements()) { 253 System.out.println(" " + (String) keys.nextElement()); 254 } 255 } 256 257 Enumeration eExtraMDDDomains = papszExtraMDDomains.elements(); 258 while(eExtraMDDDomains.hasMoreElements()) 259 { 260 String pszDomain = (String)eExtraMDDDomains.nextElement(); 261 papszMetadata = hDataset.GetMetadata_List(pszDomain); 262 if( bShowMetadata && papszMetadata.size() > 0 ) 263 { 264 Enumeration keys = papszMetadata.elements(); 265 System.out.println("Metadata (" + pszDomain + "):"); 266 while (keys.hasMoreElements()) { 267 System.out.println(" " + (String) keys.nextElement()); 268 } 269 } 270 } 271 /* -------------------------------------------------------------------- */ 272 /* Report "IMAGE_STRUCTURE" metadata. */ 273 /* -------------------------------------------------------------------- */ 274 papszMetadata = hDataset.GetMetadata_List("IMAGE_STRUCTURE" ); 275 if( bShowMetadata && papszMetadata.size() > 0) { 276 Enumeration keys = papszMetadata.elements(); 277 System.out.println("Image Structure Metadata:"); 278 while (keys.hasMoreElements()) { 279 System.out.println(" " + (String) keys.nextElement()); 280 } 281 } 282 /* -------------------------------------------------------------------- */ 283 /* Report subdatasets. */ 284 /* -------------------------------------------------------------------- */ 285 papszMetadata = hDataset.GetMetadata_List("SUBDATASETS"); 286 if (papszMetadata.size() > 0) { 287 System.out.println("Subdatasets:"); 288 Enumeration keys = papszMetadata.elements(); 289 while (keys.hasMoreElements()) { 290 System.out.println(" " + (String) keys.nextElement()); 291 } 292 } 293 294 /* -------------------------------------------------------------------- */ 295 /* Report geolocation. */ 296 /* -------------------------------------------------------------------- */ 297 papszMetadata = hDataset.GetMetadata_List("GEOLOCATION" ); 298 if (papszMetadata.size() > 0) { 299 System.out.println( "Geolocation:" ); 300 Enumeration keys = papszMetadata.elements(); 301 while (keys.hasMoreElements()) { 302 System.out.println(" " + (String) keys.nextElement()); 303 } 304 } 305 306 /* -------------------------------------------------------------------- */ 307 /* Report RPCs */ 308 /* -------------------------------------------------------------------- */ 309 papszMetadata = hDataset.GetMetadata_List("RPC" ); 310 if (papszMetadata.size() > 0) { 311 System.out.println( "RPC Metadata:" ); 312 Enumeration keys = papszMetadata.elements(); 313 while (keys.hasMoreElements()) { 314 System.out.println(" " + (String) keys.nextElement()); 315 } 316 } 317 318 /* -------------------------------------------------------------------- */ 319 /* Report corners. */ 320 /* -------------------------------------------------------------------- */ 321 System.out.println("Corner Coordinates:"); 322 GDALInfoReportCorner(hDataset, "Upper Left ", 0.0, 0.0); 323 GDALInfoReportCorner(hDataset, "Lower Left ", 0.0, hDataset 324 .getRasterYSize()); 325 GDALInfoReportCorner(hDataset, "Upper Right", hDataset 326 .getRasterXSize(), 0.0); 327 GDALInfoReportCorner(hDataset, "Lower Right", hDataset 328 .getRasterXSize(), hDataset.getRasterYSize()); 329 GDALInfoReportCorner(hDataset, "Center ", 330 hDataset.getRasterXSize() / 2.0, 331 hDataset.getRasterYSize() / 2.0); 332 333 /* ==================================================================== */ 334 /* Loop over bands. */ 335 /* ==================================================================== */ 336 for (iBand = 0; iBand < hDataset.getRasterCount(); iBand++) { 337 Double[] pass1 = new Double[1], pass2 = new Double[1]; 338 double[] adfCMinMax = new double[2]; 339 ColorTable hTable; 340 341 hBand = hDataset.GetRasterBand(iBand + 1); 342 343 /*if( bSample ) 344 { 345 float[] afSample = new float[10000]; 346 int nCount; 347 348 nCount = hBand.GetRandomRasterSample( 10000, afSample ); 349 System.out.println( "Got " + nCount + " samples." ); 350 }*/ 351 352 int[] blockXSize = new int[1]; 353 int[] blockYSize = new int[1]; 354 hBand.GetBlockSize(blockXSize, blockYSize); 355 System.out.println("Band " 356 + (iBand+1) 357 + " Block=" 358 + blockXSize[0] + "x" + blockYSize[0] 359 + " Type=" 360 + gdal.GetDataTypeName(hBand.getDataType()) 361 + ", ColorInterp=" 362 + gdal.GetColorInterpretationName(hBand 363 .GetRasterColorInterpretation())); 364 365 String hBandDesc = hBand.GetDescription(); 366 if (hBandDesc != null && hBandDesc.length() > 0) 367 System.out.println(" Description = " + hBandDesc); 368 369 hBand.GetMinimum(pass1); 370 hBand.GetMaximum(pass2); 371 if(pass1[0] != null || pass2[0] != null || bComputeMinMax) { 372 System.out.print( " " ); 373 if( pass1[0] != null ) 374 System.out.print( "Min=" + pass1[0] + " "); 375 if( pass2[0] != null ) 376 System.out.print( "Max=" + pass2[0] + " "); 377 378 if( bComputeMinMax ) 379 { 380 hBand.ComputeRasterMinMax(adfCMinMax, 0); 381 System.out.print( " Computed Min/Max=" + adfCMinMax[0] 382 + "," + adfCMinMax[1]); 383 } 384 385 System.out.print( "\n" ); 386 } 387 388 double dfMin[] = new double[1]; 389 double dfMax[] = new double[1]; 390 double dfMean[] = new double[1]; 391 double dfStdDev[] = new double[1]; 392 if( hBand.GetStatistics( bApproxStats, bStats, 393 dfMin, dfMax, dfMean, dfStdDev ) == gdalconstConstants.CE_None ) 394 { 395 System.out.println( " Minimum=" + dfMin[0] + ", Maximum=" + dfMax[0] + 396 ", Mean=" + dfMean[0] + ", StdDev=" + dfStdDev[0] ); 397 } 398 399 if( bReportHistograms ) 400 { 401 int[][] panHistogram = new int[1][]; 402 int eErr = hBand.GetDefaultHistogram(dfMin, dfMax, panHistogram, true, new TermProgressCallback()); 403 if( eErr == gdalconstConstants.CE_None ) 404 { 405 int iBucket; 406 int nBucketCount = panHistogram[0].length; 407 System.out.print( " " + nBucketCount + " buckets from " + 408 dfMin[0] + " to " + dfMax[0] + ":\n " ); 409 for( iBucket = 0; iBucket < nBucketCount; iBucket++ ) 410 System.out.print( panHistogram[0][iBucket] + " "); 411 System.out.print( "\n" ); 412 } 413 } 414 415 if ( bComputeChecksum) 416 { 417 System.out.println( " Checksum=" + hBand.Checksum()); 418 } 419 420 hBand.GetNoDataValue(pass1); 421 if(pass1[0] != null) 422 { 423 System.out.println(" NoData Value=" + pass1[0]); 424 } 425 426 if (hBand.GetOverviewCount() > 0) { 427 int iOverview; 428 429 System.out.print(" Overviews: "); 430 for (iOverview = 0; iOverview < hBand.GetOverviewCount(); iOverview++) { 431 Band hOverview; 432 433 if (iOverview != 0) 434 System.out.print(", "); 435 436 hOverview = hBand.GetOverview(iOverview); 437 System.out.print(hOverview.getXSize() + "x" 438 + hOverview.getYSize()); 439 } 440 System.out.print("\n"); 441 442 if ( bComputeChecksum) 443 { 444 System.out.print( " Overviews checksum: " ); 445 for( iOverview = 0; 446 iOverview < hBand.GetOverviewCount(); 447 iOverview++ ) 448 { 449 Band hOverview; 450 451 if( iOverview != 0 ) 452 System.out.print( ", " ); 453 454 hOverview = hBand.GetOverview(iOverview); 455 System.out.print( hOverview.Checksum()); 456 } 457 System.out.print( "\n" ); 458 } 459 } 460 461 if( hBand.HasArbitraryOverviews() ) 462 { 463 System.out.println( " Overviews: arbitrary" ); 464 } 465 466 467 int nMaskFlags = hBand.GetMaskFlags( ); 468 if( (nMaskFlags & (gdalconstConstants.GMF_NODATA|gdalconstConstants.GMF_ALL_VALID)) == 0 ) 469 { 470 Band hMaskBand = hBand.GetMaskBand() ; 471 472 System.out.print( " Mask Flags: " ); 473 if( (nMaskFlags & gdalconstConstants.GMF_PER_DATASET) != 0 ) 474 System.out.print( "PER_DATASET " ); 475 if( (nMaskFlags & gdalconstConstants.GMF_ALPHA) != 0 ) 476 System.out.print( "ALPHA " ); 477 if( (nMaskFlags & gdalconstConstants.GMF_NODATA) != 0 ) 478 System.out.print( "NODATA " ); 479 if( (nMaskFlags & gdalconstConstants.GMF_ALL_VALID) != 0 ) 480 System.out.print( "ALL_VALID " ); 481 System.out.print( "\n" ); 482 483 if( hMaskBand != null && 484 hMaskBand.GetOverviewCount() > 0 ) 485 { 486 int iOverview; 487 488 System.out.print( " Overviews of mask band: " ); 489 for( iOverview = 0; 490 iOverview < hMaskBand.GetOverviewCount(); 491 iOverview++ ) 492 { 493 Band hOverview; 494 495 if( iOverview != 0 ) 496 System.out.print( ", " ); 497 498 hOverview = hMaskBand.GetOverview( iOverview ); 499 System.out.print( 500 hOverview.getXSize() + "x" + 501 hOverview.getYSize() ); 502 } 503 System.out.print( "\n" ); 504 } 505 } 506 507 if( hBand.GetUnitType() != null && hBand.GetUnitType().length() > 0) 508 { 509 System.out.println( " Unit Type: " + hBand.GetUnitType() ); 510 } 511 512 Vector papszCategories = hBand.GetRasterCategoryNames(); 513 if (papszCategories.size() > 0) 514 { 515 System.out.println( " Categories:" ); 516 Enumeration eCategories = papszCategories.elements(); 517 i = 0; 518 while (eCategories.hasMoreElements()) { 519 System.out.println(" " + i + ": " + (String) eCategories.nextElement()); 520 i ++; 521 } 522 } 523 524 hBand.GetOffset(pass1); 525 if(pass1[0] != null && pass1[0].doubleValue() != 0) { 526 System.out.print(" Offset: " + pass1[0]); 527 } 528 hBand.GetScale(pass1); 529 if(pass1[0] != null && pass1[0].doubleValue() != 1) { 530 System.out.println(", Scale:" + pass1[0]); 531 } 532 533 papszMetadata = hBand.GetMetadata_List(""); 534 if( bShowMetadata && papszMetadata.size() > 0 ) { 535 Enumeration keys = papszMetadata.elements(); 536 System.out.println(" Metadata:"); 537 while (keys.hasMoreElements()) { 538 System.out.println(" " + (String) keys.nextElement()); 539 } 540 } 541 if (hBand.GetRasterColorInterpretation() == gdalconstConstants.GCI_PaletteIndex 542 && (hTable = hBand.GetRasterColorTable()) != null) { 543 int count; 544 545 System.out.println(" Color Table (" 546 + gdal.GetPaletteInterpretationName(hTable 547 .GetPaletteInterpretation()) + " with " 548 + hTable.GetCount() + " entries)"); 549 550 if (bShowColorTable) 551 { 552 for (count = 0; count < hTable.GetCount(); count++) { 553 System.out.println(" " + count + ": " 554 + hTable.GetColorEntry(count)); 555 } 556 } 557 } 558 559 RasterAttributeTable rat = hBand.GetDefaultRAT(); 560 if( bShowRAT && rat != null ) 561 { 562 System.out.print("<GDALRasterAttributeTable "); 563 double[] pdfRow0Min = new double[1]; 564 double[] pdfBinSize = new double[1]; 565 if (rat.GetLinearBinning(pdfRow0Min, pdfBinSize)) 566 { 567 System.out.print("Row0Min=\"" + pdfRow0Min[0] + "\" BinSize=\"" + pdfBinSize[0] + "\">"); 568 } 569 System.out.print("\n"); 570 int colCount = rat.GetColumnCount(); 571 for(int col=0;col<colCount;col++) 572 { 573 System.out.println(" <FieldDefn index=\"" + col + "\">"); 574 System.out.println(" <Name>" + rat.GetNameOfCol(col) + "</Name>"); 575 System.out.println(" <Type>" + rat.GetTypeOfCol(col) + "</Type>"); 576 System.out.println(" <Usage>" + rat.GetUsageOfCol(col) + "</Usage>"); 577 System.out.println(" </FieldDefn>"); 578 } 579 int rowCount = rat.GetRowCount(); 580 for(int row=0;row<rowCount;row++) 581 { 582 System.out.println(" <Row index=\"" + row + "\">"); 583 for(int col=0;col<colCount;col++) 584 { 585 System.out.println(" <F>" + rat.GetValueAsString(row, col)+ "</F>"); 586 } 587 System.out.println(" </Row>"); 588 } 589 System.out.println("</GDALRasterAttributeTable>"); 590 } 591 } 592 593 hDataset.delete(); 594 595 /* Optional */ 596 gdal.GDALDestroyDriverManager(); 597 598 System.exit(0); 599 } 600 } 601 602 /************************************************************************/ 603 /* GDALInfoReportCorner() */ 604 /************************************************************************/ 605 GDALInfoReportCorner(Dataset hDataset, String corner_name, double x, double y)606 static boolean GDALInfoReportCorner(Dataset hDataset, String corner_name, 607 double x, double y) 608 609 { 610 double dfGeoX, dfGeoY; 611 String pszProjection; 612 double[] adfGeoTransform = new double[6]; 613 CoordinateTransformation hTransform = null; 614 615 System.out.print(corner_name + " "); 616 617 /* -------------------------------------------------------------------- */ 618 /* Transform the point into georeferenced coordinates. */ 619 /* -------------------------------------------------------------------- */ 620 hDataset.GetGeoTransform(adfGeoTransform); 621 { 622 pszProjection = hDataset.GetProjectionRef(); 623 624 dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x 625 + adfGeoTransform[2] * y; 626 dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x 627 + adfGeoTransform[5] * y; 628 } 629 630 if (adfGeoTransform[0] == 0 && adfGeoTransform[1] == 0 631 && adfGeoTransform[2] == 0 && adfGeoTransform[3] == 0 632 && adfGeoTransform[4] == 0 && adfGeoTransform[5] == 0) { 633 System.out.println("(" + x + "," + y + ")"); 634 return false; 635 } 636 637 /* -------------------------------------------------------------------- */ 638 /* Report the georeferenced coordinates. */ 639 /* -------------------------------------------------------------------- */ 640 System.out.print("(" + dfGeoX + "," + dfGeoY + ") "); 641 642 /* -------------------------------------------------------------------- */ 643 /* Setup transformation to lat/long. */ 644 /* -------------------------------------------------------------------- */ 645 if (pszProjection != null && pszProjection.length() > 0) { 646 SpatialReference hProj, hLatLong = null; 647 648 hProj = new SpatialReference(pszProjection); 649 if (hProj != null) 650 hLatLong = hProj.CloneGeogCS(); 651 652 if (hLatLong != null) { 653 /* New in GDAL 1.10. Before was "new CoordinateTransformation(srs,dst)". */ 654 hTransform = CoordinateTransformation.CreateCoordinateTransformation(hProj, hLatLong); 655 } 656 657 if (hProj != null) 658 hProj.delete(); 659 } 660 661 /* -------------------------------------------------------------------- */ 662 /* Transform to latlong and report. */ 663 /* -------------------------------------------------------------------- */ 664 if (hTransform != null) { 665 double[] transPoint = new double[3]; 666 hTransform.TransformPoint(transPoint, dfGeoX, dfGeoY, 0); 667 System.out.print("(" + gdal.DecToDMS(transPoint[0], "Long", 2)); 668 System.out 669 .print("," + gdal.DecToDMS(transPoint[1], "Lat", 2) + ")"); 670 } 671 672 if (hTransform != null) 673 hTransform.delete(); 674 675 System.out.println(""); 676 677 return true; 678 } 679 } 680