Retrieving website height for lat / lon points in Australia using R

G'day everyone

I am trying to get some altitude data about 700 points that I have. I thought I could use the code provided on the same question ( Conversion for latitude / longitude in height to R ), unfortunately, I get errors when using the geonames package, and the website for which the best answer is provided does not contain Australian height data (errors are indicated below FYI).

I found another website that provides very accurate altitude data for Australia, but I have no idea how I can extract information from the webpage. I think it uses google heights API, but again I have no idea how to access this.

When I put the coordinates "lat, lon" in the "location search" field, it gives the height data below the map. However, I cannot find this on the original page. Website http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm .

some examples of lon lat that work:

-36.0736, 146.9442

-36.0491, 146.4622

I am wondering if someone can help me fetch this site from R and extract height data? Or does this seem like most of the hassle? I understand that the website has a batch function (up to 100 locations), but it would be great to do this with R.

Thanks everyone, sorry if this is very 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 from server: Please add a username to each call in order for geonames to    be able to identify the calling application and count the 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 a request 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 the Public Identifier
SystemLiteral " or ' expected
SYSTEM or PUBLIC, the URI is missing
Extra content at the end of the document
Error: 1: Space required after the Public Identifier
2: SystemLiteral " or ' expected
3: SYSTEM or PUBLIC, the URI is missing
4: Extra content at the end of the document
+4
3

API , Google, JSON XML. JSON, fromJSON RJSONIO.

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  

googEl matrix data.frame .

+7

raster ?getData SRTM.

:

library(raster)
m <- data.frame(lon = c(146.9442, 146.4622), lat = c(-36.0736, -36.0491))

x <- getData('alt', country = "AUS")

cbind(m, alt = extract(x, m))
       lon      lat alt
1 146.9442 -36.0736 164
2 146.4622 -36.0491 172

, :

cbind(m, alt = extract(x, m, method = "bilinear"))
       lon      lat      alt
1 146.9442 -36.0736 164.9519
2 146.4622 -36.0491 172.1293

, , .

RasterLayer, plot ..:

plot(x)
points(m)
x
class       : RasterLayer 
dimensions  : 5496, 5568, 30601728  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : 112.8, 159.2, -54.9, -9.1  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 
data source : C:\temp\AUS_msk_alt.grd 
names       : AUS_msk_alt 
values      : -43, 2143  (min, max)

enter image description here

+4

googleway, @jbaums. google_elevation()

library(googleway)

## you need an API key
key <- "your_api_key"

## data:
df <- data.frame(lat = c(-36.0736, -36.0491),
                 lon = c(146.9442, 146.4622))

google_elevation(df_locations = df, 
                 location_type = "individual",
                 key = key)

# $results
# elevation location.lat location.lng resolution
# 1  163.0000     -36.0736     146.9442   152.7032
# 2  171.7301     -36.0491     146.4622   152.7032

, , .

key <- "your_api_key"

google_map(data = df, key = key) %>%
    add_markers()

enter image description here

+2
source

Source: https://habr.com/ru/post/1525542/


All Articles