Gurthang99
Gurthang99

Reputation: 49

How do I get the hourly forecast from api.weather.gov for Texas stations or zones or offices or gridpoints or anything else?

I am trying to get the hourly forecast from api.weather.gov

I have one gridpoint working for Indiana. https://api.weather.gov/gridpoints/IND/56,65/forecast/hourly

I was given this information and it is valid. What I need is the hourly forecast in the state of Texas for every stations or zones or offices or gridpoints or anything else.

How do I do that?

Upvotes: 2

Views: 2546

Answers (2)

Stephen Clouse
Stephen Clouse

Reputation: 401

As long as you have the latitude/longitude of the location you want the forecast for, then:

  1. Get the point metadata from https://api.weather.gov/points/{lat},{lon}
  2. Follow the link in the forecastHourly property to get the forecast

This is preferable to constructing the URL as in the other answer, as your program won't break if the URL scheme changes in the future.

Upvotes: 4

Joshua Espana
Joshua Espana

Reputation: 114

Looking at the api documentation found HERE and HERE, you are calling the /gridpoints/{wfo}/{x},{y}/forecast/hourly call which will return the hourly weather forecast for the specified weather office {wfo} at the specified x-y coordinates. You can find a list of the weather offices HERE. Finding the X-Y coordinates for the weather offices may be a bit more tedious to find on the web.

If you happen have access to the GPS coordinates that you are working with you can use the /points/{x},{y} API call to get the information on the closest weather office to then pass to the /gridpoints/{wfo}/{x},{y}/forecast/hourly API call.

The flow of your application can look something like this:

Step 1: Get your map Geo coordinates. In my case, I am at 35,-106

Step 2: Make a call to the weather.gov API: https://api.weather.gov/points/35,-106. You will be presented with some JSON data. Look for the cwa key in the properties object. That will be the forecast office to pass into the next api call. In my case, the key is ABQ. You also need to find the gridX and gridY keys in the properties. These are the XY coordinates that you will use for the {X},{Y} parameters in the API call. In my case X = 121 and Y = 112.

Step 3: Make the final call to the weather.gov API: https://api.weather.gov/gridpoints/ABQ/121,112/forecast/hourly

Upvotes: 5

Related Questions