library(rinat)
library(dplyr)
library(lubridate)
library(sf)
library(mapview)
library(leafpop)Tarawi Nature Reserve
R
rinat
mapview
NSW
Tools and Libraries
I will be using R with the following selection of libraries in this blog post:
I use the library here to manage relative paths of the project:
here::i_am("regions/Kiama-walk.qmd")here() starts at /Users/z3529065/proyectos/CES/code-4-iNat
I save the downloaded inat data into this data folder at the root of the project folder:
if (!dir.exists(here::here("data")))
dir.create(here::here("data"))
inat_obs_data <- here::here("data", "inat-obs.rds")This will query all the observations from my iNaturalist user. I will save this to a data folder:
if (file.exists(inat_obs_data)) {
user_obs <- readRDS(inat_obs_data)
} else {
user_obs <- get_inat_obs_user("NeoMapas",maxresults = 5000) |>
mutate(dts=date(datetime), year=year(dts), month=month(dts))
saveRDS(user_obs, inat_obs_data)
}I can make this object spatially explicit using the function st_to_sf from package sf:
user_obs_xy <- st_as_sf(user_obs,coords=c("longitude","latitude"), crs=4326)For this post, I am focusing on the observation made on the 9 March 2025:
tarawi_obs <- filter(user_obs_xy,
dts %in% c(
"2024-04-04", "2024-04-05", "2024-04-06",
"2024-04-07", "2024-04-08", "2024-04-09",
"2024-04-10"))This is the number of observations for that day:
nrow(tarawi_obs)[1] 51
And this is the approximate number of species (or other taxa) included in those observations:
n_distinct(tarawi_obs$species_guess)[1] 37
A quick map with the default image of each observation can be made with mapview:
mapview(tarawi_obs,
map.types = c("OpenStreetMap.DE", "Esri.WorldImagery","CyclOSM"),
layer.name = c("Obs from Tarawi NR"),
popup =
popupImage(tarawi_obs$image_url, src = "remote"))That’s fantastic!