Learn R Programming

mapmisc (version 2.1.0)

GNcities: Retrieve city names and locations

Description

This function uses the geonames package to provide city names and locations from www.geonames.org.

Usage

GNcities(north, east, south, west, lang = "en", maxRows = 10, buffer=0)
	GNsearch(..., crs=crsLL)

Value

A SpatialPointsDataFrame with the sampe projection north if it exists, otherwise in long-lat.

Arguments

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 text

maxRows

Limit on returned rows

buffer

passed to extend

...

Various search arguments

crs

projection for the output

See Also

GNcities, GNsearch

Examples

Run this code

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