Skip to contents

Given a LineString, segment it into n equal length LineStrings. The n LineStrings are provided as a MultiLineString which can be expanded using expand_geoms() and consequently flattened using flatten_geoms() if desired.

Usage

line_segmentize(x, n)

line_segmentize_haversine(x, n)

Arguments

x

and object of class rs_LINESTRING

n

an integer vector determining the number of equal length LineStrings to create

Value

A vector of class rs_MULTILINESTRING

Details

line_segmentize() will segment a LineString using a Euclidean length calculation. line_segmentize_haversine() will use a Haversine length calculation instead. If you have geometries in a geographic cooridnate system such as EPSG:4326 use the Haversine variant. Otherwise, prefer the euclidean variant.

Examples

x <- geom_linestring(1:10, runif(10, -1, 1))

segs <- line_segmentize(x, 3)

flatten_geoms(
  expand_geoms(segs)
)
#> <rs_LINESTRING[3]>
#> [1] LineString([Coord { x: 1.0, y: -0.46555866254493594 }, Coord { x: 2.0, y: ...
#> [2] LineString([Coord { x: 4.018943076103605, y: -0.21676205444953042 }, Coord...
#> [3] LineString([Coord { x: 6.690996001567895, y: -0.12343073387055387 }, Coord...