Computes the Euclidean distance between two nodes using the function sf::st_distance(). If the CRS is not a Cartesian system, the Great Circle distance will be used instead.

distance_euclidean(sites, ...)

Arguments

sites

an sf object of type POINT. A spatial object containing coordinates of sites. Note that the first column must be the node label created by the function create_node_labels().

...

other argument to pass to sf::st_distance().

Value

A three-column data.frame with:

  • from, the first node

  • to, the second node

  • weight, the Euclidean distance between the two nodes

Examples

# Import Adour sites ----
path_to_file <- system.file("extdata", "adour_survey_sampling.csv", 
                            package = "chessboard")
adour_sites <- read.csv(path_to_file)

# Select the 15 first sites ----
adour_sites <- adour_sites[1:15, ]

# Create node labels ----
adour_sites <- create_node_labels(adour_sites, 
                                  location = "location", 
                                  transect = "transect", 
                                  quadrat  = "quadrat")

# Convert sites to sf object (POINTS) ----
adour_sites <- sf::st_as_sf(adour_sites, coords = c("longitude", "latitude"),
                            crs = "epsg:2154")

# Compute distances between pairs of sites ----
weights <- distance_euclidean(adour_sites)

head(weights)
#>   from  to    weight
#> 1  1-1 1-1     0.000
#> 2  1-1 1-2  2500.469
#> 3  1-1 1-3  5000.938
#> 4  1-1 1-4  7501.407
#> 5  1-1 1-5 10001.876
#> 6  1-1 2-1  2500.469