Open code

Minimum marine distances along coastlines

An implementation to determine minimum marine distances between coordinate points along coastlines.

Unlike measuring pairwise terrestrial distances, marine distances need to account for landmasses, which cannot be crossed. Marine distances are a crucial predictor in genetics to build isolation by distance models. These measure gene frequencies variation under increasing geographic distances.

When marine distances are plotted against pairwise genetic differentation levels, a linear relationship is expected. Here we provide a straightforward R script to determine minimum marine distances.

  • How it works

A high-resolution polygon representing global landmasses is converted into an infinite resistance surface. Minimum distances between sites are computed with a shortest path algorithm considering the (infinite) resistance of landmasses and null resistance throughout the marine surface.

The outcome of the following code is a matrix of pairwise distances, a figure to visualize if sites are well represented in the surface area and a figure depicting an example of a minimum marine distance.

  • Prerequisites

High resolution polygon depicting the surface of the world (e.g., Global Self-consistent Hierarchical High-resolution Shorelines;

# Source the main function

# Read the landmass polygon
global.polygon <- "Global_CostLine_HD_Polygon.shp"

## Run the function
contour( global.polygon = global.polygon , file= "Data/sampling_sites.txt" , file.sep = ";" , file.dec = "." , file.strucutre = 1 , file.header = FALSE , resolution = 0.01 , buffer = c(1,1,1,1) , export.file = TRUE )

## file : the main file with the locations; should be text delimited
## global.polygon: the path of the polygon
## file.strucutre: the main file structure: 1 to “Name Lon Lat” or 2 to “Name Lat Lon”
## file.header: define if the text file has a header with the column names (TRUE or FALSE)
## resolution: the resolution of the study area and the buffer to use around the sites.
## buffer: the buffer can be a simple value or a vector such as c(xmin,xmax,ymin,ymax).
## export.file: file to export the results as a text delimited file (TRUE or FALSE)

Main reference

Assis, J., Castilho Coelho, N., Alberto, F., Valero, M., Raimondi, P., Reed, D., Serrão, E. A. (2013). High and Distinct Range-Edge Genetic Diversity despite Local Bottlenecks. PLoS ONE, 8(7), e68646.

  • Featured code
Downloading biodiversity records from iNaturalist

Automatically download biodiversity records from iNaturalist, the most recognised citizen science initiative.

Marine climate layers for ecological modelling

High-resolution marine data layers to model the distribution of species at global scales.


Jorge Assis [PhD, Associate Researcher]
Centre of Marine Sciences, University of Algarve [Faro, Portugal]
© 2023 Biodiversity Data Science, All Rights Reserved