How to Look Up Elevation Data by Lat/Lng

How to look up elevation data by lat/lng

I'll give you one of the best "secrets" that I learned throughout the years after going through many different pains (leeching scripts, manual clicking, etc). It is an old-school trick... contact a real person there!

The best way do get the NED elevation dataset is to contact USGS's Eros group directly at bulkdatainfo_at_usgs.gov

You send them an external drive and after 4 to 8 weeks (usually much less than that) they will send you the entire dataset that you requested.

Then use GDAL to query your points in a way similar to this example. You may want to read the Affine Geotransform section of the GDAL Data Model

Extracting elevation from website for lat/lon points in Australia, using R

There's an Elevation API provided by Google, which returns either a JSON or XML response. Here's an example using a JSON response, parsed by fromJSON in the RJSONIO package.

googEl <- function(locs)  {
require(RJSONIO)
locstring <- paste(do.call(paste, list(locs[, 2], locs[, 1], sep=',')),
collapse='|')
u <- sprintf('http://maps.googleapis.com/maps/api/elevation/json?locations=%s&sensor=false',
locstring)
res <- fromJSON(u)
out <- t(sapply(res[[1]], function(x) {
c(x[['location']]['lat'], x[['location']]['lng'],
x['elevation'], x['resolution'])
}))
rownames(out) <- rownames(locs)
return(out)
}

m <- matrix(c(146.9442, 146.4622, -36.0736, -36.0491), nc=2)

googEl(m)

lat lng elevation resolution
[1,] -36.0736 146.9442 163 152.7032
[2,] -36.0491 146.4622 171.7301 152.7032

The googEl function expects a matrix or data.frame of coordinates, with longitude in the first column and latitude in the second.

How to extract altitude above sea level given latitude and longitude?

This manages to get the second point, but not the first.

library(elevatr)
library(rgdal)
lat <- c(45.08323,40.08323)
long <- c(-82.46797,-81.46797)
df <- data.frame(long, lat)
get_elev_point(df, prj="EPSG:4326")
# Note: Elevation units are in &units=Meters
# Note:. The coordinate reference system is:
# GEOGCRS["WGS 84 (with axis order normalized for visualization)",
# DATUM["World Geodetic System 1984",
# ELLIPSOID["WGS 84",6378137,298.257223563,
# LENGTHUNIT["metre",1]]],
# PRIMEM["Greenwich",0,
# ANGLEUNIT["degree",0.0174532925199433]],
# CS[ellipsoidal,2],
# AXIS["geodetic longitude (Lon)",east,
# ORDER[1],
# ANGLEUNIT["degree",0.0174532925199433,
# ID["EPSG",9122]]],
# AXIS["geodetic latitude (Lat)",north,
# ORDER[2],
# ANGLEUNIT["degree",0.0174532925199433,
# ID["EPSG",9122]]]]
# coordinates elevation elev_units
# 1 (-82.46797, 45.08323) NA meters
# 2 (-81.46797, 40.08323) 271.82 meters

Altitude of a place given Latitude and longitude?

http://code.google.com/apis/maps/documentation/elevation/

Python: Obtaining elevation from latitude and longitude values

I've been using the api from opentopodata.org to obtain elevation values.
You could use the EU-DEM dataset which covers entire sweden. An API request is as simple as the following:

https://api.opentopodata.org/v1/eudem25m?locations=57.728905,11.949309

Another elevation API can be found at https://open-elevation.com/. A request looks very similar:

https://api.open-elevation.com/api/v1/lookup?locations=57.728905,11.949309

therefore adapting your elevation_function:

def elevation_function(x):
url = 'https://api.opentopodata.org/v1/eudem25m?'
# url = 'https://api.open-elevation.com/api/v1/lookup?'
params = {'locations': f"{x[0]},{x[1]}"}
result = make_remote_request(url, params)
return result.json()['results'][0]['elevation']

Get altitude by longitude and latitude in Android

My approach is to use USGS Elevation Query Web Service:

private double getAltitude(Double longitude, Double latitude) {
double result = Double.NaN;
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
String url = "http://gisdata.usgs.gov/"
+ "xmlwebservices2/elevation_service.asmx/"
+ "getElevation?X_Value=" + String.valueOf(longitude)
+ "&Y_Value=" + String.valueOf(latitude)
+ "&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=true";
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = httpClient.execute(httpGet, localContext);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
int r = -1;
StringBuffer respStr = new StringBuffer();
while ((r = instream.read()) != -1)
respStr.append((char) r);
String tagOpen = "<double>";
String tagClose = "</double>";
if (respStr.indexOf(tagOpen) != -1) {
int start = respStr.indexOf(tagOpen) + tagOpen.length();
int end = respStr.indexOf(tagClose);
String value = respStr.substring(start, end);
result = Double.parseDouble(value);
}
instream.close();
}
} catch (ClientProtocolException e) {}
catch (IOException e) {}
return result;
}

And example of use (right in HelloMapView class):

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mZoom = (ZoomControls) mapView.getZoomControls();
linearLayout.addView(mZoom);
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == 1) {
final GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(), (int) event.getY());
final StringBuilder msg = new StringBuilder();
new Thread(new Runnable() {
public void run() {
final double lon = p.getLongitudeE6() / 1E6;
final double lat = p.getLatitudeE6() / 1E6;
final double alt = getAltitude(lon, lat);
msg.append("Lon: ");
msg.append(lon);
msg.append(" Lat: ");
msg.append(lat);
msg.append(" Alt: ");
msg.append(alt);
}
}).run();
Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT)
.show();
}
return false;
}
});
}


Related Topics



Leave a reply



Submit