sf_methods | R Documentation |
sf
methods for sfnetwork
objects.
## S3 method for class 'sfnetwork'
st_as_sf(x, active = NULL, focused = TRUE, ...)
## S3 method for class 'sfnetwork'
st_geometry(obj, active = NULL, focused = TRUE, ...)
## S3 replacement method for class 'sfnetwork'
st_geometry(x) <- value
## S3 method for class 'sfnetwork'
st_drop_geometry(x, ...)
## S3 method for class 'sfnetwork'
st_bbox(obj, active = NULL, ...)
## S3 method for class 'sfnetwork'
st_coordinates(x, active = NULL, ...)
## S3 method for class 'sfnetwork'
st_is(x, ...)
## S3 method for class 'sfnetwork'
st_is_valid(x, ...)
## S3 method for class 'sfnetwork'
st_as_s2(x, active = NULL, focused = TRUE, ...)
## S3 method for class 'sfnetwork'
st_crs(x, ...)
## S3 replacement method for class 'sfnetwork'
st_crs(x) <- value
## S3 method for class 'sfnetwork'
st_precision(x)
## S3 method for class 'sfnetwork'
st_set_precision(x, precision)
## S3 method for class 'sfnetwork'
st_shift_longitude(x, ...)
## S3 method for class 'sfnetwork'
st_transform(x, ...)
## S3 method for class 'sfnetwork'
st_wrap_dateline(x, ...)
## S3 method for class 'sfnetwork'
st_normalize(x, ...)
## S3 method for class 'sfnetwork'
st_zm(x, ...)
## S3 method for class 'sfnetwork'
st_m_range(obj, active = NULL, ...)
## S3 method for class 'sfnetwork'
st_z_range(obj, active = NULL, ...)
## S3 method for class 'sfnetwork'
st_agr(x, active = NULL, ...)
## S3 replacement method for class 'sfnetwork'
st_agr(x) <- value
## S3 method for class 'sfnetwork'
st_reverse(x, ...)
## S3 method for class 'sfnetwork'
st_segmentize(x, ...)
## S3 method for class 'sfnetwork'
st_simplify(x, ...)
## S3 method for class 'sfnetwork'
st_join(x, y, ..., ignore_multiple = TRUE)
## S3 method for class 'morphed_sfnetwork'
st_join(x, y, ...)
## S3 method for class 'sfnetwork'
st_filter(x, y, ...)
## S3 method for class 'morphed_sfnetwork'
st_filter(x, y, ...)
## S3 method for class 'sfnetwork'
st_crop(x, y, ...)
## S3 method for class 'morphed_sfnetwork'
st_crop(x, y, ...)
## S3 method for class 'sfnetwork'
st_difference(x, y, ...)
## S3 method for class 'morphed_sfnetwork'
st_difference(x, y, ...)
## S3 method for class 'sfnetwork'
st_intersection(x, y, ...)
## S3 method for class 'morphed_sfnetwork'
st_intersection(x, y, ...)
## S3 method for class 'sfnetwork'
st_intersects(x, y, ...)
## S3 method for class 'sfnetwork'
st_sample(x, ...)
## S3 method for class 'sfnetwork'
st_nearest_points(x, y, ...)
## S3 method for class 'sfnetwork'
st_area(x, ...)
x |
An object of class |
active |
Which network element (i.e. nodes or edges) to activate before
extracting. If |
focused |
Should only features that are in focus be extracted? Defaults
to |
... |
Arguments passed on the corresponding |
obj |
An object of class |
value |
The value to be assigned. See the documentation of the corresponding sf function for details. |
precision |
The precision to be assigned. See
|
y |
An object of class |
ignore_multiple |
When performing a spatial join with the nodes
table, and there are multiple matches for a single node, only the first one
of them is joined into the network. But what should happen with the others?
If this argument is set to |
See the sf
documentation. The following methods
have a special behavior:
st_geometry<-
: The geometry setter requires the replacement
geometries to have the same CRS as the network. Node replacements should
all be points, while edge replacements should all be linestrings. When
replacing node geometries, the boundaries of the edge geometries are
replaced as well to preserve the valid spatial network structure. When
replacing edge geometries, new edge boundaries that do not match the
location of their specified incident node are added as new nodes to the
network.
st_transform
: No matter if applied to the nodes or edge
table, this method will update the coordinates of both tables. The same
holds for all other methods that update the way in which the coordinates
are encoded without changing their actual location, such as
st_precision
, st_normalize
, st_zm
, and others.
st_join
: When applied to the nodes table and multiple matches
exist for the same node, only the first match is joined. A warning will be
given in this case. If ignore_multiple = FALSE
, multiple mathces
are instead added as isolated nodes to the returned network.
st_intersection
, st_difference
and st_crop
:
These methods clip edge geometries when applied to the edges table. To
preserve a valid spatial network structure, clipped edge boundaries are
added as new nodes to the network.
st_reverse
: When reversing edge geometries in a directed
network, the indices in the from and to columns will be swapped as well.
st_segmentize
: When segmentizing edge geometries, the edge
boundaries are forced to remain the same such that the valid spatial
network structure is preserved. This may lead to slightly inaccurate
results.
Geometric unary operations are only supported on sfnetwork
objects if they do not change the geometry type nor the spatial location
of the original features, since that would break the valid spatial network
structure. When applying the unsupported operations, first extract the
element of interest (nodes or edges) using st_as_sf
.
The methods for st_join
,
st_filter
, st_intersection
,
st_difference
and st_crop
, as well as
the methods for all setter functions and the geometric unary operations
preserve the class of the object it is applied to, i.e. either a
sfnetwork
object or its morphed equivalent. When dropping node
geometries, an object of class tbl_graph
is
returned. All other methods return the same type of objects as their
corresponding sf function. See the sf
documentation for
details.
library(sf, quietly = TRUE)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
net = as_sfnetwork(roxel)
# Extract the active network element as sf object.
st_as_sf(net)
# Extract any network element as sf object.
st_as_sf(net, "edges")
# Get the geometry of the active network element.
st_geometry(net)
# Get the geometry of any network element.
st_geometry(net, "edges")
# Replace the geometry of the nodes.
# This will automatically update edge geometries to match the new nodes.
newnet = net
newnds = rep(st_centroid(st_combine(st_geometry(net))), n_nodes(net))
st_geometry(newnet) = newnds
plot(net)
plot(newnet)
# Drop the geometries of the edges.
# This returns an sfnetwork with spatially implicit edges.
st_drop_geometry(activate(net, "edges"))
# Drop the geometries of the nodes.
# This returns a tbl_graph.
st_drop_geometry(net)
# Get the bounding box of the active network element.
st_bbox(net)
# Get CRS of the network.
st_crs(net)
# Get agr factor of the active network element.
st_agr(net)
# Get agr factor of any network element.
st_agr(net, "edges")
# Spatial join applied to the active network element.
net = st_transform(net, 3035)
codes = st_as_sf(st_make_grid(net, n = c(2, 2)))
codes$post_code = as.character(seq(1000, 1000 + nrow(codes) * 10 - 10, 10))
joined = st_join(net, codes, join = st_intersects)
joined
plot(net, col = "grey")
plot(codes, col = NA, border = "red", lty = 4, lwd = 4, add = TRUE)
text(st_coordinates(st_centroid(st_geometry(codes))), codes$post_code)
plot(st_geometry(joined, "edges"))
plot(st_as_sf(joined, "nodes"), pch = 20, add = TRUE)
par(oldpar)
# Spatial filter applied to the active network element.
p1 = st_point(c(4151358, 3208045))
p2 = st_point(c(4151340, 3207520))
p3 = st_point(c(4151756, 3207506))
p4 = st_point(c(4151774, 3208031))
poly = st_multipoint(c(p1, p2, p3, p4)) |>
st_cast('POLYGON') |>
st_sfc(crs = 3035) |>
st_as_sf()
filtered = st_filter(net, poly, .pred = st_intersects)
plot(net, col = "grey")
plot(poly, border = "red", lty = 4, lwd = 4, add = TRUE)
plot(filtered)
par(oldpar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.