View source: R/smooth-spline.R
smooth_spline | R Documentation |
Spline interpolation uses stats::spline()
to interpolate between existing
vertices using piecewise cubic polynomials. The coordinates are interpolated
independently. The curve will always pass through the vertices of the
original feature.
smooth_spline(x, wrap = FALSE, vertex_factor = 5, n)
x |
numeric matrix; matrix of coordinates. |
wrap |
logical; whether the coordinates should be wrapped at the ends, as for polygons and closed lines, to ensure a smooth edge. |
vertex_factor |
double; the proportional increase in the number of
vertices in the smooth curve. For example, if the original curve has 100
points, a value of |
n |
integer; number of vertices in the smoothed curve. |
This function works on matrices of points and is generally not called
directly. Instead, use smooth()
with method = "spline"
to apply this
smoothing algorithm to spatial features.
A matrix with the coordinates of the smoothed curve.
The spline method was inspired by the following StackExchange answers:
smooth()
# smooth_spline works on matrices of coordinates
# use the matrix of coordinates defining a polygon as an example
m <- jagged_polygons$geometry[[2]][[1]]
m_smooth <- smooth_spline(m, wrap = TRUE)
class(m)
class(m_smooth)
plot(m_smooth, type = "l", col = "red", axes = FALSE, xlab = NA, ylab = NA)
lines(m, col = "black")
# smooth is a wrapper for smooth_spline that works on spatial features
library(sf)
p <- jagged_polygons$geometry[[2]]
p_smooth <- smooth(p, method = "spline")
class(p)
class(p_smooth)
plot(p_smooth, border = "red")
plot(p, add = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.