Triangulate polygons with the earcut algorithm
Source:R/extendr-wrappers.R
ga_triangulate_earcut.RdReturns one multipolygon per input geometry, whose parts are that
geometry's triangles. ga_triangulate_earcut() preserves the input's length,
so it keeps each triangulated geometry aligned with the row it came from.
Details
Earcut handles polygons only. ga_triangulate_earcut() triangulates a
multipolygon part by part and merges the triangles into a single
multipolygon. It returns a null element for any other geometry type, a null
geometry, or a polygon it cannot triangulate.
Earcut is fast and respects interior rings, but the triangles it produces
are not Delaunay. Use ga_triangulate_delaunay() when triangle quality
matters.
See also
Other triangulate:
ga_triangulate_delaunay()
Examples
fp <- system.file("shape/nc.shp", package = "sf")
nc <- as.data.frame(read_shapefile(fp))
# one multipolygon of triangles per county, so you keep the input's length
tri <- ga_triangulate_earcut(nc$geometry)
tri$length
#> [1] 100
head(as.vector(ga_n_coords(tri)), 3)
#> [1] 96 92 100