I have a custom shapefile, how I can I query the API for obs within that complex shape?

I’m aware one can query the API using a bounding box - which would effectively search a rectangular area.

But ideally I’d like to search for observations only within a custom-defined shapefile area e.g. shown below. Is this possible, if I have the shapefile ready to go? I only want the API to return observations within the enclosed areas described by the shapefile.

If it is not possible I guess I’ll head over to the feature requests part of this forum…
As a workaround , how would you best approximate this complex shape of territory with just bounding boxes?

Making enough bounding boxes to get a somewhat precise approximation would mean a huge amount of requests. Maybe do the opposite, one singular outer bounding box then write some script to check whether an observation within that bounding box has coordinates within your shapefile?

Edit: Also, https://forum.inaturalist.org/t/new-rectangle-and-circle-drawing-tools-for-web-explore-page/36684/32 might help you

Thanks. That’s a smart approach. I’m not sure I fancy the complexity of checking whether observations are IN or OUT of the complex shape locally though. I’ll think about how I might do that with R

I’ve just stumbled upon what might be a cleaner approach though - maybe I could register this shape as an iNaturalist ‘Place’ ? As described in another thread here: https://forum.inaturalist.org/t/geographically-limited-searches/5983/11?u=rmounce

The traditional approach to check, AFAIK, is ray-casting (trace an horizontal line going through your point then count whether the number of times it intersects your shape is even or odd). I’m fairly certain R would have libraries for this (This Stack Exchange post might fit).

1 Like

Yeah, that was my first thought. If you registered this as a place, the API request would be as simple as querying by place ID. It would also be worth checking if there are one or more existing places that are similar enough to your shapefile.

For the more general case of “I have a bunch of shapefiles and want to find all the observations within them,” and it isn’t practical to register them all as iNat places, then you could download and filter observations locally.

You don’t need to manually check every observation, though; this is the the kind of task that GIS tools are made for. I think there are some guides for this in the Tutorials section with either ArcGIS or QGIS. If not, I or others here could help get you started.

Definitely try using iNat places first, though.

1 Like

For this thing, it’s only really this estate I want to look at so I think Places is the right thing I’m looking for. phew

Okay… I’m back. I’ve now registered the place. But it comes back with 0 observations as occuring within the bounds of the shape. This isn’t true - there are lots of observations within the bounds. I wonder if iNat can’t handle the complex enclaves, or something??

https://www.inaturalist.org/observations?place_id=185863&subview=map&verifiable=any

The place_id for my newly created place is 185863

Help? Thoughts?

Before putting too much energy into figuring that out, I’d say try again in a few hours, or maybe tomorrow. iNat’s geospatial indexes may just take some time to get updated.

3 Likes

Yes, they definitely don’t get added immediately. The other thing to keep in mind is that obscured observations or observations with large uncertainty circles won’t get indexed in your place, see details here.

2 Likes

thanks, that’s interesting. I guess I should do a little manual comparison of all the obs I think should be included in the shape/Place, versus how many appear through the server-side iNat Place filter. It may be that I want to be less conservative than blanket excluding all obs that even only very partially break the bounding box / Place boundaries. I can appreciate how that is handled is always going to be tricky, iNat sounds like it has a sensible default setting on that - thanks for making me aware of how it is handled :+1:.

1 Like

459 observations now coming-up within that ‘Place’. Waiting til the next morning was all I needed to do :)
Thanks again

Just be aware that if the accuracy radius of the sighting extends outside of the shape, that sighting will not be included. So, problems with sightings on or near the border.

2 Likes