Hello:
I'm using the org.geotools.gce.geotiff.GeoTiffReader class to read
geotiff files into a legacy application using the legacy app's rendering
mechanisms. Thus, I need to read in the geotiff file and extract the
geotiff-specific metadata so that I can build my own transform to
display the image data correctly in the legacy app.
I have tried to use the IIOMetadata class to instantiate a
GeoTiffIIOMetadataAdapter object and then extract the geotiff metadata I
need to render the image. Here is the complete program, the jars
required to compile and run the program, and the output created which
details the exception thrown.
Any suggestions on how I can fix this code to extract and print the
geotiff metadata would be appreciated.
thanks in advance,
-rob
--------------------------------------------------------------
source for GeotiffMetadataExtractor1.java:
--------------------------------------------------------------
// Source for class GeotiffMetadataExtractor1:
import java.awt.image.RenderedImage;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.metadata.IIOMetadata;
import javax.media.jai.RenderedImageAdapter;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffFormat;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.gce.geotiff.GeoTiffIIOMetadataAdapter;
public class GeotiffMetadataExtractor1 {
File imageFile;
public static void main(String args[]) {
String filename = args[0];
System.out.println("extracting geotiff metadata from file: " + filename);
GeotiffMetadataExtractor1 gtme = new GeotiffMetadataExtractor1(filename);
gtme.extractMetadata();
}
public GeotiffMetadataExtractor1(String filename) {
imageFile = new File(filename);
if (imageFile.exists()) {
System.out.println("File " + imageFile + " exists.");
} else {
System.out.println("warning: file " + imageFile + " does not exist.");
}
if (imageFile.canRead()) {
System.out.println("File " + imageFile + " can be read.");
} else {
System.out.println("warning: file " + imageFile + " can not be read.");
}
}
public void extractMetadata() {
IIOMetadata iIOMetadata = null;
try {
ImageInputStream stream = ImageIO.createImageInputStream(imageFile);
Iterator iter = ImageIO.getImageReaders(stream);
if (iter.hasNext()) {
ImageReader reader = (ImageReader)iter.next();
reader.setInput(stream);
iIOMetadata = reader.getImageMetadata(0);
} else {
System.out.println("warning: no ImageReaders found in file " +
imageFile);
}
GeoTiffFormat fmt = new GeoTiffFormat();
GeoTiffReader rdr = new GeoTiffReader(fmt, imageFile, null);
GeoTiffIIOMetadataAdapter geoTiffMetadataAdapter = new
GeoTiffIIOMetadataAdapter(iIOMetadata);
System.out.println("geoTiffMetadataAdapter.getNumGeoKeys()=" +
geoTiffMetadataAdapter.getNumGeoKeys());
String[] metadataNames = rdr.getMetadataNames();
for (int i=0; i<metadataNames.length; i++) {
System.out.println("metadata[" + i + "] name=\'" +
metadataNames[i] + "\', value=\'" +
rdr.getMetadataValue(metadataNames[i]) + "\'");
} // for
GridCoverage2D gc = (GridCoverage2D) rdr.read(null);
final RenderedImage image = gc.getRenderableImage(0,
1).createDefaultRendering();
RenderedImageAdapter ria = new RenderedImageAdapter(image);
BufferedImage bufImage= ria.getAsBufferedImage();
} catch(Exception e) {
e.printStackTrace();
}
}
}
// end of Source for class GeotiffMetadataExtractor1
--------------------------------------------------------------
jars required:
geotools\plugin\geotiff\gt2-geotiff.jar
geotools\module\main\gt2-main.jar
geotools\shared\geoapi-2.0.jar
geotools\shared\units-0.01.jar
geotools\module\main\lib\jai_codec-1.1.3-alpha.jar
geotools\module\main\lib\jai_imageio-1.1-alpha.jar
geotools\module\main\lib\jai-core-1.1.3-alpha.jar
--------------------------------------------------------------
output generated:
C:\geotools\robtest>C:\jdk1.5.0_05\bin\java -cp
C:\geotools\plugin\geotiff\gt2-g
eotiff.jar;C:\geotools\module\main\gt2-main.jar;C:\geotools\shared\geoapi-2.0.ja
r;C:\geotools\shared\units-0.01.jar;C:\geotools\module\main\lib\jai_codec-1.1.3-
alpha.jar;C:\geotools\module\main\lib\jai_imageio-1.1-alpha.jar;C:\geotools\modu
le\main\lib\jai-core-1.1.3-alpha.jar;. GeotiffMetadataExtractor1
data\rob_Dulles
_and_National_airports.TIF
extracting geotiff metadata from file:
data\rob_Dulles_and_National_airports.TIF
File data\rob_Dulles_and_National_airports.TIF exists.
File data\rob_Dulles_and_National_airports.TIF can be read.
geoTiffMetadataAdapter.getNumGeoKeys()=0
java.lang.UnsupportedOperationException: GeoTIFF reader doesn't support
metadata
manipulation yet
at
org.geotools.gce.geotiff.GeoTiffReader.getMetadataNames(GeoTiffReader
.java:162)
at
GeotiffMetadataExtractor1.extractMetadata(GeotiffMetadataExtractor1.j
ava:64)
at GeotiffMetadataExtractor1.main(GeotiffMetadataExtractor1.java:26)
--------------------------------------------------------------
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users