Estimates the direction the aircraft was flying at each record, from the positions logged either side of it on the same survey line.
Arguments
- dat
A data frame with
LATITUDEandLONGITUDE, in survey order.- by
Character vector of columns identifying one continuous occupation of a survey line.
NULL(default) picksc("FILEID", "LEGNO3")ifmake_leg_id()has been run, thenc("FILEID", "LEGNO"), then"FILEID", and prependsDATEto whichever it picks when that column is present. Getting this wrong joins the end of one line to the start of the next and produces a bearing that belongs to neither — which is whyDATEis included: two days sharing aLEGNOare separated byFILEIDalone, and some extracts carry a constantFILEID.- track_rows
Logical vector marking the records that define the track.
NULL(default) uses the census records,LEGTYPE == 2, whenLEGTYPEis present. Circling and transit positions must be excluded: an aircraft orbiting a whale has a bearing, but it is not the track-line's.
Value
A numeric vector of bearings in degrees, one per row of dat, NA
for records that do not define a track.
How the bearing is taken
Consecutive records often share a position — a sighting is logged at the same latitude and longitude as the routine position it follows (handbook 4.2) — and a bearing between two identical points is undefined. Records are therefore collapsed into runs of distinct positions first, and the bearing for a run is taken from the previous distinct position to the next one. That centred difference is less sensitive to a single jittery fix than a forward difference. At the first and last position of a line, where there is only one neighbour, the one-sided difference is used.
A line with only one distinct position has no direction, and gets NA.
Examples
path <- system.file("extdata", "narwc-example.csv", package = "distsamp")
dat <- make_leg_id(read_narwc(path))
#> `read_narwc()` renamed 2 columns:
#> LAT_DD -> LATITUDE
#> LONG_DD -> LONGITUDE
#> All matched an exact entry in the alias table; `narwc_column_mapping()` returns this, and `quiet = TRUE` silences it.
# The fixture's lines all run due north
unique(round(track_bearing(dat)))
#> [1] NA 0