knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
spplit
allows you query species occurrence data sources in a variety of ways. One of them
is via a geospatial definition. This geospatial definition can be a variety of different
things:
While GBIF allows only WKT submitted to their API, the user here can pass in all the things above, and we internally convert to WKT.
While iDigBio allows only a bounding box submitted to their API, the user here can pass in all the things above, and we internally convert to a bounding box.
Thus, as you can pass a detailed and complex WKT geospatial definition to GBIF and it will get passed directlty to GBIF, that same complex WKT when passed to iDigBio will first be simplified to a bounding box.
A bounding box is a simple numeric vector of length 4, with the following format:
[min-longitude, min-latitude, max-longitude, max-latitude]
An example in R:
c(-120, 40, -100, 45)
where -120 is the min longitude, 40 is the min latitude, -100 is the max longitude and 45 is the max latitude.
You can pass a bounding box to the geometry
parameter in sp_occ_gbif()
, or
sp_occ_idigbio()
.
WKT is a text string, and is defined by a set of spatial classes. Check out the Wikipedia entry on WKT for more info (https://en.wikipedia.org/wiki/Well-known_text).
The only type of WKT class you can use here is POLYGON
. Other classes are defined in WKT,
but GBIF doesn't support any other class.
A simple example of a WKT string of a POLYGON
class is:
POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))
You can pass a WKT string for a POLYGON
to the geometry
parameter in sp_occ_gbif()
, or
sp_occ_idigbio()
.
An easy to use website for getting WKT after drawing a shape on a map is http://arthur-e.github.io/Wicket/sandbox-gmaps3.html.
You can get WKT from within R using the wellknown
package https://cran.r-project.org/package=wellknown. With wellknown
you can get
WKT from R objects, and convert GeoJSON to WKT as well. For example:
df <- us_cities[2:5,c('long','lat')] df <- rbind(df, df[1,]) polygon(df, fmt=2) #> [1] "POLYGON ((-81.52 41.08, -122.26 37.77, -84.18 31.58, -73.80 42.67, -81.52 41.08))"
SpatialPolygons
and SpatialPolygonsDataFrame
are two classes of object defined in the package sp
(https://cran.r-project.org/package=sp).
There are other object types defined in sp
, but only these two are supported here.
We take those inputs internally and convert to a WKT for GBIF or a bounding box for
iDigBio.
You can create a SpatialPolygons
object like:
library("sp") poly <- SpatialPolygons(list(Polygons(list(Polygon(cbind( c(-124.07, -119.99, -119.99, -124.07, -124.07), c(41.48, 41.48, 35.57, 35.57, 41.48) ))), "s1")), 1L) class(poly)
Then use the SpatialPolygons
class object for a geometry based search:
library("spplit") sp_occ_gbif(geometry = poly, limit = 10)
Same goes for SpatialPolygonsDataFrame
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.