Learn R Programming

osmdata (version 0.2.3)

trim_osmdata: trim_osmdata

Description

Trim an osmdata object to within a bounding polygon

Usage

trim_osmdata(dat, bb_poly, exclude = TRUE)

Value

A trimmed version of dat, reduced only to those components lying within the bounding polygon.

Arguments

dat

An osmdata object returned from osmdata_sf or osmdata_sp.

bb_poly

A matrix representing a bounding polygon obtained with getbb (..., format_out = "polygon") (and possibly selected from resultant list where multiple polygons are returned).

exclude

If TRUE, objects are trimmed exclusively, only retaining those strictly within the bounding polygon; otherwise all objects which partly extend within the bounding polygon are retained.

See Also

Other transform: osm_elevation(), osm_poly2line(), unique_osmdata(), unname_osmdata_sf()

Examples

Run this code
if (FALSE) {
dat <- opq ("colchester uk") %>%
    add_osm_feature (key = "highway") %>%
    osmdata_sf (quiet = FALSE)
bb <- getbb ("colchester uk", format_out = "polygon")
library (sf) # required for this function to work
dat_tr <- trim_osmdata (dat, bb)
bb <- getbb ("colchester uk", format_out = "sf_polygon")
class (bb) # sf data.frame
dat_tr <- trim_osmdata (dat, bb)
bb <- as (bb, "Spatial")
class (bb) # SpatialPolygonsDataFrame
dat_tr <- trim_osmdata (dat, bb)
}

Run the code above in your browser using DataLab