Learn R Programming

osmplotr (version 0.3.2)

connect_highways: connect_highways

Description

Takes a list of highways names which must enclose an internal area, and returns a SpatialLines object containing a sequence of OSM nodes which cyclically connect all highways. Will fail if the streets do not form a cycle.

Usage

connect_highways(highways, bbox, plot = FALSE)

Arguments

highways

A vector of highway names passed directly to the Overpass API. Wildcards and whitespaces are `.'; for other options see online help for the overpass API.

bbox

the bounding box for the map. A 2-by-2 matrix of 4 elements with columns of min and max values, and rows of x and y values.

plot

If TRUE, then all OSM data for each highway is plotted and the final cycle overlaid.

Value

A single set of SpatialPoints containing the lat-lon coordinates of the cyclic line connecting all given streets.

See Also

add_osm_groups.

Examples

Run this code
# NOT RUN {
bbox <- get_bbox (c (-0.13, 51.5, -0.11, 51.52))
# }
# NOT RUN {
highways <- c ('Monmouth.St', 'Short.?s.Gardens', 'Endell.St', 'Long.Acre',
               'Upper.Saint.Martin')
# Note that dots signify "anything", including whitespace and apostrophes, and
# that '?' denotes optional previous character and so here matches both 
# "Shorts Gardens" and "Short's Gardens"
highways1 <- connect_highways (highways = highways, bbox = bbox, plot = TRUE)
highways <- c ('Endell.St', 'High.Holborn', 'Drury.Lane', 'Long.Acre')
highways2 <- connect_highways (highways = highways, bbox = bbox, plot = TRUE)

# Use of 'connect_highways' to highlight a region on a map
map <- osm_basemap (bbox = bbox, bg = 'gray20')
# dat_B <- extract_osm_data (key = 'building', value = '!residential', bbox = bbox)
# Those data are part of 'osmplotr':
dat_BNR <- london$dat_BNR # Non-residential buildings
groups <- list (highways1, highways2)
map <- add_osm_groups (map, obj = dat_BNR, groups = groups,
                       cols = c('red', 'blue'), bg = 'gray40')
print_osm_map (map)
# }

Run the code above in your browser using DataLab