swfscDAS (version 0.4.0)

das_intersects_strata: DAS strata - points

Description

Determine if swfscDAS outputs intersect with strata polygons

Usage

das_intersects_strata(x, ...)

# S3 method for list das_intersects_strata(x, y, ...)

# S3 method for data.frame das_intersects_strata(x, y, x.lon = "Lon", x.lat = "Lat", ...)

Arguments

x

a data frame (such as an object of class das_df) or a list. If x is a list, then it must be the output of das_effort or das_effort_sight. If x is a data frame, the user must also specify the coordinate columns of x using x.lon and x.lat

...

ignored

y

list of file path(s) of the CSV(s) that contain points defining each stratum. The list may be named; see 'Value' section for how these names are used

x.lon

character; name of the longitude column of x. Ignored if x is a list; default is "Lon"

x.lat

character; name of the latitude column of x. Ignored if x is a list; default is "Lat"

Value

Logical columns are added to x indicating if each point intersected with the corresponding stratum polygon. The names of these columns are the names of y; the element(s) of y will have the name InPoly#, where '#' is the index of that stratum polygon in y.

If x is a list (meaning the output of one of the effort functions), then the stratum columns are added to both the segdata and sightinfo data frames. However, note that the columns added to the sightinfo data frame still indicate whether or not the segment midpoint was in the corresponding stratum, rather than the sighting point itself.

Details

Assigns DAS event points or segment midpoints to strata polygons using st_intersects.

If x is a list, then 1) it must be the output of das_effort or das_effort_sight and 2) the segment midpoints (column names mlon and mlat, respectively) are the points checked if they intersect with each provided stratum. If x is a data frame, then the user must provide the columns that specify the point coordinates to check.

x should not be an object of class das_dfr, or an object of class das_df created with add.dtll.sight = FALSE, because the ? and numeric event codes will have NA latitude and longitude values.

Examples

Run this code
# NOT RUN {
y <- system.file("das_sample.das", package = "swfscDAS")
y.proc <- das_process(y)
y.eff <- das_effort(y.proc, method = "section", num.cores = 1)

stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS")
das_intersects_strata(y.eff, list(InPoly = stratum.file), x.lon = "Lon", x.lat = "Lat")

das_intersects_strata(y.proc, list(stratum.file))

# Visualize effort midpoints and stratum polygon
require(sf)
y.eff.strata <- das_intersects_strata(y.eff, list(InPoly = stratum.file))
segdata <- st_as_sf(y.eff.strata$segdata, coords = c("mlon", "mlat"), crs = 4326)

# Make stratum polygon
stratum.df <- read.csv(stratum.file)
stratum.sfc <- st_sfc(
  st_polygon(list(matrix(c(stratum.df$Lon, stratum.df$Lat), ncol = 2))),
  crs = 4326
)

plot(segdata["InPoly"], axes = TRUE, reset = FALSE,
     xlim = c(-137, -142.5), ylim = c(42, 47))
plot(stratum.sfc, add = TRUE)

# }

Run the code above in your browser using DataLab