View source: R/das_intersects_strata.R
| das_intersects_strata | R Documentation |
Determine if swfscDAS outputs intersect with strata polygons
das_intersects_strata(x, ...)
## S3 method for class 'list'
das_intersects_strata(x, strata.files, ...)
## S3 method for class 'data.frame'
das_intersects_strata(
x,
strata.files,
x.lon = "Lon",
x.lat = "Lat",
strata.which = FALSE,
...
)
x |
a data frame (such as an object of class |
... |
ignored |
strata.files |
list of path(s) of the CSV file(s) with points defining each stratum. The CSV files must contain headers and be a closed polygon. The list may be named; see 'Value' section for how these names are used |
x.lon |
character; name of the longitude column of |
x.lat |
character; name of the latitude column of |
strata.which |
logical; indicates if the numeric column 'strata_which' should
be included in the output data frame.
Ignored if |
Assigns DAS event points or segment midpoints to strata polygons using
sf::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.
If x is a data frame, then 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 strata.files; the
element(s) of strata.files will have the name InPoly#, where '#' is
the index of that stratum polygon in strata.files. If
strata.which, then the column 'strata_which' is added to the end of
the data frame. This column contains either a 0 if the point intersects with
no strata or 2) a numeric indicating the index (in strata.files) of
the (first) strata polygon that the point intersects with.
Otherwise, i.e. if x is a list and thus 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.
y <- system.file("extdata", "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("extdata", "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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.