A
Austin Althouse
Guest
Hello,
I am making a weather application that I want to display weather observations from the National Weather Service using their API. I am already getting forecasts from this API and I am trying to use the same code layout but the problem is where it says periods is not the same and it says features. Here is my code:
Private Sub NWS_Conditions()
Using WB As New WebClient
Try
WB.Headers.Add("User-Agent", "NWIDC Digital HD/v1.0 (website; email")
Dim ObservationData As String = WB.DownloadString($"https://api.weather.gov/zones/forecast/{My.Settings.NWS_Wx_Forecast}/observations")
Dim weather As WeatherData = JsonConvert.DeserializeObject(Of WeatherData)(ObservationData)
Dim features As features = New features
Label15.Text = weather.periods(0).detailedForecast
Label41.Text = weather.periods(0).name
My.Settings.Forecast_Time = weather.periods(0).name
Label17.Text = weather.periods(1).detailedForecast
Label18.Text = weather.periods(1).name
My.Settings.Forecast_Time_2 = weather.periods(1).name
Catch ex As Exception
End Try
End Using
End Sub
Where it says forecast will be replaced, where it says features is where I am stuck at. I want to be able to display the observations in their own label and have the icon display in a picture box. Here is the NWS's JSON file.
{
"@context": [
"https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
{
"wx": "https://api.weather.gov/ontology#",
"s": "Home - schema.org",
"geo": "http://www.opengis.net/ont/geosparql#",
"unit": "http://codes.wmo.int/common/unit/",
"@vocab": "https://api.weather.gov/ontology#",
"geometry": {
"@id": "s:GeoCoordinates",
"@type": "geo:wktLiteral"
},
"city": "s:addressLocality",
"state": "s:addressRegion",
"distance": {
"@id": "sistance",
"@type": "s:QuantitativeValue"
},
"bearing": {
"@type": "s:QuantitativeValue"
},
"value": {
"@id": "s:value"
},
"unitCode": {
"@id": "s:unitCode",
"@type": "@id"
},
"forecastOffice": {
"@type": "@id"
},
"forecastGridData": {
"@type": "@id"
},
"publicZone": {
"@type": "@id"
},
"county": {
"@type": "@id"
}
}
],
"type": "FeatureCollection",
"features": [
{
"id": "https://api.weather.gov/stations/KEQA/observations/2020-04-04T18:35:00+00:00",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-96.810000000000002,
37.780000000000001
]
},
"properties": {
"@id": "https://api.weather.gov/stations/KEQA/observations/2020-04-04T18:35:00+00:00",
"@type": "wx:ObservationStation",
"elevation": {
"value": 420,
"unitCode": "unit:m"
},
"station": "https://api.weather.gov/stations/KEQA",
"timestamp": "2020-04-04T18:35:00+00:00",
"rawMessage": "KEQA 041835Z AUTO 04007KT 10SM OVC015 05/00 A3014 RMK AO2",
"textDescription": "Cloudy",
"icon": "https://api.weather.gov/icons/land/day/ovc?size=medium",
"presentWeather": [],
"temperature": {
"value": 5,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"dewpoint": {
"value": 0,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"windDirection": {
"value": 40,
"unitCode": "unit:degree_(angle)",
"qualityControl": "qc:V"
},
"windSpeed": {
"value": 3.6000000000000001,
"unitCode": "unit:m_s-1",
"qualityControl": "qc:V"
},
"windGust": {
"value": null,
"unitCode": "unit:m_s-1",
"qualityControl": "qc:Z"
},
"barometricPressure": {
"value": 102070,
"unitCode": "unita",
"qualityControl": "qc:V"
},
"seaLevelPressure": {
"value": null,
"unitCode": "unita",
"qualityControl": "qc:Z"
},
"visibility": {
"value": 16090,
"unitCode": "unit:m",
"qualityControl": "qc:C"
},
"maxTemperatureLast24Hours": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": null
},
"minTemperatureLast24Hours": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": null
},
"precipitationLastHour": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"precipitationLast3Hours": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"precipitationLast6Hours": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"relativeHumidity": {
"value": 70.097333034191109,
"unitCode": "unitercent",
"qualityControl": "qc:C"
},
"windChill": {
"value": 2.0994068752869453,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"heatIndex": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"cloudLayers": [
{
"base": {
"value": 460,
"unitCode": "unit:m"
},
"amount": "OVC"
}
]
}
},
Any help will be greatly appreciated!
Thank You!
Continue reading...
I am making a weather application that I want to display weather observations from the National Weather Service using their API. I am already getting forecasts from this API and I am trying to use the same code layout but the problem is where it says periods is not the same and it says features. Here is my code:
Private Sub NWS_Conditions()
Using WB As New WebClient
Try
WB.Headers.Add("User-Agent", "NWIDC Digital HD/v1.0 (website; email")
Dim ObservationData As String = WB.DownloadString($"https://api.weather.gov/zones/forecast/{My.Settings.NWS_Wx_Forecast}/observations")
Dim weather As WeatherData = JsonConvert.DeserializeObject(Of WeatherData)(ObservationData)
Dim features As features = New features
Label15.Text = weather.periods(0).detailedForecast
Label41.Text = weather.periods(0).name
My.Settings.Forecast_Time = weather.periods(0).name
Label17.Text = weather.periods(1).detailedForecast
Label18.Text = weather.periods(1).name
My.Settings.Forecast_Time_2 = weather.periods(1).name
Catch ex As Exception
End Try
End Using
End Sub
Where it says forecast will be replaced, where it says features is where I am stuck at. I want to be able to display the observations in their own label and have the icon display in a picture box. Here is the NWS's JSON file.
{
"@context": [
"https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
{
"wx": "https://api.weather.gov/ontology#",
"s": "Home - schema.org",
"geo": "http://www.opengis.net/ont/geosparql#",
"unit": "http://codes.wmo.int/common/unit/",
"@vocab": "https://api.weather.gov/ontology#",
"geometry": {
"@id": "s:GeoCoordinates",
"@type": "geo:wktLiteral"
},
"city": "s:addressLocality",
"state": "s:addressRegion",
"distance": {
"@id": "sistance",
"@type": "s:QuantitativeValue"
},
"bearing": {
"@type": "s:QuantitativeValue"
},
"value": {
"@id": "s:value"
},
"unitCode": {
"@id": "s:unitCode",
"@type": "@id"
},
"forecastOffice": {
"@type": "@id"
},
"forecastGridData": {
"@type": "@id"
},
"publicZone": {
"@type": "@id"
},
"county": {
"@type": "@id"
}
}
],
"type": "FeatureCollection",
"features": [
{
"id": "https://api.weather.gov/stations/KEQA/observations/2020-04-04T18:35:00+00:00",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-96.810000000000002,
37.780000000000001
]
},
"properties": {
"@id": "https://api.weather.gov/stations/KEQA/observations/2020-04-04T18:35:00+00:00",
"@type": "wx:ObservationStation",
"elevation": {
"value": 420,
"unitCode": "unit:m"
},
"station": "https://api.weather.gov/stations/KEQA",
"timestamp": "2020-04-04T18:35:00+00:00",
"rawMessage": "KEQA 041835Z AUTO 04007KT 10SM OVC015 05/00 A3014 RMK AO2",
"textDescription": "Cloudy",
"icon": "https://api.weather.gov/icons/land/day/ovc?size=medium",
"presentWeather": [],
"temperature": {
"value": 5,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"dewpoint": {
"value": 0,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"windDirection": {
"value": 40,
"unitCode": "unit:degree_(angle)",
"qualityControl": "qc:V"
},
"windSpeed": {
"value": 3.6000000000000001,
"unitCode": "unit:m_s-1",
"qualityControl": "qc:V"
},
"windGust": {
"value": null,
"unitCode": "unit:m_s-1",
"qualityControl": "qc:Z"
},
"barometricPressure": {
"value": 102070,
"unitCode": "unita",
"qualityControl": "qc:V"
},
"seaLevelPressure": {
"value": null,
"unitCode": "unita",
"qualityControl": "qc:Z"
},
"visibility": {
"value": 16090,
"unitCode": "unit:m",
"qualityControl": "qc:C"
},
"maxTemperatureLast24Hours": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": null
},
"minTemperatureLast24Hours": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": null
},
"precipitationLastHour": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"precipitationLast3Hours": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"precipitationLast6Hours": {
"value": null,
"unitCode": "unit:m",
"qualityControl": "qc:Z"
},
"relativeHumidity": {
"value": 70.097333034191109,
"unitCode": "unitercent",
"qualityControl": "qc:C"
},
"windChill": {
"value": 2.0994068752869453,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"heatIndex": {
"value": null,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"cloudLayers": [
{
"base": {
"value": 460,
"unitCode": "unit:m"
},
"amount": "OVC"
}
]
}
},
Any help will be greatly appreciated!
Thank You!
Continue reading...