knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Download the package and load the library
# this only needs to be run if: # 1) downloading for the first time # 2) updating to get new functions devtools::install_github("VtEcostudies/VTatlas", ref = "main")
library(VTatlas)
queryAPI
functionThe queryAPI
function grabs occurrence records using the Vermont Atlas of Life's API.
See VAL's API guide here
Below is a simple query where we return all the records that have 'Odonata' in the order field.
by default the function returns all the records. One could limit the amount of
records that are returned by setting the pageSize
argument. If a
pageSize
set by the user is larger than the number of observations
the data frame returned will be filled with NAs.
Odonata <- queryAPI(query = list('order:Odonata')) head(Odonata[,1:5])
Manually set pageSize.
Odonata_1000 <- queryAPI(query = list('order:Odonata', pageSize = 1000)) tail(Odonata_1000[,1:5])
Spatial query
data(towns)# <- sf::st_read("data-raw/VTtownsWGS84.shp") wkt_text <- sf::st_as_text(sf::st_geometry(towns[towns$TOWNNAME=="BENNINGTON",]))
Od_BEN <- queryAPI(query = list('order:Odonata'), spatialWKT = wkt_text)
par(mar = c(0,0,0,0)) plot(sf::st_geometry(towns), border = "gray") plot(sf::st_geometry(towns[towns$TOWNNAME=="BENNINGTON",]), add = TRUE, col = "gray") points(Od_BEN$decimalLatitude~Od_BEN$decimalLongitude, pch = 20, col = "red") points(Odonata$decimalLatitude~Odonata$decimalLongitude, pch = ".") legend('bottomright', legend = c("Odonata observations", "Bennington observations"), pch = c(20,20), col = c('black','red'), bty = "n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.