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)

Using the queryAPI function

The queryAPI function grabs occurrence records using the Vermont Atlas of Life's API. See VAL's API guide here

Simple query

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")


VtEcostudies/VTatlas documentation built on Dec. 18, 2021, 6:20 p.m.