Skip to contents

Generate positions from durations matrix, using PCoA to find the relative positions between points, then find the best fit between the source points and the image points using an affine or a Euclidean transformation.

Usage

dc_generate_positions_from_durations(
  durations,
  source_points,
  adjustment_type = "euclidean"
)

Arguments

durations

The durations matrix

source_points

The source points, an sf POINT object

adjustment_type

The adjustment type to use, either "euclidean" or "affine"

Value

A list object with the source points and the image points, ready to be used with the dc_create function

Examples

library(sf)

# Read source points
source_pts <- st_read(
  dsn = system.file("gpkg/data-prefecture.gpkg", package = "distanamo"),
  layer = "prefecture", quiet = TRUE
)

# Read the background layer to deform
background_layer <- st_read(
  dsn = system.file("gpkg/data-prefecture.gpkg", package = "distanamo"),
  layer = "departement", quiet = TRUE
)

# Read durations matrix
durations_mat <- read.csv(system.file("csv/mat.csv", package = "distanamo"), row.names = 1)

# Generate the positions from the whole duration matrix and
# adjust the result to the source points
pos_result <- dc_generate_positions_from_durations(
  durations = durations_mat,
  source_points = source_pts,
  adjustment_type = "euclidean"
)

# Display and plot useful information about the positioning step
plot(pos_result)

summary(pos_result)
#> Summary of the multipolar displacement result:
#> Min displacement: 2349.236 [m] 
#> Mean displacement: 34569.15 [m] 
#> Max displacement: 108405.5 [m] 
#> Transformation matrix:
#>      358.1063 1126.673 673162.7 
#>      -1170.315 396.8617 6619705 
#> Scale: 1208.994 
#> RMSE: 39842.59 
#> RMSE x: 25310.6 
#> RMSE y: 30770.21 

# Use the result of the positioning to create the interpolation grid
igrid <- dc_create(
  source_points = pos_result$source_points,
  image_points = pos_result$image_points,
  precision = 2.0,
  bbox = st_bbox(background_layer)
)

# Deform the background layer
background_deformed <- dc_interpolate(
  interpolation_grid = igrid,
  layer_to_deform = background_layer
)