play_spatial: Create random spatial networks

play_spatialR Documentation

Create random spatial networks

Description

Random spatial networks are created by randomly sampling nodes within a given area, and connecting them by edges according to a specified method.

Usage

play_geometric(
  n,
  radius,
  bounds = NULL,
  edges_as_lines = TRUE,
  compute_length = FALSE,
  ...
)

Arguments

n

The number of nodes to be sampled.

radius

The radius within which nodes will be connected by an edge.

bounds

The spatial features within which the nodes should be sampled as object of class sf, sfc, sfg or bbox. If set to NULL, nodes will be sampled within a unit square.

edges_as_lines

Should the created edges be spatially explicit, i.e. have LINESTRING geometries stored in a geometry list column? Defaults to TRUE.

compute_length

Should the geographic length of the edges be stored in a column named length? Uses st_length to compute the length of the edge geometries when edges are spatially explicit, and st_distance to compute the distance between boundary nodes when edges are spatially implicit. Please note that the values in this column are not automatically recognized as edge weights. This needs to be specified explicitly when calling a function that uses edge weights. Defaults to FALSE.

...

Additional arguments passed on to st_sample. Ignored if bounds = NULL.

Functions

  • play_geometric(): Creates a random geometric graph. Two nodes will be connected by an edge if the distance between them is within the given radius. If nodes are sampled on a unit square (i.e. when bounds = NULL) this radius is unitless. If bounds are given as a spatial feature, the radius is assumed to be in meters for geographic coordinates, and in the units of the coordinate reference system for projected coordinates. Alternatively, units can also be specified explicitly by providing a units object.

Examples

library(sf, quietly = TRUE)

oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1))

# Sample 10 nodes on a unit square
# Connect nodes by an edge if they are within 0.25 distance from each other
net = play_geometric(10, 0.25)
net

plot(net)

# Sample 10 nodes within a spatial bounding box
# Connect nodes by an edge if they are within 1 km from each other
net = play_geometric(10, units::set_units(1, "km"), bounds = st_bbox(roxel))
net

plot(net)

par(oldpar)


luukvdmeer/sfnetworks documentation built on Nov. 21, 2024, 4:54 a.m.