Conversion for latitude/longitude to altitude in R

前端 未结 4 1083
野趣味
野趣味 2021-02-06 02:44

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 ?

4条回答
  •  离开以前
    2021-02-06 03:36

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

    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.

    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)))
    

提交回复
热议问题