Learn R Programming

osmplotr (version 0.1-3)

add_osm_surface: add_osm_suface

Description

Adds a colour-coded surface of spatial objects (polygons, lines, or points generated by extract_osm_objects ()) to a graphics object initialised with plot_osm_basemap(). The surface is spatially interpolated between the values given in 'dat', which has to be a matrix or data.frame of 3 colums (x, y, z), where (x,y) are (longitude, latitude), and z are the values to be interpolated. Interpolation uses spatstat::Smoothing.ppp, which applies a Gaussian kernel smoother optimised to the given data, and is effectively non-parametric.

Usage

add_osm_surface(obj = obj, dat = NULL, method = "idw", bg = NULL,
  cols = terrain.colors(30), border = FALSE, verbose = FALSE, ...)

Arguments

obj
an sp SPDF or SLDF (list of polygons or lines) returned by extract_osm_objects ()
dat
A matrix or data frame of 3 columns (x, y, z), where (x, y) are (longitude, latitude), and z are the values to be interpolated
method
Either 'idw' (Inverse Distance Weighting as spatstat::idw; default), otherwise uses 'Gaussian' for kernel smoothing (as spatstat::Smooth.ppp)
bg
If specified, OSM objects outside the convex hull surrounding 'dat' are plotted in this colour, otherwise they are included in the interpolation (which will generally be inaccurate for peripheral values)
cols
Vector of colours for shading z-values (for example, 'terrain.colors (30)')
border
Plot border? (For SpatialPolygons only)
verbose
If TRUE, provides notification of progress
...
other parameters to be passed to polygons, lines (such as lwd, lty), or points (such as pch, cex)

Value

  • Range of interpolated values (which may differ from range of 'dat$z' as submitted, and can be used to scale 'add_colourbar()')

Examples

Run this code
plot_osm_basemap (bbox=get_bbox (c (-0.15, 51.5, -0.1, 51.52)), col="gray20")
add_osm_objects (london$dat_BNR, col="gray40") # non-residential buildings
bbox <- get_bbox (c (-0.15, 51.5, -0.1, 51.52))
x <- seq (bbox [1,1], bbox [1,2], length.out=dim (volcano)[1])
y <- seq (bbox [2,1], bbox [2,2], length.out=dim (volcano)[2])
xy <- cbind (rep (x, dim (volcano) [2]), rep (y, each=dim (volcano) [1]))
z <- as.numeric (volcano)
plot_osm_basemap (bbox=bbox, bg="gray20")
# uncomment to run: can be time-consuming
# zl <- add_osm_surface (london$dat_BNR, dat=cbind (xy, z), method="idw")
cols <- adjust_colours (terrain.colors (30), -0.2) # Darken by ~20\%
# zl <- add_osm_surface (london$dat_H, dat=cbind (xy, z), cols=cols)
# zl <- add_osm_surface (london$dat_HP, dat=cbind (xy, z), cols=cols, lwd=2)
# add_colourbar (cols=terrain.colors (30), side=4, zlims=zl)

Run the code above in your browser using DataLab