Bookmark this page: Add Reading ASTER DEM Data to Yahoo MyWeb Add Reading ASTER DEM Data to Google Bookmarks Add Reading ASTER DEM Data to Windows Live Add Reading ASTER DEM Data to Del.icio.us Digg Reading ASTER DEM Data! Add Reading ASTER DEM Data to Netscape
  •  
  • Subject
  • Author
  • Date
If you were  Registered and logged in, you could reply and use other advanced thread options
Posted by Ahmad on September 28, 2009, 5:04 pm


Hi,

How can I read ASTER DEM data set.
http://en.wikipedia.org/wiki/Advanced_Spaceborne_Thermal_Emission_and_Reflection_Radiometer

I have folder that contains tiles of ASTER in tif format, and I want
to write a function that take lon/lat as arguments and return a number
as an elevation.

I wrote a class in Java to do that, but I think I have something
wrong. The readings seems not to be correct!

import java.util.concurrent.ConcurrentHashMap;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.iterator.RandomIter;
import javax.media.jai.iterator.RandomIterFactory;

public class AsterDemReader implements DemProvider {

// base path for the tiles
private String basePath;

// tiles RAM cache
private ConcurrentHashMap<String, RandomIter> cache = new
ConcurrentHashMap<String, RandomIter>();

public AsterDemReader(String basePath) {
this.basePath = basePath;
}

private RandomIter getTile(String tileName) {
RandomIter iter = cache.get(tileName);
if (iter == null) {
PlanarImage image = JAI.create("fileload", String.format(
"%s/ASTGTM_%s_dem.tif", basePath, tileName));
iter = RandomIterFactory.create(image, null);
cache.put(tileName, iter);
}
return iter;
}

// lat and lon in decimal degrees
/*
* (non-Javadoc)
*
*
*/
public double getElevation(double lat, double lon) throws
Exception {

lat -= .0001389;
lon -= .0001389;

// file name
int latDegree = (int) Math.abs(lat);
int lonDegree = (int) Math.abs(lon);

char northSouth = (lat < 0) ? 'E' : 'N';
char eastWest = (lon < 0) ? 'W' : 'E';

String tileName = String.format("%c%2d%c%3d", northSouth,
latDegree,
eastWest, lonDegree).replace(" ", "0");
// the frection only
lat -= (int) lat;
lon -= (int) lon;

lat = Math.abs(lat);
lon = Math.abs(lon);

// calculate x and y of the image
int y = 3600 - (int) (3600 * lat);
int x = (int) (3600 * lon);
// System.out.println(String.format("x=%d y=%d", x, y));

// get the image from cache

RandomIter iter = getTile(tileName);
double av = iter.getSampleDouble(x, y, 0);

return av;
}

public static void main(String args[]) throws Exception {
DemProvider aster = new AsterDemReader("D:/OldHP");
double elev = aster.getElevation(33.5, 42.5);

System.out.println(elev);
}
}

Could anyone please point me where I'm getting wrong? where can I find
more info about reading ASTER DEM?

Best Regards,

Posted by jeanh on September 28, 2009, 5:50 pm


Ahmad,

you are not providing enough information about your data and your GIS.

From your code, I would focus on how you compute the X;Y coordinates.
You are not considering any projection nor any resolution and you assume
that the north is straight up. I suggest you to search the available
libraries for doing such conversion.

Jean

Ahmad wrote:
> Hi,
>
> How can I read ASTER DEM data set.
>
http://en.wikipedia.org/wiki/Advanced_Spaceborne_Thermal_Emission_and_Reflection_Radiometer
>
> I have folder that contains tiles of ASTER in tif format, and I want
> to write a function that take lon/lat as arguments and return a number
> as an elevation.
>
> I wrote a class in Java to do that, but I think I have something
> wrong. The readings seems not to be correct!
>
> import java.util.concurrent.ConcurrentHashMap;
>
> import javax.media.jai.JAI;
> import javax.media.jai.PlanarImage;
> import javax.media.jai.iterator.RandomIter;
> import javax.media.jai.iterator.RandomIterFactory;
>
> public class AsterDemReader implements DemProvider {
>
> // base path for the tiles
> private String basePath;
>
> // tiles RAM cache
> private ConcurrentHashMap<String, RandomIter> cache = new
> ConcurrentHashMap<String, RandomIter>();
>
> public AsterDemReader(String basePath) {
> this.basePath = basePath;
> }
>
> private RandomIter getTile(String tileName) {
> RandomIter iter = cache.get(tileName);
> if (iter == null) {
> PlanarImage image = JAI.create("fileload", String.format(
> "%s/ASTGTM_%s_dem.tif", basePath, tileName));
> iter = RandomIterFactory.create(image, null);
> cache.put(tileName, iter);
> }
> return iter;
> }
>
> // lat and lon in decimal degrees
> /*
> * (non-Javadoc)
> *
> *
> */
> public double getElevation(double lat, double lon) throws
> Exception {
>
> lat -= .0001389;
> lon -= .0001389;
>
> // file name
> int latDegree = (int) Math.abs(lat);
> int lonDegree = (int) Math.abs(lon);
>
> char northSouth = (lat < 0) ? 'E' : 'N';
> char eastWest = (lon < 0) ? 'W' : 'E';
>
> String tileName = String.format("%c%2d%c%3d", northSouth,
> latDegree,
> eastWest, lonDegree).replace(" ", "0");
> // the frection only
> lat -= (int) lat;
> lon -= (int) lon;
>
> lat = Math.abs(lat);
> lon = Math.abs(lon);
>
> // calculate x and y of the image
> int y = 3600 - (int) (3600 * lat);
> int x = (int) (3600 * lon);
> // System.out.println(String.format("x=%d y=%d", x, y));
>
> // get the image from cache
>
> RandomIter iter = getTile(tileName);
> double av = iter.getSampleDouble(x, y, 0);
>
> return av;
> }
>
> public static void main(String args[]) throws Exception {
> DemProvider aster = new AsterDemReader("D:/OldHP");
> double elev = aster.getElevation(33.5, 42.5);
>
> System.out.println(elev);
> }
> }
>
> Could anyone please point me where I'm getting wrong? where can I find
> more info about reading ASTER DEM?
>
> Best Regards,