Skip to content

MET API

Torgeir Slette edited this page May 9, 2018 · 9 revisions

How to use the MET API (Redundant)

We are going to use a simple form of forecasting the weather to inform/warn about the road conditions. The MET API are providing this feature for this project, and bellow is an explanation/tutorial of how to use the different API's.

How to use the Locationforecast API

The Locationforecast is an API for a full forecast for one location, for a nine-day period starting with the current day. This is our main API for the forecast data, providing us with a full fledged forecast, though we are fore the most part interested in the data connected to precipitation.

Description

The API includes data for a number of different parameters to present the forecast. The parameters are temperature, wind speed, wind direction, pressure, precipitation, cloudiness, fog, lowClouds, mediumClouds, highClouds and humidity. Though the most essential parameter for our case is the precipitation and maybe temperature. This way we can, with the inclusion of a weathericon, keep the visualization of the data to a more simplistic, clean and refined format.

Parameters

The API uses two parameters to execute the get call

  • lat , latitude in decimal degrees
  • lon , longitude in decimal degrees

Example of a request URL with lat and lon for Trondheim would be

https://api.met.no/weatherapi/locationforecast/1.9/?lat=63.446827&lon=10.421906

Layout

The format that the API deliver data in a XML file XML schema

Structure with product data from a request sent 28-02-2018 15:36

  • weatherdata xmlns:xsi="" xsi:noNamespaceSchemaLocation="" created=""
    • meta
      • model name="" termin="" runend="" nextrun="" from="" to=""
      • model name="" termin="" runend="" nextrun="" from="" to=""
    • product class="pointData"
      • time datatype="forecast" from="2018-02-28T15:00:00Z" to="2018-02-28T15:00:00Z"
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • temperature id="TTT" unit="celsius" value="-8.7"
          • windDirection id="dd" deg="110.1" name="E"
          • windSpeed id="ff" mps="3.7" beaufort="3" name="Lett bris"
          • windGust id="ff_gust" mps="6.6"
          • areaMaxWindSpeed mps="8.7"
          • humidity value="59.2" unit="percent"
          • pressure id="pr" unit="hPa" value="1046.7"
          • cloudiness id="NN" percent="0.0"
          • fog id="FOG" percent="0.0"
          • lowClouds id="LOW" percent="0.0"
          • mediumClouds id="MEDIUM" percent="0.0"
          • highClouds id="HIGH" percent="0.0"
          • dewpointTemperature id="TD" unit="celsius" value="-15.7"
      • time datatype="forecast" from="2018-02-28T14:00:00Z" to="2018-02-28T15:00:00Z"
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"
          • symbol id="Sun" number="1"
      • time datatype="forecast" from="2018-02-28T13:00:00Z" to="2018-02-28T15:00:00Z"
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"
          • symbol id="Sun" number="1"
      • time datatype="forecast" from="2018-02-28T12:00:00Z" to="2018-02-28T15:00:00Z"
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"
          • symbol id="Sun" number="1"

The next length of data are in the same format as the ones listed above, with the following hour as the value of "to". In this case the value is to="2018-02-28T16:00:00Z". This continues further, where the first (time) displays the data at 16:00, the second (time) displays the precipitation from 15:00 to 16:00, the third (time) displays the precipitation from 14:00 to 16:00 and the fourth (time) displays the precipitation from 13:00 to 16:00.

There is also an instance of a fifth (time) that displays the precipitation from 12:00 to 16:00 as well as the max and min for temperature, but this isn't constant. It seems that the fifth (time) isn't constantly displayed correctly, either the data is missing or the (time) isn't there at all

Further description

  • weatherdata
    • meta
      • model
      • model
    • product class="pointData"
      • time datatype="forecast" from="yyyy-mm-ddThh:mm:ssZ" to="yyyy-mm-ddThh:mm:ssZ"
        • location altitude= "meter over havet" latitude="x" longitude="y"
          • temperature id="TTT" unit="celsius" value="" Temperature is something that is relevant for the project
          • Irrelevant windDirection id="dd" deg="" name=""
          • Irrelevant windSpeed id="ff" mps="" beaufort="" name=""
          • Irrelevant windGust id="ff_gust" mps=""
          • Irrelevant areaMaxWindSpeed mps=""
          • Irrelevant humidity value="" unit="percent"
          • Irrelevant pressure id="pr" unit="hPa" value="1046.7"
          • Irrelevant cloudiness id="NN" percent="0.0"
          • Irrelevant fog id="FOG" percent="0.0"
          • Irrelevant lowClouds id="LOW" percent="0.0"
          • Irrelevant mediumClouds id="MEDIUM" percent="0.0"
          • Irrelevant highClouds id="HIGH" percent="0.0"
          • dewpointTemperature id="TD" unit="celsius" value="-15.7" Effective temperature
      • time datatype="forecast" from="2018-02-28T14:00:00Z"=N-1 to="2018-02-28T15:00:00Z"=hh=N data for the previous hour.
        • location altitude="5" latitude="x" longitude="y"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0" max and min values for snow/rain
          • symbol id="Sun" number="1" what icon that will be displayed from Weathericon API
      • time datatype="forecast" from="2018-02-28T13:00:00Z" to="2018-02-28T15:00:00Z" data for the previous two hours
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"
          • symbol id="Sun" number="1"
      • time datatype="forecast" from="2018-02-28T12:00:00Z" to="2018-02-28T15:00:00Z" data for the previous three hours
        • location altitude="5" latitude="63.4468" longitude="10.4219"
          • precipitation unit="mm" value="0.0" minvalue="0.0" maxvalue="0.0"
          • symbol id="Sun" number="1"

The overall structure of the XML is as follows

  • product
    • (first time) where hour = n
      • current data at n
    • (second time) start = n-1 and end = n
      • precipitation during this time period (1h)
    • (third time) start = n-2 and end = n
      • precipitation during this time period (2h)
    • (fourth time) start = n-3 and end = n
      • precipitation during this time period (3h)

Repeat with n+1

How to use the Weathericon API

The Weathericon is an API for displaying weathericons, for example the sun. It is only a compliment to the base MET API and doesn't include any new data besides the opportunity to visualize the weather in a neat way.

Description

The API uses the symbol id provided in the locationforecast API, where each number correlates to a symbol, for example 1 = sun, 10 = rain, etc.

Parameters

The API mainly use two parameters that are mandatory in the api call

  • symbol , an int ranging mainly from 1 to 50, providing us with the index for the symbols.
  • content_type , specifies the format of the image to be returned. Example is content_type=image/png and content_type=image/svg, witch returns the symbol as a .png and .svg respectively.

There is also two additional parameters which are non-mandatory

  • is_night , if moon-symbol is wanted, use is_night=1
  • is_polarnight , if polar night symbol is wanted, use is_polarnight=1

An exaple of an api request would look similar to this:

https://api.met.no/weatherapi/weathericon/1.1/?symbol=5&content_type=image/png

For more documentation look up the official documentation for the MET api.

Clone this wiki locally