[Geotiff] pleae help me about geotiff

Pascal Quesseveur quesseveur at abaksystemes.fr
Wed Nov 9 03:42:49 EST 2005


>"zl" == zhang lihui <vgelearner at hotmail.com> writes:

  zl>    i want to read geotiff in java, if i have a coordinate value(just like 
  zl> latitude and longtitude),then i read the image data around the value, i 
  zl> down the geotiff-jai.jar,but i have not doc about it ,and how to use 
  zl> it,please help me,

I am going to try to give you some explanations.

In standard Java images are read through the ImageIO API. JAI is an
extension designed to make some advanced image manipulations. That
extension contains a TIFF reader that knows about the GeoTIFF
tags. The TIFF reader can also be used with ImageIO as long as you have
installed the JAIImageIO plugin.

The TIFF reader reads the image file and exposes the TIFF tags as
metadata that can be retrieved and processed by an application. The
GeoTiffIIOMetadataAdapter is a convenience class to help manage
GeoTIFF metadata. From the GeoTiffIIOMetadataAdapter documentation:

 * This class provides an abstraction from the details of TIFF data
 * access for the purpose of retrieving GeoTIFF metadata from an image.

It does exactly what is written.

I have included some code that shows how to access GeoTIFF
metadata. Image file is read using ImageIO. The code looks through
ImageIO readers to identify the TIFF reader. There must be others
ways to read the image.

,----
|         FileImageInputStream f = new FileImageInputStream (
|             new RandomAccessFile (fname, "r"));
| 
|         // Look through ImageIO readers
|         Iterator iter = ImageIO.getImageReaders (f);
|         IIOMetadata imdata = null;
|         GeoTiffIIOMetadataAdapter geo_data;
|         while (iter.hasNext () && imdata == null)
|         {
|             ImageReader reader = (ImageReader) iter.next ();
|             reader.setInput (f, true);
|             String reader_name = reader.getFormatName ().toLowerCase ();
|             if (reader_name.equalsIgnoreCase ("tif"))
|             {
|                 // Get Image metadata
|                 imdata = reader.getImageMetadata (0);
|                 geo_data = new GeoTiffIIOMetadataAdapter (imdata);
|                 if (geo_data != null &&
|                     geo_data.getGeoKeyDirectoryVersion () == 1)
|                 {
|                     int imw = geo_data.getImageWidth ();
|                     int imh = geo_data.getImageHeight ();
| ...
`----

HTH


-- 
Pascal Quesseveur, quesseveur at abaksystemes.fr




More information about the Geotiff mailing list