Computes the centroids of the triangles of an fm_mesh_2d()
or fm_collect() object.
Usage
fm_centroids(x, format = NULL, name = NULL, ...)
# S3 method for class 'fm_mesh_2d'
fm_centroids(x, format = NULL, name = NULL, ...)
# S3 method for class 'fm_mesh_3d'
fm_centroids(x, format = NULL, name = NULL, ...)
# S3 method for class 'fm_collect'
fm_centroids(x, format = NULL, name = NULL, ...)Value
An sf, data.frame, or SpatialPointsDataFrame object, with the vertex
coordinates, and a .triangle column with the triangle indices.
Methods (by class)
fm_centroids(fm_mesh_2d): The result is augmented with a column ".triangle" fm_centroids(fm_mesh_3d): The result is augmented with a column ".tetra" fm_centroids(fm_collect): The result is augmented with a column ".index" with the index of the mesh in the fm_collectobject.
Author
Finn Lindgren Finn.Lindgren@gmail.com
Examples
if (require("ggplot2", quietly = TRUE)) {
vrt <- fm_centroids(fmexample$mesh, format = "sf")
ggplot() +
geom_sf(data = fm_as_sfc(fmexample$mesh)) +
geom_sf(data = vrt, color = "red")
}
cen <- fm_centroids(
fm_collect(list(fmexample$mesh, fmexample$mesh)),
format = "sf",
name = "xyzzy"
)
cen
#> Simple feature collection with 1094 features and 2 fields
#> Geometry type: POINT
#> Dimension: XYZ
#> Bounding box: xmin: -5.031762 ymin: -3.736714 xmax: 3.745673 ymax: 4.990945
#> z_range: zmin: 0 zmax: 0
#> CRS: NA
#> # A tibble: 1,094 × 3
#> xyzzy.triangle xyzzy.index xyzzy
#> * <int> <int> <POINT>
#> 1 1 1 Z (0.1587483 1.786677 0)
#> 2 2 1 Z (1.497639 -0.8424027 0)
#> 3 3 1 Z (0.5596638 -1.746063 0)
#> 4 4 1 Z (-3.834319 -1.845871 0)
#> 5 5 1 Z (-4.245891 -0.1659953 0)
#> 6 6 1 Z (-2.815959 -0.7159061 0)
#> 7 7 1 Z (-0.1173224 2.613329 0)
#> 8 8 1 Z (-1.383869 2.992167 0)
#> 9 9 1 Z (-2.502116 -0.7149274 0)
#> 10 10 1 Z (-2.683279 -1.960254 0)
#> # ℹ 1,084 more rows