R中纬度/经度到海拔的转换

时间:2021-09-16 16:03:18

Does anyone know if there is a tool in R to find the height above sea level of a location, given the latitude and longitude ?

根据纬度和经度,有没有人知道在R中是否有工具可以找到某个位置海拔高度?

4 个解决方案

#1


12  

Or you can use the package that looks up from geonames, and get the value from the srtm3 digital elevation model:

或者您可以使用从地理名称中查找的包,并从srtm3数字高程模型中获取值:

> require(geonames)
> GNsrtm3(54.481084,-3.220625)
  srtm3       lng      lat
1   797 -3.220625 54.48108

or the gtopo30 model:

或者gtopo30型号:

> GNgtopo30(54.481084,-3.220625)
  gtopo30       lng      lat
1     520 -3.220625 54.48108

geonames is on CRAN so install.packages("geonames") will get it.

geonames在CRAN上,所以install.packages(“geonames”)将获得它。

The difference between these two models is because they are only approximations based on satellite data. Don't go expecting to pinpoint mountains from this.

这两种模型之间的区别在于它们只是基于卫星数据的近似值。不要指望从这里找到山脉。

#2


11  

Update: Earthtools no longer exists, so this answer is obsolete. I recommend @Spacedman's answer instead.

更新:Earthtools不再存在,所以这个答案已经过时了。我推荐@Spacedman的回答。

As DWin said, there are two parts to this: find a good source of data with a web service, then parse it in R. This answer uses the earthtools.org service.

正如DWin所说,这有两个部分:用Web服务找到一个好的数据源,然后在R中解析它。这个答案使用earthtools.org服务。

library(RCurl)
library(XML)

latitude <- 52.4822
longitude <- -1.8946
url <- paste(
    "http://www.earthtools.org/height",
    latitude, 
    longitude,
    sep = "/"
)

page <- getURL(url)
ans <- xmlTreeParse(page, useInternalNodes = TRUE)
heightNode <- xpathApply(ans, "//meters")[[1]]
(height <- as.numeric(xmlValue(heightNode)))

#3


1  

There are R packages such as RCurl that allow web queries. There are also web resources, Further specfics will require .... well, ... more specifics.

有RC包,如RCurl,允许Web查询。还有网络资源,进一步的specfics将需要....好吧,...更具体。

http://gisdata.usgs.net/xmlwebservices2/elevation_service.asmx?op=getElevation

http://gisdata.usgs.net/xmlwebservices2/elevation_service.asmx?op=getElevation

#4


1  

You can access elevation data through Google Maps Elevation API. And in R you can use this through my googleway package

您可以通过Google Maps Elevation API访问高程数据。在R中你可以通过我的googleway包使用它

To use Google Maps API you need an API key

要使用Google Maps API,您需要一个API密钥

library(googleway)

api_key <- "your_api_key"

df_locations <- data.frame(lat = c(54.481084), lon = c(-3.220625))

google_elevation(df_locations = df_locations, key = api_key)

# $results
# elevation location.lat location.lng resolution
# 1  813.9291     54.48108    -3.220625   610.8129
# 
# $status
# [1] "OK"

#1


12  

Or you can use the package that looks up from geonames, and get the value from the srtm3 digital elevation model:

或者您可以使用从地理名称中查找的包,并从srtm3数字高程模型中获取值:

> require(geonames)
> GNsrtm3(54.481084,-3.220625)
  srtm3       lng      lat
1   797 -3.220625 54.48108

or the gtopo30 model:

或者gtopo30型号:

> GNgtopo30(54.481084,-3.220625)
  gtopo30       lng      lat
1     520 -3.220625 54.48108

geonames is on CRAN so install.packages("geonames") will get it.

geonames在CRAN上,所以install.packages(“geonames”)将获得它。

The difference between these two models is because they are only approximations based on satellite data. Don't go expecting to pinpoint mountains from this.

这两种模型之间的区别在于它们只是基于卫星数据的近似值。不要指望从这里找到山脉。

#2


11  

Update: Earthtools no longer exists, so this answer is obsolete. I recommend @Spacedman's answer instead.

更新:Earthtools不再存在,所以这个答案已经过时了。我推荐@Spacedman的回答。

As DWin said, there are two parts to this: find a good source of data with a web service, then parse it in R. This answer uses the earthtools.org service.

正如DWin所说,这有两个部分:用Web服务找到一个好的数据源,然后在R中解析它。这个答案使用earthtools.org服务。

library(RCurl)
library(XML)

latitude <- 52.4822
longitude <- -1.8946
url <- paste(
    "http://www.earthtools.org/height",
    latitude, 
    longitude,
    sep = "/"
)

page <- getURL(url)
ans <- xmlTreeParse(page, useInternalNodes = TRUE)
heightNode <- xpathApply(ans, "//meters")[[1]]
(height <- as.numeric(xmlValue(heightNode)))

#3


1  

There are R packages such as RCurl that allow web queries. There are also web resources, Further specfics will require .... well, ... more specifics.

有RC包,如RCurl,允许Web查询。还有网络资源,进一步的specfics将需要....好吧,...更具体。

http://gisdata.usgs.net/xmlwebservices2/elevation_service.asmx?op=getElevation

http://gisdata.usgs.net/xmlwebservices2/elevation_service.asmx?op=getElevation

#4


1  

You can access elevation data through Google Maps Elevation API. And in R you can use this through my googleway package

您可以通过Google Maps Elevation API访问高程数据。在R中你可以通过我的googleway包使用它

To use Google Maps API you need an API key

要使用Google Maps API,您需要一个API密钥

library(googleway)

api_key <- "your_api_key"

df_locations <- data.frame(lat = c(54.481084), lon = c(-3.220625))

google_elevation(df_locations = df_locations, key = api_key)

# $results
# elevation location.lat location.lng resolution
# 1  813.9291     54.48108    -3.220625   610.8129
# 
# $status
# [1] "OK"