When distance_cutoff
and gradient_cutoff
thresholds are both broken
for route segments, this function treats them as anomalous and
sets the offending gradient values to the mean of the n
segments closest to (in front of and behind) the offending segment.
smooth_with_cutoffs(
gradient_segment,
elevation_change,
distances,
distance_cutoff = 50,
gradient_cutoff = 0.1,
n = 3,
warnNA = FALSE
)
The gradient for each segment from CycleStreets.net
The difference between the maximum and minimum elevations within each segment
The distance of each segment
Distance (m) used to identify anomalous gradients
Gradient (%, e.g. 0.1 being 10%) used to identify anomalous gradients
The number of segments to use to smooth anomalous gradents.
Logical should NA warning be given? The default is 3, meaning segments directly before, after and including the offending segment.
f = system.file(package = "cyclestreets", "extdata/journey.json")
rsf = json2sf_cs(readLines(f))
rsf$gradient_segment
#> [1] 0.010416667 0.009174312 0.000000000 0.046242775 0.000000000 0.018867925
#> [7] 0.000000000 0.040816327 0.200000000 0.000000000 0.000000000 0.000000000
#> [13] 0.018181818 0.000000000
rsf$elevation_change
#> [1] 1 1 0 8 0 2 0 2 1 0 0 0 1 0
rsf$distances
#> [1] 96 109 25 173 17 106 13 49 5 9 16 6 55 14
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances)
#> [1] 0.010416667 0.009174312 0.000000000 0.046242775 0.000000000 0.018867925
#> [7] 0.000000000 0.040816327 0.047619048 0.000000000 0.000000000 0.000000000
#> [13] 0.018181818 0.000000000
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 20, 0.05)
#> [1] 0.010416667 0.009174312 0.000000000 0.046242775 0.000000000 0.018867925
#> [7] 0.000000000 0.040816327 0.047619048 0.000000000 0.000000000 0.000000000
#> [13] 0.018181818 0.000000000
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 200, 0.02)
#> [1] 0.010416667 0.009174312 0.000000000 0.037209302 0.000000000 0.018867925
#> [7] 0.000000000 0.044776119 0.047619048 0.000000000 0.000000000 0.000000000
#> [13] 0.018181818 0.000000000
smooth_with_cutoffs(rsf$gradient_segment, rsf$elevation_change, rsf$distances, 200, 0.02, n = 5)
#> [1] 0.010416667 0.009174312 0.000000000 0.025581395 0.000000000 0.018867925
#> [7] 0.000000000 0.027472527 0.032608696 0.000000000 0.000000000 0.000000000
#> [13] 0.018181818 0.000000000