7

I have written many programs for reading and writing various types of spatial data in the past but I must admit that the GeoTIFF format has often gotten the better of me. It's such a flexible format that writing code to read/write the variations that are commonly found in the wild is extremely challenging. So I am looking for a library that I can use for accomplishing this task.

Here are my requirements:

  1. It must be developed in Java and exist as a single and ideally very small JAR file that can be easily incorporated in existing projects.

  2. It must have a licence compatible with the GNU GPL.

  3. It must be able to handle many different flavours of GeoTIFF including the various types of data compression.

The GeoTIFF web page recommends GeoTIFF-JAI (it's also recommended by the answerer of this GIS.SE question) however the project doesn't appear to have been maintained since 2001 and I am not able to find any documentation to describe its use. I am currently using a modified version of the UCAR GeoTIFF reader but it similarly is not actively maintained nor documented, and does not handle many types of modern GeoTIFFs (no compression formats). I am aware that GDAL can handle GeoTIFF quite well and that there is a JNI interface to link with Java but I am looking for a small-footprint native Java solution. I am also aware that GeoTools has a means of dealing with GeoTIFFs, but as the OP of this question points out, it actually requires a GDAL plugin, which unfortunately I need to avoid.

I realize that I am asking for a lot here but is anyone aware of a GeoTIFF library that meets these conditions? I thought I'd ask before spending another couple of days trying to hack together a solution for dealing with compressed formats.

  • Why don't you incorporate the GDAL libraries directly into your project? This avoids the undesirable separate install. GDAL has a Java API released under the X/MIT licence (i.e. open source and allows for redistribution etc like GNU). – MappaGnosis Oct 21 '14 at 14:28
  • @MappaGnosis Interesting, are you saying that I can dump the GDAL libraries into my project and access them through the Java API without prior need to install GDAL on the machine? I assume this uses JNI. In addition to my worries about requiring a proper install is the worry that this would mean I'd lose on the cross-platform status of the project. That is, I'd need to distribute a version for Windows, OS X and Linux separately...something I've tried to avoid which is why I've used only pure Java solutions in the past. Thoughts? – WhiteboxDev Oct 21 '14 at 14:39
  • Could you provide an example for reading a Geotiff using Apache Commons Imaging. – RandomRequest Oct 22 '17 at 16:18
8

Install OpenJUMP and study what all has been gathered into it

enter image description here

I have never really understood what all the alternatives are. ImageIO-ext is probably utilising native GDAL binaries if such are available but at least most other alternatives are pure java. There is also one more alternative in OpenJUMP called "Sextante raster" which is also pure java. Different drivers understand different tiff variants. Make a test data set with different compressions and try what works and what not. Sometimes the tiff needs to be geotiff with valid georeferencing, sometimes .tfw is enough and sometimes even an ungeoreferenced tiff opens.

GeoTools and GeoServer for sure can deal at least with some tiff variants without the ImageIO-ext extension. Install GeoServer without extensions and create new GeoTIFF raster stores from different tiffs and you will know what works and what not with GeoTools.

enter image description here

  • Thank you for your answer. Unfortunately ImageIO-ext requires a GDAL installation. I've purposely designed my project in a way that does not require any installation by the user (except of course for the JRE itself). That way you can download it onto a USB and run it without need for admin privileges and installation. This is an important aspect for me when teaching using the software. Requiring GDAL would mean sacrificing this design characteristic. I do certainly appreciate your answer however. – WhiteboxDev Oct 21 '14 at 14:05
  • 1
    I believe that ImageIO is enough for geotiffs and ImageIO-Ext brings support for JPEG2000 and other exotic formats. ojwiki.soldin.de/…. At least OpenJUMP without installing native GDAL binaries does cope very well with some geotiff variants. And the Apache Commons driver is also fast. – user30184 Oct 21 '14 at 14:31
  • Perfect, I'm investigating it now. Thanks for putting me onto OpenJUMP. I'm just looking at the source now to see if I can figure out how their solution works. It seems to be an excellent project. – WhiteboxDev Oct 21 '14 at 14:33
  • Investigate also how the Image layer works. It is actually a polygon file of image footprints with an index to corresponding image files. With Layer-Image Layer Manager you can add new cells to image layer. – user30184 Oct 21 '14 at 14:43
  • Really interesting. I'll have to take a look. I see that JUMP was developed by VividSolutions, which makes me wonder whether Martin Davis of JTS fame was involved. He truly is a brilliant geospatial programmer! – WhiteboxDev Oct 21 '14 at 14:47
6

I believe that I have found an adequate solution that meets all of my requirements. Thanks to user30184's answer, which pointed me in the direction of ImageIO, I was able to find an alternative Java imaging library called Apache Commons Imaging. It is a pure-Java library that consists of a single small JAR file. It also supports both reading and writing of the TIFF file format and it has built-in support for GeoTIFF tags. It appears to handle all of the common compression formats as well. It's developed under the Apache License, which makes it available to be used within GPL licensed projects. It appears to check all of the requirements.

  • Credit goes to user30184 (+1), without whom I would not have found this library. I'm not entirely sure what the etiquette is for answering your own questions, and I always told myself that I would never do so, so please no upvotes on this one. – WhiteboxDev Oct 21 '14 at 17:11
  • I downloaded the source file of Apache Commons IO. It is 32 MB file. – gansub Feb 6 '15 at 13:13
  • how about the beam GeoTiffProductReader ? – gansub Feb 6 '15 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.