Readme

Lookup a weather.gov grid by lat, lon

Documentation: https://www.weather.gov/documentation/services-web-api

Forecasts are created at each NWS Weather Forecast Office (WFO) on their own grid definition, at a resolution of about 2.5km x 2.5km. The API endpoint for the 12h forecast periods at a specific grid location is formatted as:

https://api.weather.gov/gridpoints/{office}/{gridX},{gridY}/forecast

For example: https://api.weather.gov/gridpoints/TOP/31,80/forecast

To obtain the grid forecast for a point location, use the /points endpoint to retrieve the current grid forecast endpoint by coordinates:

https://api.weather.gov/points/{latitude},{longitude}

For example: https://api.weather.gov/points/39.7456,-97.0892

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export function weatherGovGrid({ lat, lon }): Promise<WeatherData> {
return fetchJSON(
`https://api.weather.gov/points/${lat},${lon}`,
);
}
interface Coordinate {
type: string;
coordinates: [
number,
number,
];
}
interface Distance {
unitCode: string;
value: number;
}
interface Bearing {
unitCode: string;
value: number;
}
interface RelativeLocation {
type: string;
geometry: Coordinate;
properties: {
city: string;
state: string;
distance: Distance;
bearing: Bearing;
};
}
interface Properties {
"@id": string;
"@type": string;
cwa: string;
forecastOffice: string;
gridId: string;
gridX: number;
gridY: number;
forecast: string;
forecastHourly: string;
forecastGridData: string;
observationStations: string;
relativeLocation: RelativeLocation;
forecastZone: string;
county: string;
fireWeatherZone: string;
timeZone: string;
radarStation: string;
}
interface WeatherData {
id: string;
type: string;
geometry: Coordinate;
properties: Properties;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.