Package 'OpenStreetMap'

Title: Access to Open Street Map Raster Images
Description: Accesses high resolution raster maps using the OpenStreetMap protocol. Dozens of road, satellite, and topographic map servers are directly supported, including Apple, Mapnik, Bing, and stamen. Additionally raster maps may be constructed using custom tile servers. Maps can be plotted using either base graphics, or ggplot2. This package is not affiliated with the OpenStreetMap.org mapping project.
Authors: Ian Fellows, using the JMapViewer library by Jan Peter Stotz
Maintainer: Ian Fellows <[email protected]>
License: GPL-2 | file LICENCE
Version: 0.4.0
Built: 2024-10-06 06:42:18 UTC
Source: CRAN

Help Index


Create a complete ggplot appropriate to a particular data type Rexported from ggplot2. 'autoplot()' uses ggplot2 to draw a particular plot for an object of a particular class in a single command. This defines the S3 generic that other classes and packages can extend.

Description

Create a complete ggplot appropriate to a particular data type Rexported from ggplot2. 'autoplot()' uses ggplot2 to draw a particular plot for an object of a particular class in a single command. This defines the S3 generic that other classes and packages can extend.

Arguments

object

An object (for example an OpenStreetMap object)

...

Additional arguments

Value

a ggplot object

See Also

[autoplot.OpenStreetMap()]


Plot an open street map using ggplot2

Description

Plot an open street map using ggplot2

Usage

## S3 method for class 'OpenStreetMap'
autoplot(object, expand = TRUE, ...)

Arguments

object

an OpenStreetMap object

expand

if true the plotting bounds are expanded to the bounding box

...

not used

Examples

## Not run: 
require(maps)
require(ggplot2)

mp <- openmap(c(53.38332836757155,-130.517578125),
		c(15.792253570362446,-67.939453125),4)
mp_bing <- openmap(c(53.38332836757155,-130.517578125),
		c(15.792253570362446,-67.939453125),4,'bing')
states_map <- map_data("state")
states_map_merc <- as.data.frame(
		projectMercator(states_map$lat,states_map$long))
states_map_merc$region <- states_map$region
states_map_merc$group <- states_map$group
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)

p <- autoplot(mp,expand=FALSE) + geom_polygon(aes(x=x,y=y,group=group),
		data=states_map_merc,fill="black",colour="black",alpha=.1) + theme_bw()
print(p)
p <- autoplot(mp_bing) + geom_map(aes(x=-10000000,y=4000000,map_id=state,fill=Murder),
		data=crimes,map=states_map_merc)
print(p)

## End(Not run)

Plots an open street map tile using ggplot2

Description

Plots an open street map tile using ggplot2

Usage

## S3 method for class 'osmtile'
autoplot(object, plot = FALSE, ...)

Arguments

object

an osmtile

plot

if false only the annotation_raster is returned

...

not used


Returns a table with relevant source and attribution info for each map type

Description

Returns a table with relevant source and attribution info for each map type

Usage

getMapInfo()

Places of interest in Los Angeles

Description

Places of interest in Los Angeles


Launches a Java helper GUI.

Description

Launches a Java helper GUI.

Usage

launchMapHelper()

Details

note for Mac OS X users: On the mac this can only be run from a java console such as JGR.


Latitude Longitude projection

Description

Latitude Longitude projection

Usage

longlat()

Get a map based on lat long coordinates

Description

Get a map based on lat long coordinates

Usage

openmap(
  upperLeft,
  lowerRight,
  zoom = NULL,
  type = c("osm", "bing", "osm-german", "esri", "esri-topo", "esri-physical",
    "esri-shaded", "esri-imagery", "esri-terrain", "esri-natgeo", "nps", "apple-iphoto",
    "osm-public-transport"),
  minNumTiles = 9L,
  mergeTiles = TRUE
)

Arguments

upperLeft

the upper left lat and long

lowerRight

the lower right lat and long

zoom

the zoom level. If null, it is determined automatically

type

the tile server from which to get the map, or the url pattern.

minNumTiles

If zoom is null, zoom will be chosen such that the number of map tiles is greater than or equal to this number.

mergeTiles

should map tiles be merged into one tile

Details

Type may be the url of a custom tile server (http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification). should include {z}, {y}, and {x} specifying where the zoom, xtile and ytile location should be substituted. e.g.

http://api.someplace.com/.../{z}/{x}/{y}.png

Examples

## Not run: 
#show some of the maps available
nm <- c("osm","bing","osm-german","esri","esri-topo","esri-physical","esri-shaded",
  "esri-imagery","esri-terrain","esri-natgeo","nps","apple-iphoto")
par(mfrow=c(3,4), mar=c(0,0,0,0))
#Korea
for(i in 1:length(nm)){
	map <- openmap(c(43.46886761482925,119.94873046875),
			c(33.22949814144951,133.9892578125),
		minNumTiles=3,type=nm[i])
plot(map)
}
# Some maps from custom urls (use your own API key)
apiKey <- paste0("?access_token=",
 "pk.eyJ1IjoidGhlZmVsbCIsImEiOiJjaXN1anNwODEwMWlrMnRvZHBhamRrZjlqIn0.Gf8qLSpZ6yo5yfQhEutFfQ")
baseUrl <- "https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v9/tiles/256/{z}/{x}/{y}"
map <- openmap(c(43.46886761482925,119.94873046875),
	c(33.22949814144951,133.9892578125),
		minNumTiles=4,
		type=paste0(baseUrl,apiKey))
plot(map)

baseUrl <- "https://api.mapbox.com/styles/v1/mapbox/dark-v9/tiles/256/{z}/{x}/{y}"
map <- openmap(c(43.46886761482925,119.94873046875),
	c(33.22949814144951,133.9892578125),
		minNumTiles=4,
		type=paste0(baseUrl,apiKey))
plot(map)


#plot Korea with ggplot2.
library(ggplot2)
map <- openmap(c(43.46886761482925,119.94873046875),
	c(33.22949814144951,133.9892578125),
	minNumTiles=4)
autoplot(map)


## End(Not run)

Projects the open street map to an alternate coordinate system

Description

Projects the open street map to an alternate coordinate system

Usage

openproj(x, projection = "+proj=longlat", ...)

Arguments

x

an OpenStreetMap object

projection

a proj4 character string or CRS object

...

additional parameters for projectRaster

Examples

## Not run: 
library(maps)

#plot bing map in native mercator coords
map <- openmap(c(70,-179),
	c(-70,179),zoom=1,type='bing')
plot(map)

#using longlat projection lets us combine with the maps library
map_longlat <- openproj(map)
plot(map_longlat)
map("world",col="red",add=TRUE)

#robinson projection. good for whole globe viewing.
map_robinson <- openproj(map_longlat, projection=
"+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
plot(map_robinson)

#national parks service images
upperMap <- openmap(c(70,-179),
	c(10,50),zoom=2,type='nps')
#Lambert Conic Conformal
map_llc <- openproj(upperMap, projection=
"+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96")
plot(map_llc,removeMargin=TRUE)
#add choropleth
library(sp)
data(states)
st_llc <- spTransform(states,CRS("+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96"))
plot(st_llc,add=T,col=heat.colors(48,.4)[slot(st_llc,"data")[["ORDER_ADM"]]])


## End(Not run)

Open street map (and google) mercator projection

Description

Open street map (and google) mercator projection

Usage

osm()

Get an open street map tile.

Description

Get an open street map tile.

Usage

osmtile(x, y, zoom, type = "osm")

Arguments

x

location in osm native coordinates

y

location in osm native coordinates

zoom

zoom level

type

the map type (see getMapInfo)

Value

a tile


Plot an OpenStreetMap object.

Description

Plot an OpenStreetMap object.

Usage

## S3 method for class 'OpenStreetMap'
plot(x, y = NULL, add = FALSE, removeMargin = TRUE, ...)

Arguments

x

the OpenStreetMap

y

ignored

add

add to current plot

removeMargin

remove margins from plotting device

...

additional parameters to be passed to plot


Add tile to plot

Description

Add tile to plot

Usage

## S3 method for class 'osmtile'
plot(x, y = NULL, add = TRUE, raster = TRUE, ...)

Arguments

x

the tile

y

ignored

add

add to current plot (if raster, then image is always added)

raster

use raster image

...

additional parameters to image or rasterImage


Print map

Description

Print map

Usage

## S3 method for class 'OpenStreetMap'
print(x, ...)

Arguments

x

the OpenStreetMap

...

ignored


Maps long lat values to the open street map mercator projection

Description

Maps long lat values to the open street map mercator projection

Usage

projectMercator(lat, long, drop = TRUE)

Arguments

lat

a vector of latitudes

long

a vector of longitudes

drop

drop to lowest dimension


Create a RasterLayer from an OpenStreetMap

Description

Create a RasterLayer from an OpenStreetMap

Usage

## S4 method for signature 'OpenStreetMap'
raster(x, ...)

Arguments

x

an OpenStreetMap

...

unused

Examples

## Not run: 
library(raster)
longBeachHarbor <- openmap(c(33.760525217369974,-118.22052955627441),
		c(33.73290566922855,-118.17521095275879),14,'bing')
ras <- raster(longBeachHarbor)
plotRGB(ras)

## End(Not run)

Create a RasterLayer from a tile

Description

Create a RasterLayer from a tile

Usage

## S4 method for signature 'osmtile'
raster(x, ...)

Arguments

x

an osmtile

...

unused


The United States

Description

The United States