Skip to contents

Returns one multipolygon per input geometry, whose parts are that geometry's triangles. The output has the same length as the input, so a triangulated geometry stays aligned with the row it came from.

Usage

ga_triangulate_earcut(x)

Arguments

x

a GeoArrow polygon or multipolygon array

Value

a GeoArrow multipolygon array of the same length as x

Details

Earcut is defined for polygons only. A multipolygon is triangulated part by part and the triangles are merged into a single multipolygon. Any other geometry type, a null geometry, or a polygon that cannot be triangulated becomes a null element.

Earcut is fast and respects interior rings, but the triangles it produces are not Delaunay. Use ga_triangulate_delaunay() when triangle quality matters.

References

TriangulateEarcut

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 length is preserved
tri <- ga_triangulate_earcut(nc$geometry)
tri$length
#> [1] 100
head(as.vector(ga_n_coords(tri)), 3)
#> [1]  96  92 100