Hi,
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 get lon/lat as arguments and
return a number as an elevation.
I wrote a class to do that, but I think I have something wrong.
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)
*
* @see com.obteq.aster.reader.DemProvider#getElevation(double, double)
*/
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,
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users