I’ve been using the API to extract some additional information for some 6000 records of an invasive plant across North America. Our project, for various reasons, has focused on county-level records. The API does, technically, include county info, in the place_ids variable. But this information is coded (e.g., Alachua Cty., FL is 2511) and mixed in with an often impressive number of scaled place codes (e.g., "place_ids": [1, 19, 339, 9853, 51894, 57106, 59613, 59649, 61551, 64422, 64423, 66741, 81418, 81775, 82256, 82257, 90754, 96685, 97394, 127683, 127684, 145691, 157671, 201280],).
By any chance is there available somewhere accessible a list of U.S. counties with their corresponding iNaturalist code? Or at the least, are U.S. county codes bounded within a specific range? Any insights would be greatly appreciated!
You should get all the US county-level places by filtering for admin_level 20 and ancestry starting with 97394/1/, but you might want to double check that.
Not sure if this helps, but you can get the county name for an observation using something like this (untested sloppy and probably outdated jQuery code):
var placeList = observation.place_ids.toString();
var iNatApi = 'https://api.inaturalist.org/v1/places/' + placeList;
var params = { 'admin_level': '20' };
$.getJSON( iNatApi, params )
.done( function( data ) {
if ( data.results[0] !== undefined && data.results[0].name !== undefined ) {
return data.results[0].name;
} else {
return null;
}
} );