# NOT RUN {
bbox <- get_bbox (c (-0.13, 51.5, -0.11, 51.52))
# Download data using 'extract_osm_objects'
# }
# NOT RUN {
dat_HP <- extract_osm_objects (key = 'highway', value = 'primary', bbox = bbox)
dat_T <- extract_osm_objects (key = 'tree', bbox = bbox)
dat_BNR <- extract_osm_objects (key = 'building', value = '!residential',
bbox = bbox)
# }
# NOT RUN {
# These data are also provided in
dat_HP <- london$dat_HP
dat_T <- london$dat_T
dat_BNR <- london$dat_BNR
# Define a function to easily generate a basemap
bmap <- function ()
{
map <- osm_basemap (bbox = bbox, bg = "gray20")
map <- add_osm_objects (map, dat_HP, col = "gray70", size = 1)
add_osm_objects (map, dat_T, col = "green")
}
# Highlight a single region using all objects lying partially inside the
# boundary (via the boundary = 1 argument)
pts <- sp::SpatialPoints (cbind (c (-0.115, -0.125, -0.125, -0.115),
c (51.505, 51.505, 51.515, 51.515)))
# }
# NOT RUN {
dat_H <- extract_osm_objects (key = 'highway', bbox = bbox) # all highways
map <- bmap ()
map <- add_osm_groups (map, dat_BNR, groups = pts, cols = "gray90",
bg = "gray40", boundary = 1)
map <- add_osm_groups (map, dat_H, groups = pts, cols = "gray80",
bg = "gray30", boundary = 1)
print_osm_map (map)
# }
# NOT RUN {
# Generate random points to serve as group centres
set.seed (2)
ngroups <- 6
x <- bbox [1,1] + runif (ngroups) * diff (bbox [1,])
y <- bbox [2,1] + runif (ngroups) * diff (bbox [2,])
groups <- cbind (x, y)
groups <- apply (groups, 1, function (i)
sp::SpatialPoints (matrix (i, nrow = 1, ncol = 2)))
# plot a basemap and add groups
map <- bmap ()
cols <- rainbow (length (groups))
# }
# NOT RUN {
map <- add_osm_groups (map, obj = london$dat_BNR, group = groups, cols = cols)
cols <- adjust_colours (cols, -0.2)
map <- add_osm_groups (map, obj = london$dat_H, groups = groups, cols = cols)
print_osm_map (map)
# Highlight convex hulls containing groups:
map <- bmap ()
map <- add_osm_groups (map, obj = london$dat_BNR, group = groups, cols = cols,
border_width = 2)
print_osm_map (map)
# }
Run the code above in your browser using DataLab