clean_segments_by_length: Clean (Tiny) Segments by Length

Description Usage Arguments Examples

View source: R/clean_segments_by_length.R

Description

Removes tiny (below 1e-4, by default) segments generated by calc_stream_voronoi_weights that take up unnecessary space in the PBJ file and unnecessary processing power in MF-USG. Adds the tiny pieces back to another segment so lengths are not lost. Takes advantage of the fact that if it's a tiny segment it almost certainly came from a triangle corner, and triangle corners are completely in ONE node.

Usage

1
2
3
4
5
6
clean_segments_by_length(
  swdf,
  min_seg_length = 1e-04,
  forward_add = T,
  verbose = T
)

Arguments

swdf

Output from calc_stream_voronoi_weights. Must be ordered and contain geometry.

min_seg_length

Minimum allowed segment length (default: 1e-4)

forward_add

T/F Add to subsequent row in swdf (default: True). False adds to previous row. Regardless, opposite direction will be tried at start/end of swdf

verbose

T/F if information should be relayed through messages (default: True).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#-- Read in shapefiles
str <- read_sf(system.file("extdata", "straight_river.shp", package = "pbjr"))
tri <- read_sf(system.file("extdata", "straight_triangles.shp", package = "pbjr"))
vor <- read_sf(system.file("extdata", "straight_voronoi.shp", package = "pbjr"))

#-- Explode polyline
str <- line_explode(str)

#-- Create SWDF
swdf <- calc_stream_voronoi_weights(stream = str, voronoi = vor, triangles = tri,
                                    geometry = T, correct_seg_order = T)

#-- Clean up
swdf <- clean_segments_by_length(swdf)

scantle/pbjr documentation built on Dec. 22, 2021, 10:19 p.m.