pleistodist_leastcost: Calculate least-cost distance between points over time

View source: R/calcmetrics.R

pleistodist_leastcostR Documentation

Calculate least-cost distance between points over time

Description

This function calculates the least-cost overland distance between each pairwise combination of user-specified points. By assigning exposed land a resistance value of 1 and submerged areas a resistance value of 999,999, this function calculates the shortest route between each pair of points that minimises the number of overwater crossings. If both points lie on the same landmass, a distance value of 0 is returned. If one or both islands is/are underwater, then a value of NA is returned. After calculating the pairwise least-cost distances for each interval, this function calculates the time-weighted average least-cost distance between each pair of points.

Usage

pleistodist_leastcost(points, epsg, intervalfile, mapdir, outdir)

Arguments

points

A user-generated multi-point shapefile (.shp) containing at least two points. If the shapefile attribute table contains a column labelled 'Name', the output distance matrix will use the identifiers in this column to label each pairwise comparison. Otherwise, the output distance matrix will use the attribute FID values instead.

epsg

The projected coordinate system in EPSG code format. Because of the curvature of the Earth's surface, we need to apply a map projection to accurately calculate straight-line distances between points instead of using the default WGS84 geographical coordinate system. Users should specify a projected coordinate system appropriate to the geographic region being analysed using the projection's associated EPSG code (https://epsg.org/home). Geographic coordinate system projections are not recommended as those will result in distance matrices calculated in decimal degrees rather than in distance units.

intervalfile

This is the master control file generated using either the getintervals_time() or getintervals_sealvl() functions, or custom generated by the user, that defines the number of intervals, the sea level at each interval, and the duration of each interval.

mapdir

The directory containing map outputs from the makemaps() function (i.e. the directory containing the raster_flat, raster_topo, and shapefile folders).

outdir

Output directory for the point-to-point least-cost distance matrix file. If the specified output directory doesn't already exist, PleistoDist will create the output directory.

Value

This function outputs a pairwise distance matrix of pairwise inter-island least shore-to-shore distances in long format, with one column per interval.

Examples


#create temp directory
path <- file.path(tempdir())
#create points shapefile
points <- sf::st_multipoint(rbind(c(178.68408,-16.82573), c(179.13585,-16.59487)))
#convert points to feature geometry
points <- sf::st_sfc(points)
points <- sf::st_cast(points, "POINT")
#set default projection (WGS84)
sf::st_crs(points) <- 4326
#save shapefile
sf::write_sf(points,paste0(path,"/points.shp"))
#load bathymetry file
fiji <- system.file("extdata","FJ.asc",package="PleistoDist")
#generate interval file for 2 intervals and 20 kya cutoff time, binning by time
getintervals_time(time=20,intervals=2,outdir=path)
#generate maps based on interval file, projecting map using EPSG:3141
makemaps(inputraster=fiji,epsg=3141,intervalfile=paste0(path,"/intervals.csv"),outdir=path)
#calculate inter-point least cost distances, projecting points using EPSG:3141
pleistodist_leastcost(points=paste0(path,"/points.shp"),epsg=3141,
    intervalfile=paste0(path,"/intervals.csv"),mapdir=path,outdir=path)


g33k5p34k/PleistoDistR documentation built on Oct. 9, 2022, 5:27 a.m.