iso 3166-2 state codes

Is there a simple method for determination of iso 3166-2 ‘state’ codes for osm nodes using nominatim? I have run across mappings from iso 3166-2 to text and the ‘pycountry’ module which I imagine will amount to the same , but am curious if there is not an in-osm method for this conversion.
I saw a tool called ‘cosmogony’ ( , is this the way to go if text conversion runs into trouble?

I am further interested in what geonames calls ‘admin2’ codes, I am not sure what the iso equivalent is (it seems the geonames admin1 is largely equivalent to iso-3166-2) .

It isn’t completely clear what your goal is. Do you just want a list of any ISO 3166-2 codes being used in OSM? If so, then I don’t think you’ll find any. The second part of an ISO 3166-2 code may be what’s used in addr:state or addr:province tags, but I don’t think the full ISO 3166-2 code (e.g. CA-ON or US-NY) would be used in any OSM tags.

Or do you just want a list of ISO 3166-2 codes? If so, you can get that from the ISO site here.


walter aka wambacher

Given a node/way/relation , determine within which iso 3166-2 it is contained (and return all if its in more than one, none if there are none)

I paste here what was accidentally reported: