GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
2 letter abbreviations  XML
Forum Index -> Administrative Divisions
Author Message
devincrossman



Joined: 03/07/2012 22:14:23
Messages: 1
Offline

Hi I'm wondering how I can retrieve the 2 letter abbreviations for states/provinces/territories from GeoNames. The country data has the two letter abbreviation for the country ie CA for Canada and US for United States but when I look at the countries children I don't see that 2 letter abbreviation.

I'm sorry if I'm posting in the wrong area or if this question has been asked before. I tried searching for the answer but couldn't find it.

Thanks for your help!
marc



Joined: 08/12/2005 07:39:47
Messages: 3993
Offline

You can get the features with featureCode ADM1, or simply the file admin1CodesASCII.txt from the download directory.

Marc

[WWW]
Vannens



Joined: 19/11/2013 11:17:20
Messages: 1
Offline

Hello guys,

I've found the admin1 feature, but, this give me a list of numbers for the states of Spain (for example) and I need the two abbreviation letters to get the postal code of a city given the country, the two letters of the state and the place name with the PostalCodeSearchCriteria of java client.
plong0



Joined: 08/08/2015 03:05:52
Messages: 3
Offline

I found that I can get the 2 letter abbreviation for ADM1 locations using style=FULL

This will return a list of alternateName entries, including one with attribute lang="abbr"

ex. http://api.geonames.org/search?country=CA&fcode=ADM1&style=FULL&username=demo
plong0



Joined: 08/08/2015 03:05:52
Messages: 3
Offline

Hello, I am also wondering how to get the 2 letter abbreviations for provinces/states.
I have found to get the the list of them easily with:
http://api.geonames.org/search?country=CA&fcode=ADM1&username=demo

But this does not give the abbreviation codes (ex. BC for British Columbia)

Is there a way to get those abbreviation codes?
chaosmonkey



Joined: 22/04/2016 02:22:06
Messages: 5
Offline

ISO 3166-2 assigns 2 letter codes, but I don't think it's available in the free data.

Geonames has the data http://www.geonames.org/CA/administrative-division-canada.html

May be you need to get premium data for this? Can someone please confirm?

Thanks.
plong0



Joined: 08/08/2015 03:05:52
Messages: 3
Offline

I figured it out like this:

http://api.geonames.org/search?country=CA&fcode=ADM1&style=FULL&username=demo

Then I process results something like this:
(pseudo-code using xpath lookups)
Code:
 foreach ("/geonames/geoname" as area)
     if ( area.child("alternateName[@lang='abbr']") )
         code = area.child("alternateName[@lang='abbr']")
     else
         lookup = area.child("adminCode1")
         if( lookup && lookup.attribute("ISO3166-2") )
             code = lookup.attribute("ISO3166-2")
         
 


so basically:
for each area:
- lookup alternateName with lang="abbr"
- use that if it is found
- if no alternateName lang="abbr" found
- lookup adminCode1 with attribute ISO3166-2
- use value of ISO3166-2 if found

seems to work nicely for the countries I tested
marc



Joined: 08/12/2005 07:39:47
Messages: 3993
Offline

yes, the ISO 3166 subdivision codes are only available with the premium data subscription and the webservice. It is not yet included in the free daily extract.

Marc

[WWW]
 
Forum Index -> Administrative Divisions
Go to:   
Powered by JForum 2.1.5 © JForum Team