as_sfnetwork | R Documentation |
Convert a given object into an object of class sfnetwork
.
If an object can be read by as_tbl_graph
and the
nodes can be read by st_as_sf
, it is automatically
supported.
as_sfnetwork(x, ...)
## Default S3 method:
as_sfnetwork(x, ...)
## S3 method for class 'sf'
as_sfnetwork(x, ...)
## S3 method for class 'linnet'
as_sfnetwork(x, ...)
## S3 method for class 'psp'
as_sfnetwork(x, ...)
## S3 method for class 'sfc'
as_sfnetwork(x, ...)
## S3 method for class 'sfNetwork'
as_sfnetwork(x, ...)
## S3 method for class 'sfnetwork'
as_sfnetwork(x, ...)
## S3 method for class 'tbl_graph'
as_sfnetwork(x, ...)
x |
Object to be converted into an |
... |
Arguments passed on to the |
An object of class sfnetwork
.
as_sfnetwork(sf)
: Only sf objects with either exclusively geometries
of type LINESTRING
or exclusively geometries of type POINT
are
supported. For lines, is assumed that the given features form the edges.
Nodes are created at the endpoints of the lines. Endpoints which are shared
between multiple edges become a single node. For points, it is assumed that
the given features geometries form the nodes. They will be connected by
edges sequentially. Hence, point 1 to point 2, point 2 to point 3, etc.
# From an sf object.
library(sf, quietly = TRUE)
# With LINESTRING geometries.
as_sfnetwork(roxel)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
plot(st_geometry(roxel))
plot(as_sfnetwork(roxel))
par(oldpar)
# With POINT geometries.
p1 = st_point(c(7, 51))
p2 = st_point(c(7, 52))
p3 = st_point(c(8, 52))
points = st_as_sf(st_sfc(p1, p2, p3))
as_sfnetwork(points)
oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
plot(st_geometry(points))
plot(as_sfnetwork(points))
par(oldpar)
# From a linnet object.
if (require(spatstat.geom, quietly = TRUE)) {
as_sfnetwork(simplenet)
}
# From a psp object.
if (require(spatstat.geom, quietly = TRUE)) {
set.seed(42)
test_psp = psp(runif(10), runif(10), runif(10), runif(10), window=owin())
as_sfnetwork(test_psp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.