Skip to contents

This function increases the number if vertices in a polygon or polyline by either adding vertices so that no edge is longer than a certain threshold, until the cardinality reaches a certain level, or by subdividing edges a specific number of times. Vertices are always inserted on the boundary so no change in the actual geometry is induced by the operation.

Usage

densify_poly(poly, max_dist = NULL, min_cardinality = NULL, n_splits = NULL)

Arguments

poly

A polyclid_polygon or polyclid_polyline vector

max_dist

Either NULL or the maximum distance between consecutive vertices allowed after the densification

min_cardinality

Either NULL or the lowest number of vertices in the resulting polygon. If an input polygon has a higher cardinality it is returned unchanged.

n_splits

Either NULL or the number of new vertices to insert into every edge.

Value

A vector of the same type and length as poly

See also

Other boundary resolution: simplify_poly()

Examples

poly <- polygon(
  c(391, 240, 252, 374, 289, 134, 68, 154, 161, 435, 208, 295, 421, 441),
  c(374, 431, 340, 320, 214, 390, 186, 259, 107, 108, 148, 160, 212, 303)
)
#> Error in polygon(c(391, 240, 252, 374, 289, 134, 68, 154, 161, 435, 208,     295, 421, 441), c(374, 431, 340, 320, 214, 390, 186, 259,     107, 108, 148, 160, 212, 303)): plot.new has not been called yet
plot(poly)
euclid_plot(vert(poly))
#> Error in UseMethod("vert"): no applicable method for 'vert' applied to an object of class "function"

# Add 1 verice to each edges
plot(poly)
euclid_plot(vert(densify_poly(poly, n_splits = 1)))
#> Error in densify_poly(poly, n_splits = 1): `poly` must be either a polygon or polyline vector

# Increase cardinality to 40
plot(poly)
euclid_plot(vert(densify_poly(poly, min_cardinality = 40)))
#> Error in densify_poly(poly, min_cardinality = 40): `poly` must be either a polygon or polyline vector

# Make sure edges have at most a length of 100
plot(poly)
euclid_plot(vert(densify_poly(poly, max_dist = 100)))
#> Error in densify_poly(poly, max_dist = 100): `poly` must be either a polygon or polyline vector