eco_region: Filter points within ecoregions

Description Usage Arguments Details Value dataset options region options Examples

View source: R/ecoregion.R

Description

Filter points within ecoregions

Usage

1
2
3
4
5
eco_region(x, dataset = "meow", region, lat = NULL, lon = NULL, drop = TRUE)

regions_meow()

regions_fao()

Arguments

x

(data.frame) A data.frame

dataset

(character) the dataset to use. one of: "meow" (Marine Ecoregions of the World), "fao" (). See Details.

region

(character) one or more region names. has the form a:b where a is a variable name (column in the sf object) and b is the value you want to filter to within that variable. See Details.

lat, lon

(character) name of the latitude and longitude column to use

drop

(logical) Drop bad data points or not. Either way, we parse out bad data points as an attribute you can access. Default: TRUE #param ignore.na (logical) To consider NA values as a bad point or not. Default: FALSE

Details

see scrubr_cache for managing the cache of data

Value

Returns a data.frame, with attributes

dataset options

region options

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
if (requireNamespace("mapview") && requireNamespace("sf") && interactive()) {
## Marine Ecoregions of the World
wkt <- 'POLYGON((-119.8 12.2, -105.1 11.5, -106.1 21.6, -119.8 20.9, -119.8 12.2))'
res <- rgbif::occ_data(geometry = wkt, limit=300)$data
res2 <- sf::st_as_sf(res, coords = c("decimalLongitude", "decimalLatitude"))
res2 <- sf::st_set_crs(res2, 4326)
mapview::mapview(res2)
tmp <- eco_region(dframe(res), dataset = "meow",
   region = "ECOREGION:Mexican Tropical Pacific")
tmp2 <- sf::st_as_sf(tmp, coords = c("decimalLongitude", "decimalLatitude"))
tmp2 <- sf::st_set_crs(tmp2, 4326)
mapview::mapview(tmp2)
## filter many regions at once
out <- eco_region(dframe(res), dataset = "meow",
   region = c("ECOREGION:Mexican Tropical Pacific", "ECOREGION:Seychelles"))
out
out2 <- sf::st_as_sf(out, coords = c("decimalLongitude", "decimalLatitude"))
out2 <- sf::st_set_crs(out2, 4326)
mapview::mapview(out2)

## FAO
## FIXME - this needs fixing, broken
wkt <- 'POLYGON((72.2 38.5,-173.6 38.5,-173.6 -41.5,72.2 -41.5,72.2 38.5))'
manta_ray <- rgbif::name_backbone("Mobula alfredi")$usageKey
res <- rgbif::occ_data(manta_ray, geometry = wkt, limit=300, hasCoordinate = TRUE)
dat <- sf::st_as_sf(res$data, coords = c("decimalLongitude", "decimalLatitude"))
dat <- sf::st_set_crs(dat, 4326)
mapview::mapview(dat)
tmp <- eco_region(dframe(res$data), dataset = "fao", region = "OCEAN:Indian")
tmp <- tmp[!is.na(tmp$decimalLongitude), ]
tmp2 <- sf::st_as_sf(tmp, coords = c("decimalLongitude", "decimalLatitude"))
tmp2 <- sf::st_set_crs(tmp2, 4326)
mapview::mapview(tmp2)
}
## End(Not run)

scrubr documentation built on June 12, 2021, 9:06 a.m.