Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In order to do reverse geocoding lookups to find a country (as ISO-3166-1) and the subdivision (as ISO-3166-2) for given coordinates I am looking for a way to get all polygons of all countries and their subdivisions.

Reverse geocoding lookups with Google Maps or other services either do not always return the country and subdivision (Google Maps), or sometimes they are incorrect (geonames.org). As I understand it all countries and subdivisons are available in the openstreetmap data, but I do not know how to only retrieve the polygons - no map data, no points of interest or cities are necessary, only the outlines of all subdivisions with the given country and subdivision codes. Then I can check myself if a given point is within any given polygon, or near it.

Does anyone know how to retrieve this data from the openstreetmap data, or is there any other source for this data?

share|improve this question

4 Answers 4

up vote 5 down vote accepted

Maybe this site may have what you are looking for ?? http://www.gadm.org/ and http://www.gadm.org/country

regards

Kurt

share|improve this answer
    
I've checked out gadm and was able to test it - the provided data is really good, and most importantly, the ISO 3166-2 codes are contained (usually in the hasc_1 column, sometimes in the hasc_2 column). Some manual processing is still necessary depending on what kind of details one wants, but the source material seems great so far. –  iquito Apr 11 '12 at 2:42
    
@iquito: FYI those values in the HASC_* columns are not ISO 3166, they're a totally different thing. –  Crescent Fresh Apr 15 '13 at 18:16

Other sources include http://www.unsalb.org/ and http://www.diva-gis.org/Data

Stéphane

share|improve this answer

Since you requested how to extract this data from openstreetmap: theoretically you can use the XAPI to match boundary descriptions. E.g. using a query like this: (warning, will take quite a while, so I'm not formatting this as a link!)

www.overpass-api.de/api/xapi?way[bbox=2,49,7.5,54][boundary=administrative][admin_level=2]

The result will be a list of polygons, in this case denoting the boundaries of the Benelux countries. You'd probably have to repeat this for other bounding boxes, perhaps with overlap. And for other levels. Lot of work. You'd want a script for that.

Or download Planet.osm, and simply use suitable OSM libraries or XML tools to locally extract the relevant data.

All of this will come without uniform ISO-3166-2 identifiers, as far as I can tell, simply because that standard isn't available for free.

share|improve this answer

You can find a script inspired by MvG's answer and a few examples here : https://github.com/laem/regions-topojson

Sadly, not all geonames administrative relations are tagged with iso-3166-2...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.