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-11-05 03:42:09 UTC |
Source: | https://github.com/ifellows/rosm |
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.
object |
An object (for example an OpenStreetMap object) |
... |
Additional arguments |
a ggplot object
[autoplot.OpenStreetMap()]
Plot an open street map using ggplot2
## S3 method for class 'OpenStreetMap' autoplot(object, expand = TRUE, ...)
## S3 method for class 'OpenStreetMap' autoplot(object, expand = TRUE, ...)
object |
an OpenStreetMap object |
expand |
if true the plotting bounds are expanded to the bounding box |
... |
not used |
## 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)
## 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
## S3 method for class 'osmtile' autoplot(object, plot = FALSE, ...)
## S3 method for class 'osmtile' autoplot(object, plot = FALSE, ...)
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
getMapInfo()
getMapInfo()
Launches a Java helper GUI.
launchMapHelper()
launchMapHelper()
note for Mac OS X users: On the mac this can only be run from a java console such as JGR.
Get a map based on lat long coordinates
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 )
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 )
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 |
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
## 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)
## 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
openproj(x, projection = "+proj=longlat", ...)
openproj(x, projection = "+proj=longlat", ...)
x |
an OpenStreetMap object |
projection |
a proj4 character string or CRS object |
... |
additional parameters for projectRaster |
## 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)
## 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
osm()
osm()
Get an open street map tile.
osmtile(x, y, zoom, type = "osm")
osmtile(x, y, zoom, type = "osm")
x |
location in osm native coordinates |
y |
location in osm native coordinates |
zoom |
zoom level |
type |
the map type (see getMapInfo) |
a tile
Plot an OpenStreetMap object.
## S3 method for class 'OpenStreetMap' plot(x, y = NULL, add = FALSE, removeMargin = TRUE, ...)
## S3 method for class 'OpenStreetMap' plot(x, y = NULL, add = FALSE, removeMargin = TRUE, ...)
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
## S3 method for class 'osmtile' plot(x, y = NULL, add = TRUE, raster = TRUE, ...)
## S3 method for class 'osmtile' plot(x, y = NULL, add = TRUE, raster = TRUE, ...)
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
## S3 method for class 'OpenStreetMap' print(x, ...)
## S3 method for class 'OpenStreetMap' print(x, ...)
x |
the OpenStreetMap |
... |
ignored |
Maps long lat values to the open street map mercator projection
projectMercator(lat, long, drop = TRUE)
projectMercator(lat, long, drop = TRUE)
lat |
a vector of latitudes |
long |
a vector of longitudes |
drop |
drop to lowest dimension |
Create a RasterLayer from an OpenStreetMap
## S4 method for signature 'OpenStreetMap' raster(x, ...)
## S4 method for signature 'OpenStreetMap' raster(x, ...)
x |
an OpenStreetMap |
... |
unused |
## 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)
## 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
## S4 method for signature 'osmtile' raster(x, ...)
## S4 method for signature 'osmtile' raster(x, ...)
x |
an osmtile |
... |
unused |