Package rosm. April 8, 2017

Similar documents
Package osrm. November 13, 2017

Package tiler. June 9, 2018

Package gfcanalysis. August 29, 2016

Package rnaturalearth

Package exifr. October 15, 2017

Package rnrfa. April 13, 2018

Package fastdummies. January 8, 2018

Package datasets.load

Package pkgbuild. October 16, 2018

Package spark. July 21, 2017

Package opencage. January 16, 2018

Package velox. R topics documented: December 1, 2017

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package geogrid. August 19, 2018

Package ecoseries. R topics documented: September 27, 2017

Package messaging. May 27, 2018

Package testit. R topics documented: June 14, 2018

Package nlgeocoder. October 8, 2018

Package goodpractice

Package raker. October 10, 2017

Package librarian. R topics documented:

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package robotstxt. November 12, 2017

Package canvasxpress

Package validara. October 19, 2017

Package clipr. June 23, 2018

Package sankey. R topics documented: October 22, 2017

Package gridgraphics

Package oec. R topics documented: May 11, Type Package

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package smapr. October 20, 2017

Package qualmap. R topics documented: September 12, Type Package

Package imgur. R topics documented: December 20, Type Package. Title Share plots using the imgur.com image hosting service. Version 0.1.

Package pkgload. July 8, 2018

Package ECctmc. May 1, 2018

Package tidyselect. October 11, 2018

Package xroi. February 13, 2019

Package postgistools

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package io. January 15, 2018

Package spelling. December 18, 2017

Package osmdata. February 22, 2018

Package docxtools. July 6, 2018

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package darksky. September 20, 2017

Package repec. August 31, 2018

Package barcoder. October 26, 2018

Package fastqcr. April 11, 2017

Package rmapzen. October 7, 2018

Package lumberjack. R topics documented: July 20, 2018

Package smoothr. April 4, 2018

Package sessioninfo. June 21, 2017

Package cancensus. February 4, 2018

Package readxl. April 18, 2017

Package angstroms. May 1, 2017

Package SEMrushR. November 3, 2018

Package vip. June 15, 2018

Package Grid2Polygons

Package kirby21.base

Package nngeo. September 29, 2018

Package rbgm. May 18, 2018

Package gtrendsr. August 4, 2018

Package tidytransit. March 4, 2019

Package staplr. May 9, 2018

Package rcmdcheck. R topics documented: November 10, 2018

Package mapr. April 11, 2017

Package sigmanet. April 23, 2018

Package githubinstall

Package liftr. R topics documented: May 14, Type Package

Package jstree. October 24, 2017

Package shinyhelper. June 21, 2018

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package tensorflow. January 17, 2018

Package gtrendsr. October 19, 2017

Package rtext. January 23, 2019

Package ConvergenceClubs

Package waver. January 29, 2018

Package rvg. February 13, 2018

Package kdtools. April 26, 2018

Package pairsd3. R topics documented: August 29, Title D3 Scatterplot Matrices Version 0.1.0

Package tabulizer. June 7, 2018

Package calpassapi. August 25, 2018

Package fingertipsr. May 25, Type Package Version Title Fingertips Data for Public Health

Package WordR. September 7, 2017

Package modules. July 22, 2017

Package deductive. June 2, 2017

Package zip. R topics documented: March 11, Title Cross-Platform 'zip' Compression Version 2.0.1

Package rollply. R topics documented: August 29, Title Moving-Window Add-on for 'plyr' Version 0.5.0

Package meme. November 2, 2017

Package wikitaxa. December 21, 2017

Package glcm. August 29, 2016

Package pdfsearch. July 10, 2018

Package meme. December 6, 2017

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package desc. May 1, 2018

Package redux. May 31, 2018

Package mapedit. R topics documented: March 2, Title Interactive Editing of Spatial Data in R

Package sfdct. August 29, 2017

Transcription:

Type Package Package rosm April 8, 2017 Title Plot Raster Map Tiles from Open Street Map and Other Sources Version 0.2.2 Date 2017-04-6 Encoding UTF-8 Maintainer Dewey Dunnington <dewey@fishandwhistle.net> Download and plot Open Street Map <http://www.openstreetmap.org/>, Bing Maps <http://www.bing.com/maps> and other tiled map sources in a way that works seamlessly with plotting from the 'sp' package. Use to create high-resolution basemaps and add hillshade to vector-based maps. License GPL-2 LazyData TRUE Imports curl, abind, jpeg, png, sp, rgdal, rjson, methods, plyr, prettymapr Suggests rcanvec, cartography, raster, testthat URL https://github.com/paleolimbot/rosm BugReports https://github.com/paleolimbot/rosm/issues RoxygenNote 5.0.1 NeedsCompilation no Author Dewey Dunnington [aut, cre], Timothée Giraud [ctb] Repository CRAN Date/Publication 2017-04-07 22:14:30 UTC R topics documented: as.tile_source........................................ 2 bmaps.plot.......................................... 3 bmaps.types......................................... 4 1

2 as.tile_source extract_bbox........................................ 4 osm.image.......................................... 5 osm.lines.......................................... 7 osm.plot........................................... 7 osm.points.......................................... 9 osm.polygon......................................... 9 osm.segments........................................ 10 osm.text........................................... 11 osm.types.......................................... 11 register_tile_source..................................... 12 rosm............................................. 13 set_default_cachedir.................................... 14 Index 16 as.tile_source Tile Sources Tile sources define where rosm looks for map tiles. There are a number of built-in types (osm.types), or they can be created using as.tile_source(), registered using register_tile_source for easy access, or passed directly to the osm.plot family of methods. as.tile_source(x,...) is.tile_source(x) source_from_url_format(url_format, max_zoom = tile.maxzoom.default(), min_zoom = 0, attribution = NULL,...) x An object (usually a name or string format) with which to create a tile source... passed to other methods url_format A string in the form https://tiles.wmflabs.org/bw-mapnik/${z}/${x}/${y}.png, where z, x, and y are the zoom, xtile, and ytile, respectively. Also valid is $q, which will be passed a quadkey. max_zoom An integer specifying the maximum zoom to use (default is 19) min_zoom An integer specifying the minimum zoom to use (default is 1) attribution An attribution string, required by some tile providers.

bmaps.plot 3 Details Passing a name from osm.types will return that tile source; passing a name from register_tile_source will return that tile source, and passing a URL format in the form https://tiles.wmflabs.org/bw-mapnik/${z}/${x}/${ will create a new tile source. Old style function names in the form tile.url.type are still supported but are deprecated. Value An object of class tile_source # get builtin tile sources as.tile_source("osm") # get custom tile sources as.tile_source("http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png") # get registered tile sources register_tile_source(dark = "http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png") as.tile_source("dark") # create more complex tile sources using source_from_url_format source_from_url_format("http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png", attribution = "Tiles by CartoDB") # test for tile sources is.tile_source(as.tile_source("osm")) bmaps.plot Plot Bing Maps Identical syntax to osm.plot, but using Bing maps (https://www.bing.com/maps/) instead of Open Street Map. bmaps.plot(bbox, type = "Aerial", key = NULL,...) bbox type key A bounding box as generated by sp::bbox() or prettymapr::searchbbox() Use Aerial, AerialWithLabels, or Road. If plotting a large number of images, consider getting your own (free) key at the Microsoft Website.... passed on to osm.plot.

4 extract_bbox bmaps.plot(makebbox(47.2, -59.7, 43.3, -66.4)) bmaps.plot(makebbox(47.2, -59.7, 43.3, -66.4), type="road") bmaps.types List types of Bing Maps List types of Bing Maps bmaps.types() Value A list of valid bing map types bmaps.types() extract_bbox Extract a bounding box from an object This function is used internally by osm.plot, bmaps.plot, and osm.raster to extract a bounding box from their first argument. This allows considerable flexibility when specifying a location to map, in particular with character input (a place name that will be geocoded), and other Spatial*/Raster* objects. extract_bbox(x, tolatlon = TRUE,...)

osm.image 5 x Value tolatlon A Spatial* object, a Raster* object, a bounding box, or a character string that will be passed to searchbbox() (prettymapr package). Multiple strings will result in a bounding box that contains all of the geocoded bounding boxes. The last resort is calling sp::bbox() on the x. Should the bounding box be un-projected to lat/lon coordinates?... Passed to searchbbox() if applicable A bounding box in the form of sp::bbox() ns <- makebbox(47.2, -59.7, 43.3, -66.4) stopifnot(identical(ns, extract_bbox(ns))) # downloads data, takes a long time to test ns <- extract_bbox("nova scotia") osm.image Get Open Street Map Tiles As A RasterStack Get Open Street Map tiles as RasterStack object (requires package raster to be installed). 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,...) x A bounding box as generated by sp::bbox() or prettymapr::searchbbox(). Must be in lon/lat (epsg:4326)! Alternatively, pass a Spatial* object to use the bounding box of that

6 osm.image Value zoomin zoom type forcedownload cachedir progress quiet projection crop filename The amount by which to adjust the automatically calculated zoom (or manually specified if the zoom parameter is passed). Use +1 to zoom in, or -1 to zoom out. Manually specify the zoom level (not recommended; adjust zoomin instead. A map type; one of that returned by osm.types. User defined types are possible by defining tile.url.typename <-function(xtile, ytile, zoom){} and passing TYPENAME as the type argument. TRUE if cached tiles should be re-downloaded. Useful if some tiles are corrupted. The directory in which tiles should be cached. Defaults to getwd()/rosm.cache. A progress bar to use, or "none" to suppress progress updates Pass FALSE to see more error messages, particularly if your tiles do not download/load properly. A map projection in which to reproject the RasterStack as generated by CRS() or Spatial*@proj4string. If a Spatial* object is passed as the first argument, this argument will be ignored. TRUE if results should be cropped to the specified bounding box (see x), FALSE otherwise. A filename to which the raster should be written (see raster::writeraster()). Use a ".tif" extension to write as a GeoTIFF.... passed on to raster::writeraster() if filename is specified. A projected RasterStack of the fused tiles. library(cartography) library(raster) ns <- makebbox(47.2, -59.7, 43.3, -66.4) x <- osm.raster(ns, projection=crs("+init=epsg:26920"), crop=true) # plot using plotrgb (from the raster package) plotrgb(x) # use a Spatial* object as the first argument to automatically set the bounding # box and projection data(nuts2006) spdf <- nuts0.spdf[nuts0.spdf$id=="de",] x <- osm.raster(spdf, type="thunderforestlandscape") plotrgb(x) # write to disk by passing a filename argument (use.tif extension to write GeoTIFF) osm.raster(ns, projection=crs("+init=epsg:26920"), crop=true, filename="ns.tif") # can also write Raster* objects using osm.raster osm.raster(x, filename="germany.tif")

osm.lines 7 osm.lines Overlay lines on an OSM plot Plot lines on a plot created by osm.plot. This is a simple wrapper around points(). osm.lines(x, y = NULL, epsg = 4326, toepsg = 3857,...) x X coordinate vector or object as parsed by xy.coords y Y coordinate vector epsg EPSG code of the supplied coordinates toepsg EPSG code of the projected coordinates to be ploted... Args passed on to lines library(rosm) locs <- geocode(c("wolfville, ns", "kentville, ns", "halifax, ns")) prettymap({ osm.plot(searchbbox("nova scotia")) osm.lines(locs$lon, locs$lat, lwd=2) }) osm.plot Plot Open Street Map Tiles Plot Open Street Map tiles using rasterimage and sp::plot. Define your own tile sources by creating a tile url function in the global environment, although most OSM listed servers are included. See osm.types for types options. By default tiles are plotted in the Spherical Mercator projection (epsg:3857); pass project=false to keep lat/lon coordinates.

8 osm.plot 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,...) bbox zoomin zoom type A bounding box as generated by sp::bbox() or prettymapr::searchbbox() The amount by which to adjust the automatically calculated zoom (or manually specified if the zoom parameter is passed). Use +1 to zoom in, or -1 to zoom out. Manually specify the zoom level (not reccomended; adjust zoomin or res instead. A map type; one of that returned by osm.types. User defined types are possible by defining tile.url.typename <- function(xtile, ytile, zoom){} and passing TYPENAME as the type argument. forcedownload TRUE if cached tiles should be re-downloaded. Useful if some tiles are corrupted. stoponlargerequest By default osm.plot will only load 32 tiles at a time. If plotting at a higher resolution it may be necessary to pass true here. fusetiles cachedir res project progress quiet TRUE if tiles should be fused into a single image. This is the default because white lines appear between tiles if it is set to FALSE. PDFs appear not to have this problem, so when plotting large, high resolution PDFs it may be faster (and more memory efficient) to use fusetiles=false. The directory in which tiles should be cached. Defaults to getwd()/rosm.cache. The resolution used to calculate scale. TRUE if tiles should be projected to a pseudo-mercator projection, FALSE if lat/lon should be maintained. Becuase sp::plot adjusts the aspect according to latitude for lat/lon coordinates, this makes little difference at high zoom and may make plotting overlays more convenient. Defaults to TRUE. A progress bar to use, or "none" to suppress progress updates Pass FALSE to see more error messages, particularly if your tiles do not download/load properly.... Additional parameters to be passed on to the first call to sp::plot ns <- makebbox(47.2, -59.7, 43.3, -66.4) osm.plot(ns) osm.plot(ns, type="stamenbw") prettymap(osm.plot(ns), scale.style="ticks", scale.tick.cex=0)

osm.points 9 osm.points Overlay points on an OSM plot Plot points on a plot created by osm.plot. This is a simple wrapper around points(). osm.points(x, y = NULL, epsg = 4326, toepsg = 3857,...) x X coordinate vector or object as parsed by xy.coords y Y coordinate vector epsg EPSG code of the supplied coordinates toepsg EPSG code of the projected coordinates to be ploted... Args passed on to points library(rosm) locs <- geocode(c("wolfville, ns", "kentville, ns", "halifax, ns")) prettymap({ osm.plot(searchbbox("nova scotia")) osm.points(locs$lon, locs$lat, pch=18, cex=0.7) }) osm.polygon Overlay a polygon on an OSM plot Plot a polygon on a plot created by osm.plot. This is a simple wrapper around polygon(). osm.polygon(x, y = NULL, epsg = 4326, toepsg = 3857,...)

10 osm.segments x X coordinate vector or object as parsed by xy.coords y Y coordinate vector epsg EPSG code of the supplied coordinates toepsg EPSG code of the projected coordinates to be ploted... Args passed on to polygon library(rosm) locs <- geocode(c("wolfville, ns", "kentville, ns", "halifax, ns")) prettymap({ osm.plot(searchbbox("nova scotia")) osm.polygon(locs$lon, locs$lat) }) osm.segments Overlay segments on an OSM plot Plot segments on a plot created by osm.plot. This is a simple wrapper around segments(). osm.segments(x0, y0, x1 = x0, y1 = y0, epsg = 4326, toepsg = 3857,...) x0 X1 coordinate vector y0 Y1 coordinate vector x1 X2 coordinate vector y1 Y2 coordinate vector epsg EPSG code of the supplied coordinates toepsg EPSG code of the projected coordinates to be ploted... Args passed on to points

osm.text 11 library(rosm) locs <- geocode(c("wolfville, ns", "kentville, ns", "halifax, ns")) prettymap({ osm.plot(searchbbox("nova scotia")) osm.segments(locs$lon[1:2], locs$lat[1:2], locs$lon[2:3], locs$lat[2:3]) }) osm.text Overlay text on an OSM plot Plot text on a plot created by osm.plot. osm.text(x, y = NULL, labels = seq_along(x), epsg = 4326, toepsg = 3857,...) x X coordinate vector or object as parsed by xy.coords y Y coordinate vector labels A character vector or expression specifying the text to be written. epsg EPSG code of the supplied coordinates toepsg EPSG code of the projected coordinates to be ploted... Args passed on to text() osm.types Get List of Valid Tile Sources Get List of Valid Tile Sources osm.types()

12 register_tile_source Value A character vector of valid type parameters. osm.types() register_tile_source Register Tile Sources Use this function to register tile sources so they can be referred to by name in osm.plot. Tile sources will be registered for as long as the namespace is loaded. Use set_default_tile_source() to set the default source. register_tile_source(...) set_default_tile_source(x,...) get_default_tile_source()... Passed to as.tile_source for set_default_tile_source, or a named list of tile sources for register_tile_source x The tile source (or coercible string) to use as the default tile source # set the default tile source set_default_tile_source("stamenbw") # register a custom tile source register_tile_source(dark = "http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png") ns <- makebbox(47.2, -59.7, 43.3, -66.4) prettymap(osm.plot(ns, "dark"))

rosm 13 rosm Plot Raster Map Tiles From Open Street Map and Other Sources This package provides access and plots Open Street Map and Bing Maps tiles to create highresolution basemaps and use hillshade tiles to add texture to other maps. Uses the sp package to plot using base graphics. Plot Open Street Map derivative tiles using osm.plot, and plot Bing maps (Aerial, Labeled Aerial, Road) using bmaps.plot. 16 OSM and 3 Bing sources are included, with the ability to define custom tile sources based on OSM tilex, tiley, and zoom. Use osm.raster to get tiles in a RasterStack or write to disk (requires the raster package.) Author(s) Dewey Dunnington <dewey@fishandwhistle.net> References Open Street Map tile servers, Bing Maps API documentation library(rcanvec) library(sp) # basic ploting nsbox <- searchbbox("nova scotia", source="google") osm.plot(nsbox) osm.plot(nsbox, type="stamenbw") bmaps.plot(nsbox) bmaps.plot(nsbox, type="road") # use {prettymapr} to add scalebar and north arrow prettymap(osm.plot(nsbox)) prettymap(bmaps.plot(nsbox, type="road")) # increase res argument to plot to file pdf(height=8, width=10.5) prettymap(osm.plot(nsbox, type="stamenbw", res=300, stoponlargerequest=false), scale.label.col="white", arrow.text.col = "white", scale.linecol = "white", arrow.border = "white") dev.off() # use osm.raster() to export a RasterStack of tiles library(raster) x <- osm.raster(nsbox)

14 set_default_cachedir x <- osm.raster(nsbox, projection=crs("+init=epsg:26920")) #reproject to UTM 20 plotrgb(x) #plot reprojected image # write to disk by passing a filename= argument osm.raster(nsbox, projection=crs("+init=epsg:26920"), filename="ns2.tif") # canvec.qplot and hillshade using the add=true argument prettymap({ altabox <- prettymapr::searchbbox("alta Lake BC", source="google") canvec.qplot(bbox=altabox, layers=c("waterbody", "forest", "river", "road")) osm.plot(altabox, type="hillshade", add=t, project = FALSE) }) # define custom tile types in several ways # using string formats ts <- as.tile_source("http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png") osm.plot(nsbox, type=ts) # using string formats and register_tile_source register_tile_source(dark = "http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png") osm.plot(nsbox, type="dark") # set default plot type to something other than 'osm' set_default_tile_source("stamenbw") osm.plot(nsbox) set_default_cachedir Set/Get the Default Tile Cache Location 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() cachedir A path to use as the cache directory (relative to the working directory). Use NULL to reset to the default.

set_default_cachedir 15 Value The previous cache directory, invisibly. set_default_cachedir(tempfile()) get_default_cachedir() (set_default_cachedir(null))

Index as.tile_source, 2, 12 bmaps.plot, 3, 4, 13 bmaps.types, 4 extract_bbox, 4 get_default_cachedir (set_default_cachedir), 14 get_default_tile_source (register_tile_source), 12 is.tile_source (as.tile_source), 2 osm.image, 5 osm.lines, 7 osm.plot, 2 4, 7, 7, 9 13 osm.points, 9 osm.polygon, 9 osm.raster, 4, 13 osm.raster (osm.image), 5 osm.segments, 10 osm.text, 11 osm.types, 2, 3, 6 8, 11 register_tile_source, 2, 3, 12 rosm, 13 rosm-package (rosm), 13 set_default_cachedir, 14 set_default_tile_source (register_tile_source), 12 source_from_url_format (as.tile_source), 2 16