trim_osmdata | R Documentation |
Trim an osmdata object to within a bounding polygon
trim_osmdata(dat, bb_poly, exclude = TRUE)
dat |
An osmdata object returned from osmdata_sf or osmdata_sp. |
bb_poly |
A matrix representing a bounding polygon obtained with
|
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. |
A trimmed version of dat
, reduced only to those components
lying within the bounding polygon.
It will generally be necessary to pre-load the sf package for this function to work correctly.
Caution is advised when using polygons obtained from Nominatim via
getbb(..., format_out = "polygon"|"sf_polygon")
. These shapes can be
outdated and thus could cause the trimming operation to not give results
expected based on the current state of the OSM data.
Other transform:
osm_elevation()
,
osm_poly2line()
,
unique_osmdata()
,
unname_osmdata_sf()
## Not run:
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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.