Title: | Plot Raster Map Tiles from Open Street Map and Other Sources |
---|---|
Description: | Download and plot Open Street Map <https://www.openstreetmap.org/>, Bing Maps <https://www.bing.com/maps> and other tiled map sources. Use to create basemaps quickly and add hillshade to vector-based maps. |
Authors: | Dewey Dunnington [aut, cre] , Timothée Giraud [ctb] |
Maintainer: | Dewey Dunnington <[email protected]> |
License: | GPL-2 |
Version: | 0.2.6.9000 |
Built: | 2024-11-06 02:56:56 UTC |
Source: | https://github.com/paleolimbot/rosm |
The previous interface for rosm was written to support idioms that are no longer prevalent in modren r-spatial code. These functions may continue to exist; however, their use is not encouraged and the functions may be removed in a future release.
as.tile_source(x, ...) is.tile_source(x) source_from_url_format( url_format, max_zoom = tile.maxzoom.default(), min_zoom = 0, attribution = NULL, extension = tools::file_ext(url_format[1]), ... ) register_tile_source(...) set_default_tile_source(x, ...) get_default_tile_source() osm.types() bmaps.types() bmaps.plot(bbox, type = "Aerial", key = NULL, ...) extract_bbox(x, tolatlon = TRUE, ...) osm.plot( bbox, zoomin = 0, zoom = NULL, type = NULL, forcedownload = FALSE, stoponlargerequest = TRUE, fusetiles = TRUE, cachedir = NULL, res = 150, project = TRUE, progress = c("text", "none"), quiet = TRUE, ... ) osm.image( x, zoomin = 0, zoom = NULL, type = NULL, forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"), quiet = TRUE ) osm.raster( x, zoomin = 0, zoom = NULL, type = "osm", forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"), quiet = TRUE, projection = NULL, crop = FALSE, filename = NULL, resample = "bilinear", ... ) osm.points(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.segments(x0, y0, x1 = x0, y1 = y0, epsg = 4326, toepsg = 3857, ...) osm.lines(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.polygon(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.text(x, y = NULL, labels = seq_along(x), epsg = 4326, toepsg = 3857, ...) makebbox(n, e, s, w) zoombbox(bbox, factor = 1, offset = c(0, 0))
as.tile_source(x, ...) is.tile_source(x) source_from_url_format( url_format, max_zoom = tile.maxzoom.default(), min_zoom = 0, attribution = NULL, extension = tools::file_ext(url_format[1]), ... ) register_tile_source(...) set_default_tile_source(x, ...) get_default_tile_source() osm.types() bmaps.types() bmaps.plot(bbox, type = "Aerial", key = NULL, ...) extract_bbox(x, tolatlon = TRUE, ...) osm.plot( bbox, zoomin = 0, zoom = NULL, type = NULL, forcedownload = FALSE, stoponlargerequest = TRUE, fusetiles = TRUE, cachedir = NULL, res = 150, project = TRUE, progress = c("text", "none"), quiet = TRUE, ... ) osm.image( x, zoomin = 0, zoom = NULL, type = NULL, forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"), quiet = TRUE ) osm.raster( x, zoomin = 0, zoom = NULL, type = "osm", forcedownload = FALSE, cachedir = NULL, progress = c("text", "none"), quiet = TRUE, projection = NULL, crop = FALSE, filename = NULL, resample = "bilinear", ... ) osm.points(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.segments(x0, y0, x1 = x0, y1 = y0, epsg = 4326, toepsg = 3857, ...) osm.lines(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.polygon(x, y = NULL, epsg = 4326, toepsg = 3857, ...) osm.text(x, y = NULL, labels = seq_along(x), epsg = 4326, toepsg = 3857, ...) makebbox(n, e, s, w) zoombbox(bbox, factor = 1, offset = c(0, 0))
x , y , x0 , y0 , x1 , y1 , url_format , max_zoom , min_zoom , attribution , extension
|
Deprecated |
... |
Arguments passed to other methods |
bbox |
A bounding box as generated by |
type |
A map type; one of that returned by osm.types. User defined types are possible
by defining |
key , tolatlon , epsg , toepsg , labels , n , e , s , w , factor , offset
|
Deprecated |
zoomin |
The amount by which to adjust the automatically calculated zoom (or
manually specified if the |
zoom |
Manually specify the zoom level (not reccomended; adjust |
forcedownload |
|
stoponlargerequest |
By default |
fusetiles |
|
cachedir |
The directory in which tiles should be cached. Defaults to |
res |
The resolution used to calculate scale. |
project |
|
progress |
A progress bar to use, or "none" to suppress progress updates |
quiet |
Pass |
projection |
A map projection in which to reproject the RasterStack as
generated by |
crop |
|
filename |
A filename to which the raster should be written (see
|
resample |
One of "ngb" (nearest neighbour) or "bilinear". Passed to projectRaster. |
Used to skip tests and examples for this package when offline.
has_internet()
has_internet()
TRUE if the internet is available, false otherwise
has_internet()
has_internet()
Coordinate helpers
osm_native(x, y) osm_lnglat(lng, lat) osm_crs_native() osm_ensure_lnglat(pt) osm_ensure_native(pt)
osm_native(x, y) osm_lnglat(lng, lat) osm_crs_native() osm_ensure_lnglat(pt) osm_ensure_native(pt)
x , y
|
Ordinate values in EPSG:3857 (Spherical Mercator in meters) |
lng , lat
|
Coordinate values for longitude/latitude in degrees. |
pt |
A vector of points as coerced by [wk::as_xy()]. The CRS for these points is considered. |
- 'osm_native()', 'osm_lnglat()', 'osm_ensure_native()', and 'osm_ensure_lnglat()' return a [wk::xy()] with the appropriate crs - 'osm_crs_native()' returns a value that can be used as the [wk::wk_crs()] of a vector.
osm_lnglat(-64, 45) osm_ensure_native(osm_lnglat(-64, 45)) osm_ensure_lnglat( osm_ensure_native(osm_lnglat(-64, 45)) )
osm_lnglat(-64, 45) osm_ensure_native(osm_lnglat(-64, 45)) osm_ensure_lnglat( osm_ensure_native(osm_lnglat(-64, 45)) )
Load an Open Street Map image
osm_raster( bbox, spec, zoom = osm_zoom_num_tiles(6), cache_spec = NULL, quiet = NA )
osm_raster( bbox, spec, zoom = osm_zoom_num_tiles(6), cache_spec = NULL, quiet = NA )
bbox |
A [wk::rct()] or object with a [wk::wk_bbox()] method. |
spec |
An [osm_url_spec()] |
zoom |
A zoom level or an auto zoom specifier like [osm_zoom_num_tiles()]. |
cache_spec |
An optional [osm_url_spec()] or character vector to be used as the cache. |
quiet |
Use 'TRUE' for fewer messages or 'FALSE' for more messages. |
A [wk::grd_rct()] whose data member is a nativeRaster.
bounds <- wk::rct( -7476083, 5349058, -6594103, 6243203, crs = osm_crs_native() ) (grd <- osm_raster(bounds, osm_url_spec())) plot(grd)
bounds <- wk::rct( -7476083, 5349058, -6594103, 6243203, crs = osm_crs_native() ) (grd <- osm_raster(bounds, osm_url_spec())) plot(grd)
Open Street Map operates using a system of tiles whose value and bounds are easily calculated from WGS84 longitude/latitude. These functions convert between tile system coordinates and longitude/latitude.
osm_tile(pt, zoom) osm_tile_quadkey(tile) osm_tile_top_left(tile, crs = osm_crs_native()) osm_tile_envelope(tile, crs = osm_crs_native())
osm_tile(pt, zoom) osm_tile_quadkey(tile) osm_tile_top_left(tile, crs = osm_crs_native()) osm_tile_envelope(tile, crs = osm_crs_native())
pt |
A vector of points as coerced by [wk::as_xy()]. The CRS for these points is considered. |
zoom |
A zoom level, generally between 0 and 21, with higher values representing a smaller (i.e., more detailed) tile. |
tile |
A 'data.frame()' with columns 'x', 'y', and 'zoom'. |
crs |
A target CRS. Either [wk::wk_crs_longlat()] or [osm_crs_native()]. |
- 'osm_tile()': A 'data.frame()' with columns 'x', 'y', and 'zoom'. - 'osm_tile_top_left()': A [wk::xy()] of the top-left (northwest) corner of the tile. - 'osm_tile_envelope()': A [wk::rct()] of the tile bounds.
(tiles <- osm_tile(osm_lnglat(-64, 45), zoom = 0:5)) osm_tile_envelope(tiles)
(tiles <- osm_tile(osm_lnglat(-64, 45), zoom = 0:5)) osm_tile_envelope(tiles)
Get an OSM tile covering
osm_tile_covering(bbox, zoom = osm_zoom_num_tiles(6)) osm_zoom_num_tiles(num_tiles)
osm_tile_covering(bbox, zoom = osm_zoom_num_tiles(6)) osm_zoom_num_tiles(num_tiles)
bbox |
A [wk::rct()] or object with a [wk::wk_bbox()] method. |
zoom |
A zoom level or an auto zoom specifier like [osm_zoom_num_tiles()]. |
num_tiles |
The minimum number of tiles to use when choosing a zoom level. |
- 'osm_tile_covering()' returns a 'data.frame()' with columns x, y, and zoom.
bounds <- wk::rct( -7514064, 5009380, -6261722, 6261715, crs = osm_crs_native() ) osm_tile_covering(bounds)
bounds <- wk::rct( -7514064, 5009380, -6261722, 6261715, crs = osm_crs_native() ) osm_tile_covering(bounds)
Resolve a tile into a URL
osm_url(tile, spec)
osm_url(tile, spec)
tile |
A 'data.frame()' with columns 'x', 'y', and 'zoom'. |
spec |
An [osm_url_spec()] |
A character vector of URLs
bounds <- wk::rct( -7514064, 5009380, -6261722, 6261715, crs = osm_crs_native() ) tiles <- osm_tile_covering(bounds, zoom = 6) osm_url(tiles, osm_url_spec())
bounds <- wk::rct( -7514064, 5009380, -6261722, 6261715, crs = osm_crs_native() ) tiles <- osm_tile_covering(bounds, zoom = 6) osm_url(tiles, osm_url_spec())
Load tile URLs
osm_url_load_async(tile, spec, callback = NULL, cache_spec = NULL)
osm_url_load_async(tile, spec, callback = NULL, cache_spec = NULL)
tile |
A 'data.frame()' with columns 'x', 'y', and 'zoom'. |
spec |
An [osm_url_spec()] |
callback |
A function to be run for each tile fetch or NULL to do nothing. The callback is always called with two arguments: the first is the subset of 'tile' for which this URL applies (typically one row but can be more than one in some corner cases); the second is the curl response object whose useful elements are url, status_code, type, and content. |
cache_spec |
An optional [osm_url_spec()] or character vector to be used as the cache. |
'tile', invisibly.
bounds <- wk::rct( 252185, 4815826, 739729, 5210280, crs = "EPSG:32620" ) tiles <- osm_tile_covering(bounds, zoom = 5) osm_url_load_async( tiles, osm_url_spec_example(), function(tile, res) { str(tile) str(res) } )
bounds <- wk::rct( 252185, 4815826, 739729, 5210280, crs = "EPSG:32620" ) tiles <- osm_tile_covering(bounds, zoom = 5) osm_url_load_async( tiles, osm_url_spec_example(), function(tile, res) { str(tile) str(res) } )
See <https://github.com/roblabs/xyz-raster-sources> for a number of useful values to use for 'server_url'.
osm_url_spec( server_url = "https://tile.openstreetmap.org/{z}/{x}/{y}.png", block_size = c(256, 256), min_zoom = 0, max_zoom = 18, content_type = NA_character_, name = NULL ) osm_url_spec_example() as_osm_url_spec(x, ..., name = NULL)
osm_url_spec( server_url = "https://tile.openstreetmap.org/{z}/{x}/{y}.png", block_size = c(256, 256), min_zoom = 0, max_zoom = 18, content_type = NA_character_, name = NULL ) osm_url_spec_example() as_osm_url_spec(x, ..., name = NULL)
server_url |
A url using 'x', 'y', and 'z' for the x, y, and zoom level to be replaced. This can be any URL; non-URLs are assumed to be local file paths relative to the current working directory at the time of the download. |
block_size |
The pixel size of each image |
min_zoom , max_zoom
|
The min/max zoom that this tile specification can handle |
content_type |
A MIME type or NA to guess the type from 'server_url'. |
name |
A name for this spec. Useful for cache specifications. |
x |
An object to convert to an osm_url_spec |
... |
Passed to S3 methods |
An object of class osm_url_spec.
osm_url_spec()
osm_url_spec()
The default tile cache location is the "rosm.cache" folder in the current working directory, but for a variety of reasons it may be desirable to use one cache directory for all calls in a script. This must be called every time the namespace is loaded.
set_default_cachedir(cachedir) get_default_cachedir()
set_default_cachedir(cachedir) get_default_cachedir()
cachedir |
A path to use as the cache directory (relative to the working directory). Use NULL to reset to the default. |
The previous cache directory, invisibly.
set_default_cachedir(tempfile()) get_default_cachedir() (set_default_cachedir(NULL))
set_default_cachedir(tempfile()) get_default_cachedir() (set_default_cachedir(NULL))