migration distance - calculating the migration distance for a species

This function is in the compiled package ‘RDH’, available on my GitHub page

The following are the required packages for this function:

library(maptools)
## Loading required package: sp
## Checking rgeos availability: TRUE
library(sp)
library(fossil)
## Loading required package: maps
## 
##  # ATTENTION: maps v3.0 has an updated 'world' map.        #
##  # Many country borders and names have changed since 1990. #
##  # Type '?world' or 'news(package="maps")'. See README_v3. #
## Loading required package: shapefiles
## Loading required package: foreign
## 
## Attaching package: 'shapefiles'
## The following objects are masked from 'package:foreign':
## 
##     read.dbf, write.dbf
library(rgeos)
## rgeos version: 0.3-19, (SVN revision 524)
##  GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921 
##  Linking to sp version: 1.2-3 
##  Polygon checking: TRUE

In this example I will be using range data for the Blue-winged Warbler (Vermivora cyanoptera)

shp <- readShapeSpatial("Vermivora_cyanoptera_9085_NS.shp")

The range data for this species is broken down into breeding, wintering and non-breeding:

plot(shp, col=c("red","blue","red","purple","purple","blue","blue"))
map('world', add=T)
legend(-65, 35, c("Breeding","Non-Breeding", "Wintering"),pch=rep(15, 3), col=c("red", "purple", "blue"))
map.axes()

For this function we are interested in the distance between the breeding and wintering areas of the range. The non-breeding part of the range is where the species passes through on its migratory route, and is not always listed (see the species range data visualized on the IUCN webpage).

This function calculates the distance between the midpoint of the breeding range and the midpoint of the wintering range, with additional information returned, nd is run in the following manner:

source("migration.distance.R")

migration.distance(shp)
##                Species Breeding Range Size Wintering Range Size
## 1 Vermivora cyanoptera            188.1241             64.54852
##   Breeding Range Centroid X Breeding Range Centroid Y
## 1                 -86.05498                  39.80874
##   Wintering Range Centroid X Wintering Range Centroid Y Migration Distance
## 1                  -88.31543                   16.09659           2646.501