Retrieve city names and locations
This function uses the geonames package to provide city names and locations from www.geonames.org.
GNcities(north, east, south, west, lang = "en", maxRows = 10, buffer=0) GNsearch(..., crs=crsLL)
north
: A bounding box or SpatialPoints or SpatialPolygons or Extent or Raster object, or a decimal degree of longitude.east,south,west
: If north
is numeric, decimal degree bounding box.lang
: Language for internationalised returned textmaxRows
: Limit on returned rowsbuffer
: passed to extend
...
: Various search argumentscrs
: projection for the outputGNcities
, GNsearch
A SpatialPointsDataFrame with the sampe projection north
if it exists, otherwise in long-lat.
## Not run: GNsearch(q="Toronto Ontario", maxRows = 3) ## End(Not run) 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) }
Useful links