
- Reading-ASTER-DEM-Data
- 09-28-2009
If you were Registered and logged in, you could reply and use other advanced thread options
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
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,
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
>
> How can I read ASTER DEM data set.
>
>
> 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,
> 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,
- Aster satellite images to research minerals in SE US
- Geographic Information Systems (GIS)
- 2007-07-10
- TomTom selling data to police!
- UK GPS Discussions
- 2011-05-07
- cell phone sat data
- Satellite Navigation
- 2011-10-09
- NMEA data format
- Global Positioning System
- 2011-07-25
- Question About Garmin "Hot Fix Data"
- Garmin GPS
- 2010-08-05



ConcurrentHashMap<String, RandomIter>();