More structured place information from the observation API

It looks like the observation API returns two pieces of data about where an observation was made:

  • The “place_guess” which is just a string (and could be in any language)
  • A simple list of “place_ids”, with no organization

If I want to find out, for example, which country an observation was made in, it seems I have to query all of the place IDs in the list (which could be dozens) and see which one has admin_level 0. It would be really nice if the standard place levels were included in the initial observation API response or perhaps as an optional set of data invoked using the ‘extra’ parameter (e.g. ‘extra=places’). The response key pairs could look something like:
“continent”: 97394,
“country”: 1,
“admin_level_1”: 42,
“admin_level_2”: 913,

(assuming that admin level -1 is always a continent and admin level 0 is always a country).

For context, this is mainly needed for the iNaturalist2Commons tool, so that it can list where the photo was taken.

Strongly support this request. Additionally, are the geocoordinates and accuracy not exposed in this API method?

The coordinates are in a field called coordinates and the accuracy is in a field called positional_accuracy.

Is it actually useful to you to get those place IDs back, or would you actually prefer something more like

"continent": "Asia",
"country": "India"

in the observation search response? If you do want more of that place detail, or you want to consolidate place detail retrieval into one request per batch of observations, what if we added an admin_level param to the places detail endpoint, so your place request could look something like https://api.inaturalist.org/v1/places/1,2,3,4,5,6,7?admin_level=-1,0,1,2?

I’m a little hesitant to add to the observation search responses, which are already kind of like Tetsuo at the end of Akira. @pleary may have thoughts on this too.

1 Like

@zygy, not sure if you’re getting notifications from the Forum but would something like https://api.inaturalist.org/v1/places/1,2,3,4,5,6,7?admin_level=-1,0,1,2 (i.e. altering the places API to fetch only “standard” places) work for you here?

1 Like

@kueda - Sorry for the delayed response. Yes, your suggestion would be a nice improvement and would make dealing with the place data for an observation easier.

1 Like

looks like this has been implemented. see https://github.com/inaturalist/iNaturalistAPI/issues/211.

@kueda: I am trying to use the admin_level parameter for the places API endpoint to restrict results to certain admin levels. It seems like it’s not working as intended, at least as I understand it.

Your example https://api.inaturalist.org/v1/places/1,2,3,4,5,6,7?admin_level=-1,0,1,2 should be returning 7 results: 6 admin level 1 (states) and 1 admin level 0 (country). Yet, it only returns one result: that for United States (id: 1). No matter how I configure it, I can’t seem to get anything more than countries out (admin level 0) with the admin_level parameter included.

1 Like

i believe there was a change a while back to make states admin code = 10. similar changes apply to counties and continent admin codes, if i remember correctly.

2 Likes

That’s correct, multiply everything by 10, https://api.inaturalist.org/v1/places/1,2,3,4,5,6,7?admin_level=-10,0,10,20

1 Like

Oh, perfect! Thank you @pisum and @jwidness.

1 Like