Find country code from city name
Ältere Kommentare anzeigen
Is there a function available or method to figure out in which country the city is.
I have a column table with a lot of cities and need to complete it with the country name.
5 Kommentare
"I have a column table with a lot of cities and need to complete it with the country name. "
In general this is not possible without some supplementary information. Consider:
Algiers: https://en.wikipedia.org/wiki/Algiers or https://en.wikipedia.org/wiki/Algiers,_New_Orleans or https://en.wikipedia.org/wiki/Algiers,_Indiana ?
Memphis: https://en.wikipedia.org/wiki/Memphis,_Egypt or https://en.wikipedia.org/wiki/Memphis,_Tennessee ?
Wellington: https://en.wikipedia.org/wiki/Wellington,_Somerset or https://en.wikipedia.org/wiki/Wellington ?
etc. etc. for thousands of other duplicated city and placenames.
On top of that you would probably need to consider spelling variations, special characters, etc.
Steven Lord
am 10 Aug. 2022
MathWorks HQ is in Natick, Massachusetts. There are also apparently towns or cities named Natick in Rhode Island and Nebraska.
Dion Theunissen
am 10 Aug. 2022
Bearbeitet: Dion Theunissen
am 10 Aug. 2022
Stephen23
am 10 Aug. 2022
"I also have street adresses, numbers and postalcodes"
I guess the city name and street and postcode are likely to narrow it down to a particular country. But there is no chance that all of your data are formatted exactly the same format as any database that you will download, so most likely you will have to use an online search engine or service.
dpb
am 10 Aug. 2022
I found it pretty trival exercise to create a lookup engine for a downloaded database to which to simply pass the ZIP code to...of course, online databases change/are updated, but if one doesn't have highspeed connection and the data aren't all that dynamic, the static database works pretty well.
I've used it successfully with our local community college student applications database to fill in missing data -- it fails on the rarest of occasion with a missing entry;
>> numel(unique(tZipInfo.Country))
ans =
62
>> height(tZipInfo.Country)
ans =
42724
>>
shows it has 62 unique countries and some 42,000 locations. I'm sure there are many more possible; just how exotic OP's search list is will determine just how sophisticated his lookup will have to be.
Antworten (2)
dpb
am 10 Aug. 2022
Postal codes helps for many countries, yes...although there are some that either don't have or don't use one, if all your addresses include one, you've got at least a chance.
While not the most sophisticated thing, I've built the following routine from a downloaded database I found online -- right now I don't recall which one, specifically, I used...
function [city county state country]=ziplocation(Z)
%ZIPLOCATION returns physical location of ZIP code
% USAGE:
% [city,county,state,country]=ziplocation(ZIP)
load zipDatabaseTable.mat
tmp=repmat({''},size(Z));
[lia,ib]=ismember(Z,tZipInfo.ZIP);
ib=ib(find(ib));
city=tmp; city(lia)=tZipInfo.City(ib);
county=tmp; county(lia)=tZipInfo.County(ib);
state=tmp; state(lia)=tZipInfo.State(ib);
country=tmp;country(lia)=tZipInfo.Country(ib);
end
Steven Lord
am 10 Aug. 2022
0 Stimmen
As far as I'm aware there's no function in MATLAB to map address information to country information, but if there is a web resource that you can use to determine this information you could use some of the basic web services functionality to query those resources. If those tools are not sufficient, there are some more advanced tools available as well.
Kategorien
Mehr zu Interact with Maps finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!