sp_segment_lines: Function to split spatial lines into segments with fixed...

View source: R/sp_segment_lines.R

sp_segment_linesR Documentation

Function to split spatial lines into segments with fixed lengths.

Description

sp_segment_lines has been pulled from another package which can be found here,

Usage

sp_segment_lines(sp, length, features = FALSE)

Arguments

sp

Spatial line object.

length

Length for the split segments. This is in the units of sp's projection system.

features

Should the function be applied to all features in sp separately?

Value

SpatialLinesDataFrame with one id variable.

Author(s)

Jason Taylor, David Blodgett, and Stuart K. Grange

See Also

https://github.com/jmt2080ad/polylineSplitter

Examples


# Make a line, this is in Switzerland so am using the local, metric projection 
# system
sp_lines <- dplyr::tribble(
  ~latitude,  ~longitude,
  47.381114,  8.5769906, 
  47.3839327, 8.5831275, 
  47.3884799, 8.5849729, 
  47.3902377, 8.5856166, 
  47.3910512, 8.5865822, 
  47.3930994, 8.5912171, 
  47.3938402, 8.5924187, 
  47.3951621, 8.5935345, 
  47.3975152, 8.5952726, 
  47.3993162, 8.5954228, 
  47.4057356, 8.598856
) %>% 
  sp_from_data_frame(type = "lines") %>% 
  sp_transform(projection_swiss())

# Check length
sp_length(sp_lines)

# Into 100 metre sections
sp_lines_split <- sp_segment_lines(sp_lines, length = 100)

# Check lengths
sp_length(sp_lines_split, features = TRUE)
sp_length(sp_lines_split, features = FALSE)


skgrange/gissr documentation built on Feb. 24, 2024, 2:55 p.m.