使用 R 从网站提取澳大利亚纬度/经度点的高程 [英] Extracting elevation from website for lat/lon points in Australia, using R

查看:40
本文介绍了使用 R 从网站提取澳大利亚纬度/经度点的高程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

G'day 大家,

我正在尝试获取大约 700 个点的海拔数据.我想我可能会使用提供给同一个问题的代码(纬度转换/经度到海拔高度的 R),不幸的是我在使用 geonames 包时遇到错误,并且最佳答案提供的网站没有可用的澳大利亚海拔数据(错误提供如下仅供参考).

I am trying to get some elevation data for about 700 points I have. I thought I might use the code provided to the same question (Conversion for latitude/longitude to altitude in R), unfortunately I get errors when using the geonames package, and the website the best answer provides does not have Australian elevation data available (Errors provided below FYI).

我找到了另一个网站,该网站提供了非常准确的澳大利亚海拔数据,但我不知道如何从网页中提取信息.我认为它正在使用谷歌海拔 API,但我也不知道如何访问它.

I found another website which provides very accurate elevation data for Australia, but I have no idea how I might extract the information from the webpage . I think it is using the google elevation API, but again I have no idea how to access that.

当我将纬度、经度"坐标放入搜索位置"框中时,它会提供地图下方的高程数据.但是,我似乎无法在源页面中找到它.该网站是 http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm.

When I put 'lat, lon' coordinates into the 'search for location' box it gives the elevation data below the map. However, I can't seem to find this in the source page. The website is http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm.

一些有效的 lon lat 值示例:

some example lon lat values that work:

-36.0736, 146.9442

-36.0736, 146.9442

-36.0491, 146.4622

-36.0491, 146.4622

我想知道是否有人可以帮助我从 R 中查询此站点并提取高程数据?还是看起来很麻烦?我意识到网站上有一个批处理功能(最多 100 个位置),但是能够从 R 中执行此操作会很酷.

I am wondering if anyone can help me query this site from R, and extract the elevation data? Or does it seem like to much of a hassle? I realise there is a batch function (up to 100 locations) on the website, but it would be cool to be able to do this from R.

谢谢大家,对不起,如果这非常明显.

Thanks everyone, sorry if this is extremely obvious.

干杯,亚当

错误

使用地理名称时:

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'

使用查询代码时:

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

推荐答案

有一个 Elevation API 由 Google 提供,它返回 JSON 或 XML 响应.这是一个使用 JSON 响应的示例,由 RJSONIO 包中的 fromJSON 解析.

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  

googEl 函数需要一个 matrixdata.frame 坐标,第一列是经度,第二列是纬度.

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

这篇关于使用 R 从网站提取澳大利亚纬度/经度点的高程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆