1

i have an image in JPG also crated JGW file using Affine transformation now i want to convert this jpg file with jgw file into geotiff how can i do that? thanks

1 Answers1

0

First you'll need to make sure you have a dependency on gt-image and gt-geotiff:

<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-image</artifactId>
  <version>${geotools.version}</version>
</dependency>
<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-geotiff</artifactId>
  <version>${geotools.version}</version>
</dependency>

Then you can simply open the JPG with WLD file (or any other image based file) and write it out as a GeoTIFF.

AbstractGridFormat format = GridFormatFinder.findFormat(input);
Hints hints = null;
if (format instanceof GeoTiffFormat) {
  hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
}

AbstractGridCoverage2DReader reader = format.getReader(input, hints);
GridCoverage2D grid = reader.read(null);
reader.dispose();
File out = new File("test.tif");

GeoTiffFormat outFormat = new GeoTiffFormat();
GridCoverageWriter writer = outFormat.getWriter(out, hints);
writer.write(grid, null);
writer.dispose();
Ian Turton
  • 10,018
  • 1
  • 28
  • 47
  • Thanks for reply please guide this line AbstractGridFormat format = GridFormatFinder.findFormat(input); what is input in this line new File(image path) or new File(JGW) path – ammar javed Aug 14 '19 at 15:03
  • Hints class not found what dependency do i need to add for Hints? – ammar javed Aug 16 '19 at 01:13
  • org.geotools.coverage.grid.io.GridFormatFactorySpi is not an ImageIO SPI class – ammar javed Aug 23 '19 at 17:48
  • AbstractGridFormat format=GridFormatFinder.findFormat( new File("C:\\Users\\NVIS-DEVLAB\\Desktop\\img\\Bangi.jpg")) this is the line where above error is coming – ammar javed Aug 23 '19 at 19:18