#library (osmplotr)
devtools::install_github ('mpadge/osmplotr')
This vignette demonstrates how the london
data included with the osmplotr
package were generated. First customise an osm_structures
data frame.
# better with a bigger bbox:
# bbox <- get_bbox (c(-0.15,51.5,-0.1,51.52))
bbox <- get_bbox (c(-0.13,51.5,-0.11,51.52))
structures <- c ('highway', 'highway', 'building', 'building', 'building',
'amenity', 'grass', 'park', 'natural', 'tree')
structs <- osm_structures (structures=structures, col_scheme='dark')
structs$value [1] <- '!primary'
structs$value [2] <- 'primary'
structs$suffix [2] <- 'HP'
structs$value [3] <- '!residential'
structs$value [4] <- 'residential'
structs$value [5] <- 'commercial'
structs$suffix [3] <- 'BNR'
structs$suffix [4] <- 'BR'
structs$suffix [5] <- 'BC'
Then download the corresponding data, noting that extract_osm_objects
returns two components: warn
containing any warnings generated during download, and obj
containing the appropriate spatial object.
london <- list ()
for (i in 1:(nrow (structs) - 1))
{
dat <- extract_osm_objects (key=structs$key [i], value=structs$value [i],
bbox=bbox)
if (!is.null (dat$warn))
warning (dat$warn)
fname <- paste0 ('dat_', structs$suffix [i])
assign (fname, dat$obj)
london [[i]] <- get (fname)
names (london)[i] <- fname
rm (list=c(fname))
}
And finally the additional data for specific buildings and highways (ignoring potential warnings this time).
extra_pairs <- c ('name', 'Royal.Festival.Hall')
london$dat_RFH <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)$obj
extra_pairs <- list (c ('addr:street', 'Stamford.St'),
c ('addr:housenumber', '150'))
london$dat_ST <- extract_osm_objects (key='building', extra_pairs=extra_pairs,
bbox=bbox)$obj
# These examples need expanded bboxes
bbox <- get_bbox (c(-0.15,51.5,-0.10,51.52))
highways <- c ('Kingsway', 'Holborn', 'Farringdon.St', 'Strand',
'Fleet.St', 'Aldwych')
london$highways1 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Queen.s.Walk', 'Blackfriars', 'Waterloo', 'The.Cut')
london$highways2 <- highways2polygon (highways=highways, bbox=bbox)
highways <- c ('Regent.St', 'Oxford.St', 'Shaftesbury')
london$highways3 <- highways2polygon (highways=highways, bbox=bbox)