# Convert DEM to GIF & keep Z values

I have a raster image ( DEM fromat from  US Geological survey).
This format has x,y, z(elevation data). If I want to display it in the Web,
I have to convert it to GIF/JPG formats. In doing so, I will loose the z's values
which I need
to use in my calculation in Java or whatever. Is there a way to convert the DEM
format to
GIF but still keep the all the z values. I see on solution is to save he z values in a
text
file but in this case java will take too much time to download it and interact with it
once it is loaded. I am looking for a solution. I am prepared to do whatever to find
a
solution to this problem. If you know, please let me know please. Thanks

Waleed
###### Who is Participating?

Commented:
waleed, if the DEM format is close to the DTM (digital terrine model) format, then the points are not covering the surface (its not point per pixel, just grid or non ordered points) than the only thing that you can do with it is simply generate contours or slope maps. There is no built in ability in java to do that (and its not a simple task, mathematically). If however the format is pixel oriented than I would suggest you to set a transformation height <-> color and thus to represent the height through color (like a green to brown scale) .  If its a pixel oriented I can show you how to make a conversion using gif libraries. If its not (my first option) I can give you directions to how to solve such a problem, but you are in for a lot of work.
Regards,
G.

0

Commented:
Have you tried compresing the contents into an archive file, specifically .JAR format
0

Author Commented:
yes its point per pixel. Every pixel has a value but a pixel with avalue of say 000 is a pixel
with no elevation (or unidentified). I know in java there is no built in class but you can write
slope algorithm ofcourse theat read the pixel value (z) and color the the one with high degree of slope. I have done so but the problem is:

Before converting the DEM to GIF, I have to save the z values in a text file (ASCII format)
After converting the image to GIF, I need to download the file every time the applet is loaded, and this will take too much time because the file is big
This supposed to be real-time processing. You see what I mean my friend.
Waleed
0

Commented:
Ok, you can do one of two things:
1. pack the file in a jar (to minimze communication) and read it over the net into the applet and perform conversion directly to the screen - without the use of gif/jpg formats.
2. perform and off line processing on the data and generate the gif/jpg outside the applet.
each of the approaches has pluses and minuses. The first is more up to date but slower. The second is faster but not up to date and requeirs a server side programming.
0

Author Commented:
My application require fast processing ! Maybe I go for the first approach.

I ) What is jar? Jar the data file that contain z's ? and can java read it?

2) What you mean by perform conversion directly to the screen-without using gif/jpg ?

I need to display the image(gif/jpg) in my applet. Just for displaying purposes
next the result of my calculation is coloring the image (GIF) pixels with some colors.

To explain, I want to do slope algorithms according to the z values. If the slope of the pixel
is (e.g 100 then the color is balck, 90 dark gray, 0 white),
0

Commented:
1. Well, jar is pretty must the same as zip (actually unzip would work for it). Java has a built in libraries to deal with jars/zips.
2. I think that for your needs, the conversion for gif and from gif to derivatives map (slopes) is a waste of time. So my suggession is read the data in, process it on the fly while reading (depending on your algorithem but you can hold just few image line at any given time, in order to find slopes. 3 to 7 I'd say) and put the pixels on the screen to a canvas component. No need to generate a gif out of it. You stated yourself that the gif is not needed. This will work faster.

0

Author Commented:
I like very much what you say. But loading a simple GIF image will take time ?
since sometimes we need to see the image before processing it (before performing the slope). Do you think displaying a GIF in java take considerable amount of time ? beside the calculation

Waleed
0

Author Commented:
Sorry I forgot this:

For jar/zip, java will process the file unzipped?  if that is the case . This is very good
Waleed
0

Author Commented:
Sorry I forgot this:

For jar/zip, java will process the file unzipped?  if that is the case . This is very good
Waleed
0

Commented:
No. Loading and displaying the gif is very short. BUT since you want to create it first - this action may take some time, since this action involves compressing of the image etc. You dont have to have gif or jpg in order to display raster info on the screen!
About the zip. The java is able to read from a file that is over the net and zipped. The file is unzipped on the fly, in the client side.
0

Author Commented:
I thank you very much. You have solved my problem

Waleed
0

Commented:
Ok. Let me know if you need pointers when you write your code.

Regards,
G.
0

Author Commented:
Can you do this now. I am afraid you forget.
0

Author Commented:
Can you do this now. I am afraid you forget.
0

Author Commented:
Can you do this now. I am afraid you forget.
0

Commented:
Ok. At first stage you can leave the zip/jar thing. You can always add it later.
1. First start by writing an applet that reads a file from the same directory where the applet is. Use the URL class (its openStream) and read the file.
2. try and break the file into tokens using StreamTokenizer.
3. Convert the strings to numbers using Integer class or Float or Double class.
4. Build an array of points (define class mypoint with 3 floats/int whatever you nned) from the data.

Tell me how that goes.

0

Author Commented:
thanks

Waleed
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.