Learn R Programming

mapmisc (version 1.1.1)

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)
	GNsearch(...)

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
...
Various search arguments

Value

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

See Also

GNcities, GNsearch

Examples

Run this code
myraster = raster(matrix(0,10,10),xmn=8,xmx=18,ymn=0,ymx=10, 
	crs="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
values(myraster) = seq(0,1,len=ncell(myraster))
myPoints = SpatialPoints(myraster, proj4string=CRS(proj4string(myraster)))[
	seq(1,ncell(myraster),len=5)]

if (requireNamespace("geonames", quietly = TRUE)) { 
cities=GNcities(myPoints, max=5)
mytiles = openmap(myraster)

map.new(cities)
plot(mytiles, add=TRUE)
points(cities, col='red')
text(cities, labels=cities$name, col='red',pos=4)


cities=GNcities(myraster, max=5)

map.new(cities)
plot(mytiles, add=TRUE)
points(cities, col='red')
text(cities, labels=cities$name, col='red',pos=4)

GNsearch(q="Toronto Ontario")
}

Run the code above in your browser using DataLab