Keeps only the records or segments falling inside a rectangular area.
Usage
crop_to_bbox(x, bbox, coords = c("LONGITUDE", "LATITUDE"))Arguments
- x
A data frame with longitude and latitude columns, an
sfobject, or adistsamp_segmentsobject. For adistsamp_segmentsobject both thesegmentsandpointstables are cropped, the former on its midpoint.- bbox
Either a numeric vector with names
xmin,xmax,ymin,ymax, or an objectsf::st_bbox()understands.- coords
Names of the longitude and latitude columns, used for plain data frames. Defaults to
c("LONGITUDE", "LATITUDE"), falling back to the midpoint columns for a segment table.
Examples
path <- system.file("extdata", "narwc-example.csv", package = "distsamp")
dat <- 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.
gom <- c(xmin = -71, xmax = -66, ymin = 42, ymax = 45)
nrow(crop_to_bbox(dat, gom))
#> [1] 113