GithubHelp home page GithubHelp logo

tcallsen / geotiff2java Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 7 KB

Simple Java app that reads GeoTIFF file data with GeoTools.

Home Page: https://taylor.callsen.me/parsing-geotiff-files-in-java/

Java 100.00%
geotiff geotools java

geotiff2java's Introduction

Read GeoTIFF Data with Java GeoTools

Demonstrates how to read GeoTIFF data using the GeoTools library in Java. Raster data is retrieved for a particular latitude/longitude.

GeoTIFF Compression

GeoTIFF files can be compressed to reduce filesize. I was not able to get the GeoTools library to read GeoTIFF files with LZW compression, and had to uncompress the file with GDAL prior to reading it in Java/GeoTools:

gdal_translate pathtoinput.tif pathforoutput.tif -co COMPRESS=NONE

I was able to read the LZW compressed files directly when using the GDAL Java bindings (sample project).

For more information on GeoTIFF compression, check out: https://kokoalberti.com/articles/geotiff-compression-optimization-guide/

Other Libraries

I experimented with a few other Java libraries for reading GeoTIFF files. The code snippets below show how to read the file into a Raster object. From there, the steps in App.java can be followed.

I also created another sample project that reads GeoTIFF data using the Java GDAL bindings: https://github.com/tcallsen/geotiff2java-gdal

Java Advanced Imaging - no GeoTIFF LZW Compression support

// https://stackoverflow.com/questions/15429011/how-to-convert-tiff-to-jpeg-png-in-java
FileSeekableStream s = new FileSeekableStream(tiffFile);
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
RenderedImage op = dec.decodeAsRenderedImage(0);
Raster tiffRaster = op.getData();

ImageIO - no GeoTIFF LZW Compression support

// https://stackoverflow.com/questions/64537498/get-tiff-tag-value-including-non-ascii-characters-from-tiff-images-in-java-11
try (ImageInputStream input = ImageIO.createImageInputStream(tiffFile)) {
  ImageReader reader = ImageIO.getImageReaders(input).next(); // TODO: Handle reader not found
  reader.setInput(input);
  // IIOMetadata metadata = reader.getImageMetadata(0); // 0 is the index of first image
  BufferedImage image = reader.read(0);
  Raster tiffRaster = image.getData();
}

Apache Commons Imaging - support for GeoTiff LZW compression but samples not as accurate

// https://gis.stackexchange.com/questions/119134/looking-for-an-open-source-java-based-geotiff-library
final TiffImagingParameters params = new TiffImagingParameters();
TiffImageParser readerT = new TiffImageParser();
BufferedImage image = readerT.getBufferedImage(tiffFile, params);
Raster tiffRaster = image.getData();

Blog Post

A blog post that discusses this project in more detail is available here: https://taylor.callsen.me/parsing-geotiff-files-in-java/

geotiff2java's People

Contributors

tcallsen avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

xx5302617

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.