toSeg: Split polygons or lines to segments

View source: R/toSeg.R

toSegR Documentation

Split polygons or lines to segments

Description

Split lines or polygons to separate segments.

Usage

toSeg(x)

Arguments

x

A SpatialLines* or a SpatialPolygons* object

Value

A SpatialLines object where each segment is represented by a separate feature

References

This function uses a modified version of code from the following 'r-sig-geo' post by Roger Bivand: https://stat.ethz.ch/pipermail/r-sig-geo/2013-April/017998.html

Examples

seg = toSeg(build[1, ])
plot(seg, col = sample(rainbow(length(seg))))
# raster::text(rgeos::gCentroid(seg, byid = TRUE), 1:length(seg))
raster::text(as(sf::st_centroid(sf::st_geometry(sf::st_as_sf(seg))), "Spatial"), 1:length(seg))

# Other data structures
toSeg(geometry(build)) # SpatialPolygons
toSeg(boston_sidewalk) # SpatialLinesDataFrame
toSeg(geometry(boston_sidewalk)) # SpatialLinesDataFrame


michaeldorman/shadow documentation built on Sept. 10, 2023, 4:17 a.m.