Skip to contents

Create haul level trip distance variable

Usage

create_trip_distance(
  dat,
  project,
  port,
  trip_id,
  starting_port,
  starting_haul = c("Lon", "Lat"),
  ending_haul = c("Lon", "Lat"),
  ending_port,
  haul_order,
  name = "TripDistance",
  a = 6378137,
  f = 1/298.257223563
)

Arguments

dat

Primary data containing information on hauls or trips. Table in the FishSET database contains the string 'MainDataTable'.

project

Project name.

port

Port data frame. Contains columns: Port_Name, Port_Long, Port_Lat. Table is generated using the load_port function and saved in the FishSET database as the project and port, for example 'pollockPortTable'.

trip_id

Unique trip identifier in dat.

starting_port

Variable in dat containing ports at the start of the trip.

starting_haul

Character string, variables containing latitude and longitude at start of haul in dat.

ending_haul

Character string, variables containing latitude and longitude at end of haul in dat.

ending_port

Variable in dat containing ports at the end of the trip.

haul_order

Variable in dat that identifies haul order within a trip. Can be time, coded variable, etc.

name

String, name of created variable. Defaults to `TripDistance`.

a

Numeric, major (equatorial) radius of the ellipsoid. The default value is for WGS84 ellipsoid.

f

Numeric, ellipsoid flattening. The default value is for WGS84 ellipsoid.

Value

Returns the primary dataset with a trip distance variable added.

Details

Summation of distance across a trip based on starting and ending ports and hauls in between. The function uses distGeo from the geosphere package to calculate distances between hauls. Inputs are the trips, ports, and hauls from the primary dataset, and the latitude and longitude of ports from the port. The ellipsoid arguments, a and f, are numeric and can be changed if an ellipsoid other than WGS84 is appropriate. See the geosphere R package for more details (https://cran.r-project.org/web/packages/geosphere/geosphere.pdf).

Examples

if (FALSE) {
pcodMainDataTable <- create_trip_distance(pcodMainDataTable, "pcod", "pcodPortTable", 
  "TRIP_SEQ", "DISEMBARKED_PORT", c("LonLat_START_LON", "LonLat_START_LAT"),
  c("LonLat_END_LON", "LonLat_END_LAT"), "EMBARKED_PORT", "HAUL_SEQ", "TripDistance"
)
}

#