MeteoSwissApi
.NET API for Swiss national weather provider MeteoSwiss
Install
| Product | Versions |
|---|---|
| .NET Standard |
README
MeteoSwissApi
.NET client for easy access of Swiss national weather data. This library is a private, non-commercial project and is by no means related to or maintained by the Federal Office of Meteorology and Climatology MeteoSwiss.
Download and Install MeteoSwissApi
This library is available on NuGet: https://www.nuget.org/packages/MeteoSwissApi Use the following command to install MeteoSwissApi using NuGet package manager console:
PM> Install-Package MeteoSwissApi
You can use this library in any .NET project which is compatible to .NET Standard 2.0 and higher.
API Usage
The following sections document basic use cases of this library. The following code excerpts can also be found in the sample applications.
Request weather info by PLZ
MeteoSwissWeatherService is the main entry point of this library. Create an instance of MeteoSwissWeatherService or
inject IMeteoSwissWeatherService using dependency injection techniques.
IMeteoSwissWeatherService weatherService = new MeteoSwissWeatherService(logger, weatherServiceConfiguration);
Request weather information for any Swiss zip code (plz):
var weatherInfo = await weatherService.GetCurrentWeatherAsync(plz: 6330);
Download icons
IMeteoSwissWeatherService provides methods to download icons as SVG image streams. Each method returns the icon
stream. If no real icon exists for the given identifier, a transparent 1x1 icon is returned:
| Method | Description |
|---|---|
GetWeatherIconAsync(iconId, weatherIconMapping) |
Returns the weather icon for the given icon id, e.g. weatherInfo.CurrentWeather.IconV2. |
GetWarningIconAsync(warnLevel, warningIconMapping) |
Returns the warning icon for the given warn level. MeteoSwiss provides warning icons for warn levels 2 to 5; lower warn levels return a transparent 1x1 icon. |
Download the weather icon which illustrates the current weather condition:
var weatherIconStream = await weatherService.GetWeatherIconAsync(weatherInfo.CurrentWeather.IconV2);
Weather icons are resolved via IWeatherIconMapping. By default, DefaultWeatherIconMapping downloads the original
weather icons from MeteoSwiss. Alternatively, HighContrastWeatherIconMapping serves high-contrast weather icons
embedded in this library. You can also provide your own IWeatherIconMapping implementation:
var weatherIconStream = await weatherService.GetWeatherIconAsync(weatherInfo.CurrentWeather.IconV2, new HighContrastWeatherIconMapping());
Weather warnings (weatherInfo.Warnings, weatherInfo.WarningsOverview) report a warn level between 1 and 5. For warn
levels 2 to 5, MeteoSwiss provides warning icons which can be downloaded as SVG image streams:
var warningIconStream = await weatherService.GetWarningIconAsync(WarnLevel.Level3);
Warning icons are resolved via IWarningIconMapping. By default, DefaultWarningIconMapping downloads the original
warning icons from MeteoSwiss. Alternatively, HighContrastWarningIconMapping serves high-contrast warning icons
embedded in this library. You can also provide your own IWarningIconMapping implementation:
var warningIconStream = await weatherService.GetWarningIconAsync(WarnLevel.Level3, new HighContrastWarningIconMapping());
Links
Federal Office of Meteorology and Climatology MeteoSwiss https://www.meteoschweiz.admin.ch
WSL Institute for Snow and Avalanche Research SLF www.slf.ch
Contribution
Contributors welcome! If you find a bug or you want to propose a new feature, feel free to do so by opening a new issue on github.com.
Links
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.