Pregunta

The NOAA REST service provides a way to get weather information. I noticed that there is a textbox on the NOAA website, and I could input City,St to get the weather information for that location.

With the REST service, it lists only limited City,St with their corresponding Lat,Lng:

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

However, if I want to see the Lat,Lng for MCRAE, GA, it's not listed as a City,St in the REST service.

My goal is to use any City,St as input to a python program and the program will retrieve the weather data for that location. This eventually involves figuring out the City,St coordinates and then building the url using the coordinates. I was hoping the REST service would give me the coordinates, but it doesn't seem possible.

My question is how does NOAA figure out the correct coordinate to use for any given City,St? And is there any REST service which will easily return that data if it's possible? I would rather not have to simulate the user input and then screen scraping the coordinate.

¿Fue útil?

Solución

Using 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'])

yields

(u'-82.9006993', u'32.0679541')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top