2012-12-16 200 views
-1

我想要某些代碼,以經緯度爲輸入,我想獲取它所屬的大陸?我知道我可以手動讀取座標,然後從地圖上看到。但有沒有更簡單的方法來做到這一點?獲取給定經緯度的大陸

+0

這個線程可能是有用的... http://gis.stackexchange.com/questions/30254/dividing-earth-into-continent-polygons – bla

回答

1

您可以使用Google地理編碼API。假設我們要搜索的緯度= 22,經度= 77(落在亞洲),您可以運行此代碼:

url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=22,77&sensor=true'; 
    urlread(url) 

這將返回一個數字的細節當中,你也得到了國家中緯度,發現經度。現在,您可以在查找表中查找該國家/地區。您將需要創建此查找表(或下載它)。 https://stackoverflow.com/a/1283168/845528

完整的代碼是在這裏:

 str = {'AD','Europe';'AE','Asia';'AF','Asia';'AG','North America';'AI','North America';'AL','Europe';'AM','Asia';'AN','North America';'AO','Africa';'AQ','Antarctica';'AR','South America';'AS','Australia';'AT','Europe';'AU','Australia';'AW','North America';'AZ','Asia';'BA','Europe';'BB','North America';'BD','Asia';'BE','Europe';'BF','Africa';'BG','Europe';'BH','Asia';'BI','Africa';'BJ','Africa';'BM','North America';'BN','Asia';'BO','South America';'BR','South America';'BS','North America';'BT','Asia';'BW','Africa';'BY','Europe';'BZ','North America';'CA','North America';'CC','Asia';'CD','Africa';'CF','Africa';'CG','Africa';'CH','Europe';'CI','Africa';'CK','Australia';'CL','South America';'CM','Africa';'CN','Asia';'CO','South America';'CR','North America';'CU','North America';'CV','Africa';'CX','Asia';'CY','Asia';'CZ','Europe';'DE','Europe';'DJ','Africa';'DK','Europe';'DM','North America';'DO','North America';'DZ','Africa';'EC','South America';'EE','Europe';'EG','Africa';'EH','Africa';'ER','Africa';'ES','Europe';'ET','Africa';'FI','Europe';'FJ','Australia';'FK','South America';'FM','Australia';'FO','Europe';'FR','Europe';'GA','Africa';'GB','Europe';'GD','North America';'GE','Asia';'GF','South America';'GG','Europe';'GH','Africa';'GI','Europe';'GL','North America';'GM','Africa';'GN','Africa';'GP','North America';'GQ','Africa';'GR','Europe';'GS','Antarctica';'GT','North America';'GU','Australia';'GW','Africa';'GY','South America';'HK','Asia';'HN','North America';'HR','Europe';'HT','North America';'HU','Europe';'ID','Asia';'IE','Europe';'IL','Asia';'IM','Europe';'IN','Asia';'IO','Asia';'IQ','Asia';'IR','Asia';'IS','Europe';'IT','Europe';'JE','Europe';'JM','North America';'JO','Asia';'JP','Asia';'KE','Africa';'KG','Asia';'KH','Asia';'KI','Australia';'KM','Africa';'KN','North America';'KP','Asia';'KR','Asia';'KW','Asia';'KY','North America';'KZ','Asia';'LA','Asia';'LB','Asia';'LC','North America';'LI','Europe';'LK','Asia';'LR','Africa';'LS','Africa';'LT','Europe';'LU','Europe';'LV','Europe';'LY','Africa';'MA','Africa';'MC','Europe';'MD','Europe';'ME','Europe';'MG','Africa';'MH','Australia';'MK','Europe';'ML','Africa';'MM','Asia';'MN','Asia';'MO','Asia';'MP','Australia';'MQ','North America';'MR','Africa';'MS','North America';'MT','Europe';'MU','Africa';'MV','Asia';'MW','Africa';'MX','North America';'MY','Asia';'MZ','Africa';'NA','Africa';'NC','Australia';'NE','Africa';'NF','Australia';'NG','Africa';'NI','North America';'NL','Europe';'NO','Europe';'NP','Asia';'NR','Australia';'NU','Australia';'NZ','Australia';'OM','Asia';'PA','North America';'PE','South America';'PF','Australia';'PG','Australia';'PH','Asia';'PK','Asia';'PL','Europe';'PM','North America';'PN','Australia';'PR','North America';'PS','Asia';'PT','Europe';'PW','Australia';'PY','South America';'QA','Asia';'RE','Africa';'RO','Europe';'RS','Europe';'RU','Europe';'RW','Africa';'SA','Asia';'SB','Australia';'SC','Africa';'SD','Africa';'SE','Europe';'SG','Asia';'SH','Africa';'SI','Europe';'SJ','Europe';'SK','Europe';'SL','Africa';'SM','Europe';'SN','Africa';'SO','Africa';'SR','South America';'ST','Africa';'SV','North America';'SY','Asia';'SZ','Africa';'TC','North America';'TD','Africa';'TF','Antarctica';'TG','Africa';'TH','Asia';'TJ','Asia';'TK','Australia';'TM','Asia';'TN','Africa';'TO','Australia';'TR','Asia';'TT','North America';'TV','Australia';'TW','Asia';'TZ','Africa';'UA','Europe';'UG','Africa';'US','North America';'UY','South America';'UZ','Asia';'VC','North America';'VE','South America';'VG','North America';'VI','North America';'VN','Asia';'VU','Australia';'WF','Australia';'WS','Australia';'YE','Asia';'YT','Africa';'ZA','Africa';'ZM','Africa';'ZW','Africa'}; 
    url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=22,77&sensor=true'; 
    queryResult = urlread(url) 
    countryName = queryResult(672:673); 
    strfind(cellstr(str), countryName); 
    continent = str(find(strcmp(countryName, str)), 2) 
+0

不錯的主意,但對於例如你只給出獲得的國家名稱(以及該決議的信息,即縣,市......)。爲了獲得大陸人們需要添加至少一行代碼。 – bla

+0

嗯,是的。但請看看這個:http://stackoverflow.com/a/4477549/845528。 – Kishore

+0

那麼,這裏有一個網址,可以給你大陸和國家之間的鏈接...... http://www.worldatlas.com/cntycont.htm – bla

4

我做這個代碼只是爲了讓大陸

我在這個答案提供一個創造了這樣一個查找表。這不是100%確切的,但對大多數地區都很好。

我這樣做是爲了確定大洲要求由PVsyst,所以我differenciate澳大利亞和太平洋之間,但這是可以很容易地改變:

如果你不希望澳大利亞和太平洋之間者區分,只是刪除澳大利亞部分(LatAus,LonAus,從ContinentIndex和Continent List中刪除它)。

function Continent = GetContinent(Lat,Lon,plotTrueFalse) 

LatNAm = [90  90 78.13 57.5 15 15 1.25 1.25 51 60 60]; 
LonNAm = [-168.75 -10 -10  -37.5 -30 -75 -82.5 -105 -180 -180 -168.75]; 
LatNA2 = [51 51 60]; 
LonNA2 = [166.6 180 180]; 

LatSAm = [1.25 1.25 15 15 -60 -60]; 
LonSAm = [-105 -82.5 -75 -30 -30 -105]; 

LatEur = [90 90 42.5 42.5 40.79 41 40.55 40.40 40.05 39.17 35.46 33 38 35.42 28.25 15 57.5 78.13]; 
LonEur = [-10 77.5 48.8 30 28.81 29 27.31 26.75 26.36 25.19 27.91 27.5 10 -10 -13 -30 -37.5 -10]; 

LatAfr = [15 28.25 35.42 38 33 31.74 29.54 27.78 11.3 12.5 -60 -60]; 
LonAfr = [-30 -13 -10 10 27.5 34.58 34.92 34.46 44.3 52 75 -30]; 

LatAus = [-11.88 -10.27 -10 -30 -52.5 -31.88]; 
LonAus = [110  140 145 161.25 142.5 110]; 

LatAsi = [90 42.5 42.5 40.79 41 40.55 40.4 40.05 39.17 35.46 33 31.74 29.54 27.78 11.3 12.5 -60 -60 -31.88 -11.88 -10.27 33.13 51 60 90]; 
LonAsi = [77.5 48.8 30 28.81 29 27.31 26.75 26.36 25.19 27.91 27.5 34.58 34.92 34.46 44.3 52 75 110 110 110 140 140 166.6 180 180]; 
LatAs2 = [90 90  60  60]; 
LonAs2 = [-180 -168.75 -168.75 -180]; 

LatAnt = [-60 -60 -90 -90]; 
LonAnt = [-180 180 180 -180]; 

inNAm   = inpolygon(Lat,Lon,LatNAm,LonNAm) + inpolygon(Lat,Lon,LatNA2,LonNA2); 
inEur   = inpolygon(Lat,Lon,LatEur,LonEur); 
[inSAm,onSAm] = inpolygon(Lat,Lon,LatSAm,LonSAm); 
[inAfr,onAfr] = inpolygon(Lat,Lon,LatAfr,LonAfr); 
[inAus,onAus] = inpolygon(Lat,Lon,LatAus,LonAus); 
[inAsi,onAsi] = inpolygon(Lat,Lon,LatAsi,LonAsi); 
[inAs2,onAs2] = inpolygon(Lat,Lon,LatAs2,LonAs2); 

ContinentIndex = 1 +(inAfr||onAfr)*1 + (inAus||onAus)*2 + (inAsi||onAsi||inAs2||onAs2)*3 + inEur*4 + inNAm*5 + (inSAm||onSAm)*6; 
ContinentList = {'Pacific','Africa','Australia','Asia','Europe','North_America','South_America'}; 

Continent  = ContinentList{ContinentIndex}; 
%% If you want to show the figure, set plotTrueFalse to true or to ~=0. 
if plotTrueFalse 
    geoshow('landareas.shp', 'FaceColor', [1 1 1]); 
    axis([-180 180 -90 90]) 
    set(gca,'xtick',-180:15:180,'ytick',-90:15:90) 
    grid on; 
    hold on; 
    patch(LonNAm,LatNAm,'r'); 
    patch(LonNA2,LatNA2,'r'); 
    patch(LonSAm,LatSAm,'g'); 
    patch(LonEur,LatEur,'b'); 
    patch(LonAfr,LatAfr,'k'); 
    patch(LonAus,LatAus,[1 0.5 0]); 
    patch(LonAsi,LatAsi,'y'); 
    patch(LonAs2,LatAs2,'y'); 
    patch(LonAnt,LatAnt,[0 1 1]); 
    alpha(0.5); 
end 
+0

爲了在Java中實現這一點,你可以參考這個:https:// stackoverflow的.com /問題/ 8721406 /如何對確定-IF-A-點是-內部-A-2D-凸多邊形 –