簡體   English   中英

NOAA如何將City,St轉換為長途?

[英]How does NOAA convert City,St to lat long?

NOAA REST服務提供了獲取天氣信息的方法。 我注意到NOAA網站上有一個文本框,我可以輸入City,St來獲取該位置的天氣信息。

使用REST服務,它僅列出有限的City,St及其對應的Lat,Lng:

http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdXMLclient.php?listCitiesLevel=1234

但是,如果我想看看Lat,Lng for MCRAE, GA ,它在REST服務中沒有列為City,St。

我的目標是使用任何City,St作為python程序的輸入,程序將檢索該位置的天氣數據。 這最終涉及計算City,St坐標,然后使用坐標構建url。 我希望REST服務能給我坐標,但似乎不可能。

我的問題是NOAA如何找出適用於任何特定城市的正確坐標,St? 是否有可以輕松返回數據的REST服務? 我寧願不必模擬用戶輸入,然后屏幕抓取坐標。

使用openstreetmap.org

import urllib2
import urllib
import json

url = 'http://nominatim.openstreetmap.org/search?'
place = 'MCRAE, GA'
params = urllib.urlencode(dict(q=place, format='json'))
# print(url+params)
response = urllib.urlopen(url+params)
data = json.loads(response.read())[0]
print(data['lon'], data['lat'])

產量

(u'-82.9006993', u'32.0679541')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM