【问题标题】:How to extract altitude above sea level given latitude and longitude?如何在给定纬度和经度的情况下提取海拔高度?
【发布时间】:2021-09-15 08:23:37
【问题描述】:

我正在尝试为我的数据中给定的一组纬度和经度提取海拔数据。我试图查找一些较旧的答案(从 9 到 10 年前)..但是许多方法已经过时或功能不起作用。有什么新鲜的建议吗?

lat <- c(45.08323,40.08323)
long <- c(-82.46797,-81.46797)
df <- data.frame(lat, long)

我尝试了以下建议:

  1. Using the geonames package, and get the value from the srtm3 digital elevation model

我遇到如下错误:Error in url(url, open = "r") : cannot open the connection to 'http://api.geonames.org/srtm3JSON?lat=NA&amp;lng=NA&amp;

  1. 我尝试按照链接答案中的建议使用 googlewayelevatr pacakages

对于最新的 R > 4.0 版本,不会下载 elevatr 包。

I get an error that says   Configuration failed because libudunits2.so was not found. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: udunits2-devel (Fedora, EPEL, ...)
    * brew: udunits (OSX)
  If udunits2 is already installed in a non-standard location, use:
    --configure-args='--with-udunits2-lib=/usr/local/lib'
  if the library was not found, and/or:
    --configure-args='--with-udunits2-include=/usr/include/udunits2'
  if the header was not found, replacing paths with appropriate values.
  You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually. 

当我尝试安装所需的包时:

“包‘libudunits2’不适用于这个版本的R”

###EDIT:什么有效?

library(geonames)
readLines(url("http://api.geonames.org/",open="r"))
options(geonamesUsername= "MyUsername") #Note you have to create a username one the website AND enable webservices on your geonames user account at https://www.geonames.org/manageaccount. 

GNsrtm3(54.481084,-3.220625)

【问题讨论】:

  • @user20650 都没有用。对于第一个,它一直说连接错误,第二个在最新的 R 版本中无法加载包
  • 好的。如果您添加了所有您尝试过但对您的问题不起作用的东西,以节省您在建议上浪费时间,这可能会有所帮助
  • 第二个错误是因为你需要系统库。所以试试apt install libudunits2-dev(来自sudo)——或者任何相关的——然后尝试重新安装
  • libudunits2 是一个 system 包,而不是 R 包。 Linux (deb, rpm) 或 MacOS (brew) 的错误消息中给出了安装说明

标签: r google-maps latitude-longitude google-latitude google-elevation-api


【解决方案1】:

这设法得到第二点,但不是第一点。

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

【讨论】:

  • 使用 GNsrtm3 结果是 175 & 277
【解决方案2】:

需要在https://www.geonames.org/manageaccount上创建用户名并启用webservice

    library(geonames)
    readLines(url("http://api.geonames.org/",open="r"))
    options(geonamesUsername= "MyUsername") #Note you have to create a username one the website AND enable webservices on your geonames user account at https://www.geonames.org/manageaccount. 
    
    GNsrtm3(54.481084,-3.220625)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 2014-10-26
    • 2016-01-11
    • 1970-01-01
    相关资源
    最近更新 更多