api - Extracting elevation from website for lat/lon points in Australia, using R -
g'day everyone,
i trying elevation data 700 points have. thought might use code provided same question (conversion latitude/longitude altitude in r), unfortunately errors when using geonames package, , website best answer provides not have australian elevation data available (errors provided below fyi).
i found website provides accurate elevation data australia, have no idea how might extract information webpage . think using google elevation api, again have no idea how access that.
when put 'lat, lon' coordinates 'search location' box gives elevation data below map. however, can't seem find in source page. website http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm.
some example lon lat values work:
-36.0736, 146.9442
-36.0491, 146.4622
i wondering if can me query site r, , extract elevation data? or seem of hassle? realise there batch function (up 100 locations) on website, cool able r.
thanks everyone, sorry if extremely obvious.
cheers, adam
errors
when using geonames:
elevation <- gngtopo30(adult$lat, adult$lon) error in getjson("gtopo30json", list(lat = lat, lng = lng)) : error code 10 server: please add username each call in order geonames able identify calling application , count credits usage. in addition: warning message: in readlines(u) : incomplete final line found on 'http://ws.geonames.org/gtopo30json? lat=-36.0736&lng=146.9442'
when using query code:
library(rcurl) library(xml) url <- paste("http://earthtools.org/height", adult$lat, adult$lon, sep = '/') page <- geturl(url) ans <- xmltreeparse(page, useinternalnodes = true) space required after public identifier systemliteral " or ' expected system or public, uri missing content @ end of document error: 1: space required after public identifier 2: systemliteral " or ' expected 3: system or public, uri missing 4: content @ end of document
there's elevation api provided google, returns either json or xml response. here's example using json response, parsed fromjson
in 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 matrix
or data.frame
of coordinates, longitude in first column , latitude in second.
Comments
Post a Comment