Converts an edge list to an sf
spatial object of type LINESTRING
with
one row per edge.
edges_to_sf(edges, sites)
a data.frame
with the following two columns: from
(the
first node of the edge) and to
(the second node of the edge). The output
of the functions create_edge_list()
or append_edge_lists()
.
an sf
object of type POINT
. A spatial object with
coordinates of sites (nodes). Note that the first column must be the
node labels.
An sf
spatial object of type LINESTRING
where the number of rows
correspond to the number of edges.
# Import Adour sites ----
path_to_file <- system.file("extdata", "adour_survey_sampling.csv",
package = "chessboard")
adour_sites <- read.csv(path_to_file)
# Select first location ----
adour_sites <- adour_sites[adour_sites$"location" == 1, ]
# Create node labels ----
adour_nodes <- create_node_labels(data = adour_sites,
location = "location",
transect = "transect",
quadrat = "quadrat")
# Find edges with 1 degree of neighborhood (pawn method) ----
adour_edges <- create_edge_list(adour_nodes, method = "pawn",
directed = TRUE)
# Convert sites to spatial POINT ----
adour_sites_sf <- sf::st_as_sf(adour_nodes, coords = 5:6, crs = "epsg:2154")
# Convert edges to spatial LINESTRING ----
edges_sf <- edges_to_sf(adour_edges, adour_sites_sf)
head(edges_sf)
#> Simple feature collection with 6 features and 2 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 470209.3 ymin: 6221518 xmax: 476347 ymax: 6230758
#> Projected CRS: RGF93 v1 / Lambert-93
#> from to geometry
#> 1 1-1 1-2 LINESTRING (474036.9 622151...
#> 2 1-2 1-3 LINESTRING (473080 6223828,...
#> 3 1-3 1-4 LINESTRING (472123.1 622613...
#> 4 1-4 1-5 LINESTRING (471166.2 622844...
#> 5 2-1 2-2 LINESTRING (476347 6222475,...
#> 6 2-2 2-3 LINESTRING (475390.1 622478...
# Visualization ----
plot(sf::st_geometry(adour_sites_sf), pch = 19)
plot(sf::st_geometry(edges_sf), add = TRUE)
# Find edges with 1 degree of neighborhood (pawn and bishop methods) ----
adour_edges_1 <- create_edge_list(adour_nodes, method = "pawn",
directed = TRUE)
adour_edges_2 <- create_edge_list(adour_nodes, method = "bishop",
directed = TRUE)
# Append edges ----
adour_edges <- append_edge_lists(adour_edges_1, adour_edges_2)
# Convert sites to spatial POINT ----
adour_sites_sf <- sf::st_as_sf(adour_nodes, coords = 5:6, crs = "epsg:2154")
# Convert edges to spatial LINESTRING ----
edges_sf <- edges_to_sf(adour_edges, adour_sites_sf)
head(edges_sf)
#> Simple feature collection with 6 features and 2 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 471166.2 ymin: 6221518 xmax: 475390.1 ymax: 6229405
#> Projected CRS: RGF93 v1 / Lambert-93
#> from to geometry
#> 1 1-1 1-2 LINESTRING (474036.9 622151...
#> 2 1-1 2-2 LINESTRING (474036.9 622151...
#> 3 1-2 1-3 LINESTRING (473080 6223828,...
#> 4 1-2 2-3 LINESTRING (473080 6223828,...
#> 5 1-3 1-4 LINESTRING (472123.1 622613...
#> 6 1-3 2-4 LINESTRING (472123.1 622613...
# Visualization ----
plot(sf::st_geometry(adour_sites_sf), pch = 19)
plot(sf::st_geometry(edges_sf), add = TRUE)