I have several thousand observations for which I have observation numbers that I would like to get location data for (state is sufficient). Anybody know how to do this? I can get them all into one filter view with a URL (&id=168701017,168358931,131737455…) but I cannot get the download export function to work. They are not in a specific project, not by one user, not in a specific geographic area, not of the same taxon, etc. They are all specimens submitted for DNA barcoding and I would love to be able to quickly get at least location but some other metadata would be interesting too. Is this a situation where I would either have to do this painstakingly slowly by manually getting this data or is this a situation where I have to try to figure out how to use the API which I might barely be able to stumble through and will probably take me even longer to figure out? If the latter, any pointers on iNat API for dummies or any other tools? r/inat seemed promising but doesn’t seem to do what I am wanting here (or at least not in a way a dummy like me can figure out).
I could possibly get them all if I can search by a field using a wildcard but I don’t know if this is possible. Something akin to field:Voucher%20Number(s)=OMDL* for OMDL00001, OMDL00002, OMDL00003, etc.
You’re most of the way there. The API returns a JSON file containing the structured data that can be queried using any programming tools that you’re familiar with. Your mention of rinat
suggests that you may be familiar with R
, so here’s some simple R code to give you some pointers.
library(jsonlite)
obs <- fromJSON("https://api.inaturalist.org/v1/observations?id=168701017,168358931,131737455")
#The GPS coordinates for each observation
obs$results$geojson$coordinates
#The name of the place stored with the observation
obs$results$place_guess
#The ID numbers of the iNaturalist places that the observations are contained within
obs$results$place_ids
#More details of the places can be retrieved using the places endpoint of the API
place_nums <- paste(unique(unlist(obs$results$place_ids)), collapse = ",")
place_url <- paste0("https://api.inaturalist.org/v1/places/", place_nums)
places <- fromJSON(place_url)
places$results[,c("id", "name")]
https://api.inaturalist.org/v1/docs is the place to find out more about the API. It provides a lot of helpful tools to learn how to query it.
Create a list of your ID’s in R, then use rinat get_inat_obs_id() in a loop of those ID’s to get the data for the ID, pull out what you need from the resulting data frame and move on to next ID.
Thank you @sdjbrown! This is very helpful and is really helping me understand the data structure here. I have pretty basic experience with r so I just try to stumble through and see if I can figure it out. I have run into a bit of a wall though in that the place_guess and place_ids values are not in the same order as the obs$results.id and I am not sure what order they are in as they do not match to the observation numbers. I know this is probably incredibly obvious to somebody who understands this better but alas I am no good at this.
Thanks so much for the help so far!
obs$results$id
should return the observation ID numbers in the same order as the others.
The three fields of interest can be combined into a single, smaller data frame which will make it easier to check that everything’s behaving the way you want it to.
place_df <- obs$results[, c('id', 'place_guess', 'place_ids')]
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.