if (FALSE) {
GNsearch(q="Toronto Ontario", maxRows = 3)
}
library('terra')
myraster = rast(
matrix(1:100,10,10),
extent=ext(8,18,0,10), crs=crsLL)
options(geonamesUsername="myusernamehere")
if(file.exists("~/geonamesUsername.R")) source("~/geonamesUsername.R")
if(requireNamespace("geonames", quietly = TRUE)) {
cities=try(GNcities(myraster, max=5), silent=TRUE)
mytiles = openmap(myraster, zoom=5, buffer=1)
oldpar=map.new(mytiles)
plot(mytiles, add=TRUE)
if(!all(class(cities)=='try-error')) {
points(cities, col='red')
text(cities, labels=cities$name, col='red',pos=4)
}
par(oldpar)
}
Run the code above in your browser using DataLab