Skip to contents

Dowloading observations

Get started quickly : Get Canis Lupus observations from Atlas

Observations within Atlas may be downloaded using the get_observations functions. To filter our request to the dataset, we will use the function get_taxa() to obtain first the Canis Lupus taxa data. We then use it as a filter to get observations and then display the first 10 records.

library(ratlas)
taxa <- get_taxa(scientific_name = "Canis lupus")
obs <- get_observations(id_taxa = taxa$id_taxa_obs)
head(obs, 10)

RAtlas functions expose Atlas data tables and related attributes. The observations table returned by the get_observations function already returns informations on the related dataset and taxonomy of an observations.

# Display first record as a vertical list
print(t(obs[1, ]))

Filter observation request using any table attributes

Any request may be filtered using any data attributes used as a data column in Atlas. For example, we will filter the original_source column to get only datasets related to the Placettes-échantillons permanentes datasets. We will then use the id values of those datasets to return only observations with the specified id_datasets and for the taxa associated to the sugar maple Acer saccharum.

Different tables can be joined using the base pipe |> and dplyr functions.

# Get dataset and taxa records for which we will filter observations
pep <- get_datasets(original_source = "Placettes-échantillons permanentes") |>
  dplyr::rename_with(~ paste0("ds.", .x))
taxa <- get_taxa(scientific_name = "Acer saccharum") |>
  dplyr::rename_with(~ paste0("taxa.", .x))

# Filter observation request through `id_taxa` and `id_datasets` and year values
obs <- get_observations(
  id_datasets = pep$ds.id,
  id_taxa = taxa$taxa.id_taxa_obs,
  year = 2018:2021)

print(glue::glue(
  "Found {nrow(obs)} observations between {min(obs$year_obs)} ",
  "and {max(obs$year_obs)}")
  )

# Print map of observations using the package `leaflet`

# install.packages("leaflet")
library(leaflet)
coord <- head(t(sapply(obs$geometry, as.list)), 100) # Only 100 records shown
colnames(coord) <- c("lng", "lat")

map <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng = as.numeric(coord[, "lng"]), lat = as.numeric(coord[, "lat"]))
map