Skip to main content

waypoints in geotiff ?

9 replies [Last post]
lancelot_234
Offline
Joined: 2010-06-08

Hi,

I downloaded a "geotiff" file from http://www.gelib.com/

also, I created a project (in Eclipse) with one class: "LookupSampleProgram.java"
(that I found in below link)

http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-...

"LookupSampleProgram.java" correctly displayed the 'geotiff' file on the screen.

my questions are:

1) - how can I show 'waypoints' in the map? (no need to change the 'geotiff' file, only to display some polygons (or icons) on top of the map to identify locations.

2) - how can I show coordinates, while moving the mouse over the map?

thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rafael Santos

> any help is appreciated. I couldn't find any information in Internet.
>
>
http://www.lac.inpe.br/JIPCookbook/index.jsp may be of help.

Unless you're looking for the exact solution for your specific problem
(geographic coordinates), then there is none (but take a look at geotools).

> btw, if JAI is not the correct tool for showing 'geotiff' files with 'waypoints', maybe someone could suggest another tool (in Java)?
>
Rafael

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

lancelot_234
Offline
Joined: 2010-06-08

Hi,

thanks for the help.

JadeDisplay and the code sample is a great way to display a 'geotiff' and draw on top of it. (the image was loaded faster too)

I looked at Geotools. the samples 'quickstart.java' and 'quickstart2.java' worked well (they showed a 'shapefile' on the screen), but the sample ImageLab (that should display a 'geotiff' and draw a 'shapefile' on top of it, didn't execute correctly. it threw lots of exceptions)

now I'll start investigating how to extract coordinates from a 'geotiff'. hopefully I can find a .jar that already does it. (no need to reinvent the wheel)

lancelot_234
Offline
Joined: 2010-06-08

Hi,

if someone is interested in extracting information from a GeoTiff file....

this is what I got so far:

I'm trying to use geotools to extract the GeoTiff metadata:

( I got the tiff file from http://www.gelib.com/ )

below is the code I'm using :

the bad news is that it doesn't work. geotools throws lots of exceptions :(

maybe someone in this forum has experience with geotools? (or some other tool for extracting metadata from a GeoTiff?)

btw, [b]if JAI allows displaying a 'GeoTiff', then it should provide an API for accesing its metadata as well.[/b]

-----------

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.geotools.data.DataSourceException;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.gce.geotiff.adapters.GeoTiffIIOMetadataDecoder;

public class ExtractInfoFromGeoTiff {
public static void main(String args[]) throws DataSourceException, FileNotFoundException{

String myImageFile = "b2_A1.tif";
InputStream input = new FileInputStream(myImageFile);
GeoTiffReader a = new GeoTiffReader(input);
GeoTiffIIOMetadataDecoder b = a.getMetadata();

// Geotiff geokeys for geocoding
// http://www.remotesensing.org/geotiff/spec/geotiff2.7.html#2.7.2

int projNatOriginLongGeoKey = 3080;
int projNatOriginLatGeoKey = 3081;

String natOriginLongGeoKey = b.getGeoKey(projNatOriginLongGeoKey);
String natOriginLatGeoKey = b.getGeoKey(projNatOriginLatGeoKey);
}
}

Nidel, Mike

did you ask these questions on the GeoTools forum?

your questions really don't have anything directly to do with JAI.
it's very possible someone here knows the answer, but if they do they
will also probably be a member of the GeoTools forum.

i myself don't know much at all about GeoTools, so I can't help you,
although I did write the GeoTiffIIOMetadataAdapter. But your code
below doesn't use that directly, I guess it uses it down inside GeoTools.

so it's not likely that you'll get a helpful answer here, you should
ask your question to GeoTools developers or users.

> -----Original Message-----
> From: jai-interest@javadesktop.org [mailto:jai-
> interest@javadesktop.org]
> Sent: Thursday, June 10, 2010 8:50 AM
> To: interest@jai.dev.java.net
> Subject: Re: [JAI] Re: waypoints in geotiff ?
>
> Hi,
>
> if someone is interested in extracting information from a GeoTiff
> file....
>
> this is what I got so far:
>
> I'm trying to use geotools to extract the GeoTiff metadata:
>
> ( I got the tiff file from http://www.gelib.com/ )
>
>
> below is the code I'm using :
>
> the bad news is that it doesn't work. geotools throws lots of
> exceptions :(
>
> maybe someone in this forum has experience with geotools? (or some
> other tool for extracting metadata from a GeoTiff?)
>
>
> btw, [b]if JAI allows displaying a 'GeoTiff', then it should provide an
> API for accesing its metadata as well.[/b]
>
> -----------
>
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.InputStream;
>
> import org.geotools.data.DataSourceException;
> import org.geotools.gce.geotiff.GeoTiffReader;
> import org.geotools.gce.geotiff.adapters.GeoTiffIIOMetadataDecoder;
>
>
> public class ExtractInfoFromGeoTiff {
> public static void main(String args[]) throws
> DataSourceException, FileNotFoundException{
>
> String myImageFile = "b2_A1.tif";
> InputStream input = new FileInputStream(myImageFile);
> GeoTiffReader a = new GeoTiffReader(input);
> GeoTiffIIOMetadataDecoder b = a.getMetadata();
>
> // Geotiff geokeys for geocoding
> //
> http://www.remotesensing.org/geotiff/spec/geotiff2.7.html#2.7.2
>
> int projNatOriginLongGeoKey = 3080;
> int projNatOriginLatGeoKey = 3081;
>
> String natOriginLongGeoKey =
> b.getGeoKey(projNatOriginLongGeoKey);
> String natOriginLatGeoKey =
> b.getGeoKey(projNatOriginLatGeoKey);
> }
> }
> [Message sent by forum member 'lancelot_234']
>
> http://forums.java.net/jive/thread.jspa?messageID=473739
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

lancelot_234
Offline
Joined: 2010-06-08

any help is appreciated. I couldn't find any information in Internet.

btw, if JAI is not the correct tool for showing 'geotiff' files with 'waypoints', maybe someone could suggest another tool (in Java)?

thanks.

Nidel, Mike

You need to give some more information.

The key independent points of your program as I see them are:

1. Display the image
2. Display the waypoints on the image.

You'll probably want to create some kind of coordinate converter
that converts from a geocoordinate (lat/long or whatever) to the
x,y location on the geotiff. then you'll convert the geocoordinate
of each waypoint to

What form do you have your image in when it's loaded?
Is it a RenderedImage? Depending on the size of the image, you
may not need JAI to display it (if it's small). You can do the
2 things above with just Java2D (not JAI). Use Graphics2D.drawXYZ()
type methods, once you have the coordinate conversion to x,y
location.

good luck,

> -----Original Message-----
> From: jai-interest@javadesktop.org [mailto:jai-
> interest@javadesktop.org]
> Sent: Tuesday, June 08, 2010 8:36 AM
> To: interest@jai.dev.java.net
> Subject: [JAI] Re: waypoints in geotiff ?
>
> any help is appreciated. I couldn't find any information in Internet.
>
>
> btw, if JAI is not the correct tool for showing 'geotiff' files with
> 'waypoints', maybe someone could suggest another tool (in Java)?
>
>
> thanks.
> [Message sent by forum member 'lancelot_234']
>
> http://forums.java.net/jive/thread.jspa?messageID=473315
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

lancelot_234
Offline
Joined: 2010-06-08

you are correct.

I would appreciate if someone can point me in the right direction on :
[b]- how to convert a coordinate (latitude, longitude) to a x,y location in a "geotiff".[/b]

[b]- how to draw a point (or line, or polygon) over a "geotiff".[/b]

(btw, the geotiff I'm using is quite big. I got it from "Google Earth Library" and the file is over 50 MB)

>What form do you have your image in when it's loaded? Is it a RenderedImage?

difficult question.

below this text, I wrote the code I'm using:
(the code is easier to read from here:

http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-...
)

and the output I get in the console is: "TIFF image is type byte."
----------------------------------

// The main method.
public static void main(String[] args) {
// Validate input.
if (args.length != 1) {
System.out.println("Usage: java LookupSampleProgram " +
"TIFF_image_filename");
System.exit(-1);
}
// Create an input stream from the specified file name to be
// used with the TIFF decoder.
FileSeekableStream stream = null;
try {
stream = new FileSeekableStream(args[0]);
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
// Store the input stream in a ParameterBlock to be sent to
// the operation registry, and eventually to the TIFF
// decoder.
ParameterBlock params = new ParameterBlock();
params.add(stream);
// Specify to TIFF decoder to decode images as they are and
// not to convert unsigned short images to byte images.
TIFFDecodeParam decodeParam = new TIFFDecodeParam();
decodeParam.setDecodePaletteAsShorts(true);
// Create an operator to decode the TIFF file.
RenderedOp image1 = JAI.create("tiff", params);
// Find out the first image's data type.
int dataType = image1.getSampleModel().getDataType();
RenderedOp image2 = null;
if (dataType == DataBuffer.TYPE_BYTE) {
// Display the byte image as it is.
System.out.println("TIFF image is type byte.");
image2 = image1;
} else if (dataType == DataBuffer.TYPE_USHORT) {
// Convert the unsigned short image to byte image.
System.out.println("TIFF image is type ushort.");
// Setup a standard window-level lookup table. */
byte[] tableData = new byte[0x10000];
for (int i = 0; i < 0x10000; i++) {
tableData[i] = (byte)(i >> 8);
}
// Create a LookupTableJAI object to be used with the
// "lookup" operator.
LookupTableJAI table = new LookupTableJAI(tableData);
// Create an operator to lookup image1.
image2 = JAI.create("lookup", image1, table);
} else {
System.out.println("TIFF image is type " + dataType +
", and will not be displayed.");
System.exit(0);
}
// Get the width and height of image2.
int width = image2.getWidth();
int height = image2.getHeight();
// Attach image2 to a scrolling panel to be displayed.
ScrollingImagePanel panel = new ScrollingImagePanel(
image2, width, height);
// Create a frame to contain the panel.
Frame window = new Frame("Lookup Sample Program");
window.add(panel);
window.pack();
window.show();
}
}

----------------------

Nidel, Mike

well i may not be able to answer all your questions.
for the coordinate conversion, you will need to use
the metadata in the geotiff, which is a separate
subject from drawing the image.

from your code it looks like image2 is a RenderedOp.
To load the tiff the way you are doing requires JAI,
as you can see -- you could also use JAI imageIO tools
to load the TIFF, which might be a more up-to-date
implementation and would not require JAI.

Once you have a RenderedOp, which is just an implementation
of RenderedImage, then you want to display it. To draw the
image and points you need a Graphics2D from your swing
component, I assume. Graphics2D has a drawImage() method
that takes in an Image. But you can't pass in a RenderedOp
to this. So you have a few possibilities. If you KNOW that
you can store your whole image in memory you can convert the
RenderedOp to a BufferedImage, which is an Image and can be
passed into Graphics2D.drawImage(). For this you can call
RenderedOp.getAsBufferedImage().

If your image is too large to fit all in memory, then you
probably do not want to display it all at once. In this case,
you need to "render" a subset of the image tiles. This will
require some geometry calculations, x and y bounds etc.
Then you would get each tile (Raster) and put it into a
BufferedImage, then draw it using the Graphics2D.

The easiest answer is to use one of the available frameworks
out there that will do all of this for you. I recommend
JadeDisplay:

http://www.openchannelsoftware.com/projects/JadeDisplay/

Good luck!

> -----Original Message-----
> From: jai-interest@javadesktop.org [mailto:jai-
> interest@javadesktop.org]
> Sent: Tuesday, June 08, 2010 9:22 AM
> To: interest@jai.dev.java.net
> Subject: Re: RE: [JAI] Re: waypoints in geotiff ?
>
> you are correct.
>
> I would appreciate if someone can point me in the right direction on :
> [b]- how to convert a coordinate (latitude, longitude) to a x,y
> location in a "geotiff".[/b]
>
> [b]- how to draw a point (or line, or polygon) over a "geotiff".[/b]
>
> (btw, the geotiff I'm using is quite big. I got it from "Google Earth
> Library" and the file is over 50 MB)
>
>
>
> >What form do you have your image in when it's loaded? Is it a
> RenderedImage?
>
> difficult question.
>
> below this text, I wrote the code I'm using:
> (the code is easier to read from here:
>
> http://java.sun.com/products/java-
> media/jai/forDevelopers/jai1_0_1guide-unc/Examples.doc.html
> )
>
> and the output I get in the console is: "TIFF image is type byte."
> ----------------------------------
>
>
> // The main method.
> public static void main(String[] args) {
> // Validate input.
> if (args.length != 1) {
> System.out.println("Usage: java LookupSampleProgram " +
> "TIFF_image_filename");
> System.exit(-1);
> }
> // Create an input stream from the specified file name to be
> // used with the TIFF decoder.
> FileSeekableStream stream = null;
> try {
> stream = new FileSeekableStream(args[0]);
> } catch (IOException e) {
> e.printStackTrace();
> System.exit(0);
> }
> // Store the input stream in a ParameterBlock to be sent to
> // the operation registry, and eventually to the TIFF
> // decoder.
> ParameterBlock params = new ParameterBlock();
> params.add(stream);
> // Specify to TIFF decoder to decode images as they are and
> // not to convert unsigned short images to byte images.
> TIFFDecodeParam decodeParam = new TIFFDecodeParam();
> decodeParam.setDecodePaletteAsShorts(true);
> // Create an operator to decode the TIFF file.
> RenderedOp image1 = JAI.create("tiff", params);
> // Find out the first image's data type.
> int dataType = image1.getSampleModel().getDataType();
> RenderedOp image2 = null;
> if (dataType == DataBuffer.TYPE_BYTE) {
> // Display the byte image as it is.
> System.out.println("TIFF image is type byte.");
> image2 = image1;
> } else if (dataType == DataBuffer.TYPE_USHORT) {
> // Convert the unsigned short image to byte image.
> System.out.println("TIFF image is type ushort.");
> // Setup a standard window-level lookup table. */
> byte[] tableData = new byte[0x10000];
> for (int i = 0; i < 0x10000; i++) {
> tableData[i] = (byte)(i >> 8);
> }
> // Create a LookupTableJAI object to be used with the
> // "lookup" operator.
> LookupTableJAI table = new LookupTableJAI(tableData);
> // Create an operator to lookup image1.
> image2 = JAI.create("lookup", image1, table);
> } else {
> System.out.println("TIFF image is type " + dataType +
> ", and will not be displayed.");
> System.exit(0);
> }
> // Get the width and height of image2.
> int width = image2.getWidth();
> int height = image2.getHeight();
> // Attach image2 to a scrolling panel to be displayed.
> ScrollingImagePanel panel = new ScrollingImagePanel(
> image2, width, height);
> // Create a frame to contain the panel.
> Frame window = new Frame("Lookup Sample Program");
> window.add(panel);
> window.pack();
> window.show();
> }
> }
>
> ----------------------
> [Message sent by forum member 'lancelot_234']
>
> http://forums.java.net/jive/thread.jspa?messageID=473326
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Bob Deen

> The easiest answer is to use one of the available frameworks
> out there that will do all of this for you. I recommend
> JadeDisplay:
>
> http://www.openchannelsoftware.com/projects/JadeDisplay/

It also has a facility to help you draw "overlays", which you can use to
plot your points. The initial intent of that capability was to draw
tiepoints over an image, which is a very similar concept.

-Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net