I am trying to extract altitude data for a given set of lats and longs in my data. I tried to look up some older answers (from 9-10 years ago)..but many of the methods are obsolete or the functions don’t work. Any fresh suggestions?
lat <- c(45.08323,40.08323)
long <- c(-82.46797,-81.46797)
df <- data.frame(lat, long)
I have tried the following suggestions:
I run into errors that say: Error in url(url, open = "r") : cannot open the connection to 'http://api.geonames.org/srtm3JSON?lat=NA&lng=NA&
- I tried using the googleway and elevatr pacakages as suggested in the linked answers
The elevatr package would not download for the latest R > 4.0 version.
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.
When I try installing the required package:
"package ‘libudunits2’ is not available for this version of R"
###EDIT: What worked?
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)
2
Answers
Need to create a username and enable webservice on https://www.geonames.org/manageaccount
This manages to get the second point, but not the first.