gs_geometry() returns a node geometry column of a
GraphSpace object, and gs_geometry<- adds, replaces
or removes one. Geometry columns are sfc objects from the
sf package, with one geometry per node, such as node shapes or
cell boundaries.
Usage
# S4 method for class 'GraphSpaceInterface'
gs_geometry(x, name = "geometry", raw = FALSE, unit = NULL)
# S4 method for class 'GraphSpaceInterface'
gs_geometry(x, name = "geometry") <- valueArguments
- x
A GraphSpace object.
- name
Name of the geometry column (a single string).
- raw
A single logical value. If
FALSE(default), return the working copy; ifTRUE, the pristine copy, in the frame of the raw coordinates. As ings_coords.- unit
Optional length unit, such as
"um", to return the geometry in, using the unit set withgs_coords_unit; scaled asgs_coords(x, raw, unit), so that both stay aligned.- value
An
sfcgeometry column, ansfobject (its geometry is used) or a list ofsfggeometries, with one geometry per node; orNULLto remove the column.
Value
gs_geometry() returns an sfc object, or NULL if
name isn't a geometry column. gs_geometry<- returns the
updated GraphSpace object.
Details
Like node coordinates, geometry is kept in two forms: a raw copy, which
matches the raw coordinates, and a working copy, which matches the node
positions (see normalizeGeometry). Both follow coordinate
transformations and the scale factor. gs_geometry() returns the
working copy, or the raw copy with raw = TRUE. Setting a geometry
column updates both; invalid geometries are repaired with
sf::st_make_valid().
If name is already used by another node field, that field is
removed and replaced, with a warning; structural columns and coordinates
can't be replaced. Geometry columns can also be removed with
gs$name <- NULL.
Examples
library(RGraphSpace)
data("gtoy1", package = "RGraphSpace")
gs <- GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
# Add node shapes as a geometry column (requires the 'sf' package)
if (requireNamespace("sf", quietly = TRUE)) {
gs_geometry(gs) <- sfshape_ngons(n = gs_vcount(gs))
gs_geometry(gs)
# The raw copy, in the frame of gs_coords(gs, raw = TRUE)
gs_geometry(gs, raw = TRUE)
# A second column, under another name
gs_geometry(gs, name = "stars") <- sfshape_stars(n = gs_vcount(gs))
# Remove a geometry column
gs_geometry(gs, name = "stars") <- NULL
}