从3个代码ISO代码(ISO 3166-1 alpha-3)获取MS GeoId

时间:2009-07-17 08:21:22

标签: .net interop internationalization

我有一个3 letter ISO code(例如DEU代表德国,美国代表美国......)并希望获得this table中列出的GeoID,也可以here我可以如何使用直接.NET,P / Invoking或通过MapPoint PIA执行此操作。

e.g。鉴于“SWE”,我想检索221。

System.Globalisation.RegionInfo看起来很有希望 - 但它需要2个字母代码(美国代替美国)。为此,一个3个字母 - > 2字母转换也可以。

3 个答案:

答案 0 :(得分:1)

我认为你必须手动设置映射开始,除非有人已经完成了。稍微修补一下你就可以使用数据库或类似的方法来对名称进行连接,并且可能获得90%或更多的连接,然后手工填写其余部分。

我会将映射保留在外部文件,数据库表等中,因此它不是硬编码的(不确定添加或更新GeoID值的可能性......)和load them into a hashtable/dictionary如果你需要能够很快地查找它们。

编辑:

你走了,我很无聊。有大约30个我无法比拟,其余的排队很好,稍微调整一下。全外连接FTW。

(isocode,geoid,isoname,msname)
'AFG','0x3','Afghanistan','Afghanistan'
'AGO','0x9','Angola','Angola'
'AIA','0x12C','Anguilla','Anguilla'
'ALA',null,'Åland Islands',null
'ALB','0x6','Albania','Albania'
'AND','0x8','Andorra','Andorra'
'ANT','0x14D','Netherlands Antilles','Netherlands Antilles'
'ARE','0xE0','United Arab Emirates','United Arab Emirates'
'ARG','0xB','Argentina','Argentina'
'ARM','0x7','Armenia','Armenia'
'ASM','0xA','American Samoa','American Samoa'
'ATA','0x12D','Antarctica','Antarctica'
'ATF','0x13F','French Southern and Antarctic Lands','French Southern and Antarctic Lands'
'ATG','0x2','Antigua and Barbuda','Antigua and Barbuda'
'AUS','0xC','Australia','Australia'
'AUT','0xE','Austria','Austria'
'AZE','0x5','Azerbaijan','Azerbaijan'
'BDI','0x26','Burundi','Burundi'
'BEL','0x15','Belgium','Belgium'
'BEN','0x1C','Benin','Benin'
'BFA','0xF5','Burkina Faso','Burkina Faso'
'BGD','0x17','Bangladesh','Bangladesh'
'BGR','0x23','Bulgaria','Bulgaria'
'BHR','0x11','Bahrain','Bahrain'
'BHS','0x16','Bahamas, The','Bahamas, The'
'BIH','0x19','Bosnia and Herzegovina','Bosnia and Herzegovina'
'BLM',null,'Saint Barthélemy',null
'BLR','0x1D','Belarus','Belarus'
'BLZ','0x18','Belize','Belize'
'BMU','0x14','Bermuda','Bermuda'
'BOL','0x1A','Bolivia','Bolivia'
'BRA','0x20','Brazil','Brazil'
'BRB','0x12','Barbados','Barbados'
'BRN','0x25','Brunei','Brunei'
'BTN','0x22','Bhutan','Bhutan'
'BVT','0x132','Bouvet Island','Bouvet Island'
'BWA','0x13','Botswana','Botswana'
'CAF','0x37','Central African Republic','Central African Republic'
'CAN','0x27','Canada','Canada'
'CCK','0x137','Cocos (Keeling) Islands','Cocos (Keeling) Islands'
'CHE','0xDF','Switzerland','Switzerland'
'CHL','0x2E','Chile','Chile'
'CHN','0x2D','China','China'
'CIV','0x77','Côte d''Ivoire','Côte d''Ivoire'
'CMR','0x31','Cameroon','Cameroon'
'COD','0x2C','Congo, DRC','Congo, DRC'
'COG','0x2B','Congo','Congo'
'COK','0x138','Cook Islands','Cook Islands'
'COL','0x33','Colombia','Colombia'
'COM','0x32','Comoros','Comoros'
'CPV','0x39','Cape Verde','Cape Verde'
'CRI','0x36','Costa Rica','Costa Rica'
'CUB','0x38','Cuba','Cuba'
'CXR','0x135','Christmas Island','Christmas Island'
'CYM','0x133','Cayman Islands','Cayman Islands'
'CYP','0x3B','Cyprus','Cyprus'
'CZE','0x4B','Czech Republic','Czech Republic'
'DEU','0x5E','Germany','Germany'
'DJI','0x3E','Djibouti','Djibouti'
'DMA','0x3F','Dominica','Dominica'
'DNK','0x3D','Denmark','Denmark'
'DOM','0x41','Dominican Republic','Dominican Republic'
'DZA','0x4','Algeria','Algeria'
'ECU','0x42','Ecuador','Ecuador'
'EGY','0x43','Egypt','Egypt'
'ERI','0x47','Eritrea','Eritrea'
'ESH',null,'Western Sahara',null
'ESP','0xD9','Spain','Spain'
'EST','0x46','Estonia','Estonia'
'ETH','0x49','Ethiopia','Ethiopia'
'FIN','0x4D','Finland','Finland'
'FJI','0x4E','Fiji','Fiji'
'FLK','0x13B','Falkland Islands (Islas Malvinas)','Falkland Islands (Islas Malvinas)'
'FRA','0x54','France','France'
'FRO','0x51','Faroe Islands','Faroe Islands'
'FSM','0x50','Micronesia','Micronesia'
'GAB','0x57','Gabon','Gabon'
'GBR','0xF2','United Kingdom','United Kingdom'
'GEO','0x58','Georgia','Georgia'
'GGY','0x144','Guernsey','Guernsey'
'GHA','0x59','Ghana','Ghana'
'GIN','0x64','Guinea','Guinea'
'GLP','0x141','Guadeloupe','Guadeloupe'
'GMB','0x56','Gambia, The','Gambia, The'
'GNB','0xC4','Guinea-Bissau','Guinea-Bissau'
'GNQ','0x45','Equatorial Guinea','Equatorial Guinea'
'GRC','0x62','Greece','Greece'
'GRD','0x5B','Grenada','Grenada'
'GRL','0x5D','Greenland','Greenland'
'GTM','0x63','Guatemala','Guatemala'
'GUF','0x13D','French Guiana','French Guiana'
'GUM','0x142','Guam','Guam'
'GUY','0x65','Guyana','Guyana'
'HKG','0x68','Hong Kong','Hong Kong'
'HMD','0x145','Heard Island and McDonald Islands','Heard Island and McDonald Islands'
'HND','0x6A','Honduras','Honduras'
'HRV','0x6C','Croatia','Croatia'
'HTI','0x67','Haiti','Haiti'
'HUN','0x6D','Hungary','Hungary'
'IDN','0x6F','Indonesia','Indonesia'
'IMN','0x3B16','Isle of Man','Isle of Man'
'IND','0x71','India','India'
'IOT','0x72','British Indian Ocean Territory','British Indian Ocean Territory'
'IRL','0x44','Ireland','Ireland'
'IRN','0x74','Iran','Iran'
'IRQ','0x79','Iraq','Iraq'
'ISL','0x6E','Iceland','Iceland'
'ISR','0x75','Israel','Israel'
'ITA','0x76','Italy','Italy'
'JAM','0x7C','Jamaica','Jamaica'
'JEY','0x148','Jersey','Jersey'
'JOR','0x7E','Jordan','Jordan'
'JPN','0x7A','Japan','Japan'
'KAZ','0x89','Kazakhstan','Kazakhstan'
'KEN','0x81','Kenya','Kenya'
'KGZ','0x82','Kyrgyzstan','Kyrgyzstan'
'KHM','0x28','Cambodia','Cambodia'
'KIR','0x85','Kiribati','Kiribati'
'KNA','0xCF','Saint Kitts and Nevis','Saint Kitts and Nevis'
'KOR','0x86','Korea','Korea'
'KWT','0x88','Kuwait','Kuwait'
'LAO','0x8A','Laos','Laos'
'LBN','0x8B','Lebanon','Lebanon'
'LBR','0x8E','Liberia','Liberia'
'LBY','0x94','Libya','Libya'
'LCA','0xDA','Saint Lucia','Saint Lucia'
'LIE','0x91','Liechtenstein','Liechtenstein'
'LKA','0x2A','Sri Lanka','Sri Lanka'
'LSO','0x92','Lesotho','Lesotho'
'LTU','0x8D','Lithuania','Lithuania'
'LUX','0x93','Luxembourg','Luxembourg'
'LVA','0x8C','Latvia','Latvia'
'MAC','0x97','Macau SAR','Macau SAR'
'MAF',null,'Saint Martin (France)',null
'MAR','0x9F','Morocco','Morocco'
'MCO','0x9E','Monaco','Monaco'
'MDA','0x98','Moldova','Moldova'
'MDG','0x95','Madagascar','Madagascar'
'MDV','0xA5','Maldives','Maldives'
'MEX','0xA6','Mexico','Mexico'
'MHL','0xC7','Marshall Islands','Marshall Islands'
'MKD','0x4CA2','Macedonia, FYROM','Macedonia, FYROM'
'MLI','0x9D','Mali','Mali'
'MLT','0xA3','Malta','Malta'
'MMR','0x1B','Myanmar','Myanmar'
'MNE',null,'Montenegro',null
'MNG','0x9A','Mongolia','Mongolia'
'MNP','0x151','Northern Mariana Islands','Northern Mariana Islands'
'MOZ','0xA8','Mozambique','Mozambique'
'MRT','0xA2','Mauritania','Mauritania'
'MSR','0x14C','Montserrat','Montserrat'
'MTQ','0x14A','Martinique','Martinique'
'MUS','0xA0','Mauritius','Mauritius'
'MWI','0x9C','Malawi','Malawi'
'MYS','0xA7','Malaysia','Malaysia'
'MYT','0x14B','Mayotte','Mayotte'
'NAM','0xFE','Namibia','Namibia'
'NCL','0x14E','New Caledonia','New Caledonia'
'NER','0xAD','Niger','Niger'
'NFK','0x150','Norfolk Island','Norfolk Island'
'NGA','0xAF','Nigeria','Nigeria'
'NIC','0xB6','Nicaragua','Nicaragua'
'NLD','0xB0','Netherlands','Netherlands'
'NOR','0xB1','Norway','Norway'
'NPL','0xB2','Nepal','Nepal'
'NRU','0xB4','Nauru','Nauru'
'NZL','0xB7','New Zealand','New Zealand'
'OMN','0xA4','Oman','Oman'
'PAK','0xBE','Pakistan','Pakistan'
'PAN','0xC0','Panama','Panama'
'PCN','0x153','Pitcairn Islands','Pitcairn Islands'
'PER','0xBB','Peru','Peru'
'PHL','0xC9','Philippines','Philippines'
'PLW','0xC3','Palau','Palau'
'PNG','0xC2','Papua New Guinea','Papua New Guinea'
'POL','0xBF','Poland','Poland'
'PRI','0xCA','Puerto Rico','Puerto Rico'
'PRK','0x83','North Korea','North Korea'
'PRT','0xC1','Portugal','Portugal'
'PRY','0xB9','Paraguay','Paraguay'
'PSE','0xB8','Palestinian Authority','Palestinian Authority'
'PYF','0x13E','French Polynesia','French Polynesia'
'QAT','0xC5','Qatar','Qatar'
'REU','0xC6','Réunion','Réunion'
'ROU','0xC8','Romania','Romania'
'RUS','0xCB','Russia','Russia'
'RWA','0xCC','Rwanda','Rwanda'
'SAU','0xCD','Saudi Arabia','Saudi Arabia'
'SDN','0xDB','Sudan','Sudan'
'SEN','0xD2','Senegal','Senegal'
'SGP','0xD7','Singapore','Singapore'
'SGS','0x156','South Georgia and the South Sandwich Islands','South Georgia and the South Sandwich Islands'
'SHN','0x157','Saint Helena','Saint Helena'
'SJM','0xDC','Svalbard and Jan Mayen','Svalbard and Jan Mayen'
'SLB','0x1E','Solomon Islands','Solomon Islands'
'SLE','0xD5','Sierra Leone','Sierra Leone'
'SLV','0x48','El Salvador','El Salvador'
'SMR','0xD6','San Marino','San Marino'
'SOM','0xD8','Somalia','Somalia'
'SPM','0xCE','Saint Pierre and Miquelon','Saint Pierre and Miquelon'
'SRB','0x10D','Serbia','Serbia'
'STP','0xE9','São Tomé and Príncipe','São Tomé and Príncipe'
'SUR','0xB5','Suriname','Suriname'
'SVK','0x8F','Slovakia','Slovakia'
'SVN','0xD4','Slovenia','Slovenia'
'SWE','0xDD','Sweden','Sweden'
'SWZ','0x104','Swaziland','Swaziland'
'SYC','0xD0','Seychelles','Seychelles'
'SYR','0xDE','Syria','Syria'
'TCA','0x15D','Turks and Caicos Islands','Turks and Caicos Islands'
'TCD','0x29','Chad','Chad'
'TGO','0xE8','Togo','Togo'
'THA','0xE3','Thailand','Thailand'
'TJK','0xE4','Tajikistan','Tajikistan'
'TKL','0x15B','Tokelau','Tokelau'
'TKM','0xEE','Turkmenistan','Turkmenistan'
'TLS','0x6F60E7','Timor-Leste','Timor-Leste'
'TON','0xE7','Tonga','Tonga'
'TTO','0xE1','Trinidad and Tobago','Trinidad and Tobago'
'TUN','0xEA','Tunisia','Tunisia'
'TUR','0xEB','Turkey','Turkey'
'TUV','0xEC','Tuvalu','Tuvalu'
'TWN','0xED','Taiwan','Taiwan'
'TZA','0xEF','Tanzania','Tanzania'
'UGA','0xF0','Uganda','Uganda'
'UKR','0xF1','Ukraine','Ukraine'
'UMI',null,'United States Minor Outlying Islands',null
'URY','0xF6','Uruguay','Uruguay'
'USA','0xF4','United States','United States'
'UZB','0xF7','Uzbekistan','Uzbekistan'
'VAT','0xFD','Vatican City','Vatican City'
'VCT','0xF8','Saint Vincent and the Grenadines','Saint Vincent and the Grenadines'
'VEN','0xF9','Venezuela','Venezuela'
'VGB','0x15F','Virgin Islands, British','Virgin Islands, British'
'VIR','0xFC','Virgin Islands','Virgin Islands'
'VNM','0xFB','Vietnam','Vietnam'
'VUT','0xAE','Vanuatu','Vanuatu'
'WLF','0x160','Wallis and Futuna','Wallis and Futuna'
'WSM','0x103','Samoa','Samoa'
'YEM','0x105','Yemen','Yemen'
'ZAF','0xD1','South Africa','South Africa'
'ZMB','0x107','Zambia','Zambia'
'ZWE','0x108','Zimbabwe','Zimbabwe'
null,'0x5A',null,'Gibraltar'
null,'0x7D',null,'Jan Mayen'
null,'0x7F',null,'Johnston Atoll'
null,'0x102',null,'Wake Island'
null,'0x12E',null,'Aruba'
null,'0x12F',null,'Ascension Island'
null,'0x130',null,'Ashmore and Cartier Islands'
null,'0x131',null,'Baker Island'
null,'0x134',null,'Channel Islands'
null,'0x136',null,'Clipperton Island'
null,'0x139',null,'Coral Sea Islands'
null,'0x13A',null,'Diego Garcia'
null,'0x143',null,'Guantanamo Bay'
null,'0x146',null,'Howland Island'
null,'0x147',null,'Jarvis Island'
null,'0x149',null,'Kingman Reef'
null,'0x14F',null,'Niue'
null,'0x152',null,'Palmyra Atoll'
null,'0x154',null,'Rota Island'
null,'0x155',null,'Saipan'
null,'0x15A',null,'Tinian Island'
null,'0x15C',null,'Tristan da Cunha'
null,'0x52FA',null,'Midway Islands'

答案 1 :(得分:1)

使用EnumSystemGeoID枚举所有GSID,然后将GetGeoInfoGEO_ISO3一起用作GeoType

当然,最好是你这样做一次,缓存结果,然后你可以按照你想要的方式映射两种方式。

链接:

答案 2 :(得分:0)

在使用Enum。*和反射API之后,我终于通过枚举所有可能的RegionInfo来解决这个问题。这可以通过获取所有CultureInfos并从中创建RegionInfos来实现。

以下代码很蹩脚,需要完善。

    internal MapPoint.GeoCountry GetGeocode(string isoCountryCode)
    {
        CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
        RegionInfo region = null;
        foreach (CultureInfo culture in cultures)
        {
            try
            {
                 region = new RegionInfo(culture.Name);
                 if (String.Compare(region.ThreeLetterISORegionName, isoCountryCode, true) == 0)
                     return (GeoCountry)region.GeoId;
            }
            catch
            {
            }
        }

        return GeoCountry.geoCountryDefault;
    }

随意疯狂使其变得通用,漂亮,优化等:)