3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Azure Maps Weather Services API の天気予報を試してみる

Posted at

今回は、2019年10月末にプレビュー版として発表された Azure Maps Weather Services を使用して天気予報の API の精度を試してみようと思います。

Azure Maps Weather Servies の概要

2019年10月末に発表されたニュースによると、Microsoft と大手天気プロバイダー AccuWeather がパートナーシップを結びました。
それにより、Azure の地理情報サービスである、Azure Maps の API として天気予報を見れるようになったみたいです。

雨の日も晴れの日も Azure Maps Weather Services で分析情報を取得
https://azure.microsoft.com/ja-jp/blog/rain-or-shine-azure-maps-weather-services-will-bring-insights-to-your-enterprise/

主に IoT や地図を使用した Web Apps 向けの API のように見えますが、Accu Weather の天気データべースを用いた大規模なサービスに発展する可能性を期待します。

Azure Maps をデプロイする

まずは Azure Maps をデプロイします。Azure Portal から感覚的に非常に簡単でデプロイ出来ます。

image.png

デプロイが完了すると左のメニューの SettingAuthentication から API Key を取得出来ます。
Primary と Secoundary Key がありますが、ここでは特になにも考えず、Secoudary Key を使用することにします。

image.png

これで Azure Maps を使用する準備が整いました。あとは API Key を呼び出す URL を作成するのみです。(超簡単ですね!!)

天気予報を Json 形式で呼び出す

以下のページが Azure Maps Weather Servies の諸々のパラメータが纏まっています。

Weather
https://docs.microsoft.com/en-us/rest/api/maps/weather

今回は1日の天気予報を予測するため、Daily Forecast の REST SPI を参考にしてみます。

Weather - Get Daily Forecast Preview
https://docs.microsoft.com/en-us/rest/api/maps/weather/getdailyforecastpreview

今回は品川区の天気予報を呼び出してみます。品川駅の緯度経度を調べると、35.628471,139.73876です。
REST API を呼び出すには、以下の URL を使用します。

https://atlas.microsoft.com/weather/forecast/daily/json?subscription-key={subscription-key}&api-version=1.0&query={query}

この Query の部分に品川駅の緯度経度を入力します。Subscription-key には先ほど取得した、Auzre Maps の API Key を入力します。
入力した URL をそのままブラウザに貼り付けます。すると以下の結果が返ってきます。

{
  "summary": {
    "startDate": "2020-01-07T22:00:00+00:00",
    "endDate": "2020-01-08T10:00:00+00:00",
    "severity": 3,
    "phrase": "Rain Wednesday",
    "category": "rain"
  },
  "forecasts": [
    {
      "date": "2020-01-05T22:00:00+00:00",
      "temperature": {
        "minimum": {
          "value": 3.3,
          "unit": "C",
          "unitType": 17
        },
        "maximum": {
          "value": 11.7,
          "unit": "C",
          "unitType": 17
        }
      },
      "realFeelTemperature": {
        "minimum": {
          "value": 0.6,
          "unit": "C",
          "unitType": 17
        },
        "maximum": {
          "value": 11.1,
          "unit": "C",
          "unitType": 17
        }
      },
      "realFeelTemperatureShade": {
        "minimum": {
          "value": 0.6,
          "unit": "C",
          "unitType": 17
        },
        "maximum": {
          "value": 10.0,
          "unit": "C",
          "unitType": 17
        }
      },
      "hoursOfSun": 8.1,
      "degreeDaySummary": {
        "heating": {
          "value": 10.0,
          "unit": "C",
          "unitType": 17
        },
        "cooling": {
          "value": 0.0,
          "unit": "C",
          "unitType": 17
        }
      },
      "airAndPollen": [
        {
          "name": "AirQuality",
          "value": 0,
          "category": "Good",
          "categoryValue": 1,
          "type": "Particle Pollution"
        },
        {
          "name": "Grass",
          "value": 0,
          "category": "Low",
          "categoryValue": 1
        },
        {
          "name": "Mold",
          "value": 0,
          "category": "Low",
          "categoryValue": 1
        },
        {
          "name": "Tree",
          "value": 0,
          "category": "Low",
          "categoryValue": 1
        },
        {
          "name": "Ragweed",
          "value": 0,
          "category": "Low",
          "categoryValue": 1
        },
        {
          "name": "UVIndex",
          "value": 3,
          "category": "Moderate",
          "categoryValue": 2
        }
      ],
      "day": {
        "iconCode": 6,
        "iconPhrase": "Mostly cloudy",
        "hasPrecipitation": false,
        "shortPhrase": "Becoming cloudy",
        "longPhrase": "Breezy this morning; increasing cloudiness",
        "precipitationProbability": 11,
        "thunderstormProbability": 0,
        "rainProbability": 11,
        "snowProbability": 0,
        "iceProbability": 0,
        "wind": {
          "direction": {
            "degrees": 355.0,
            "localizedDescription": "N"
          },
          "speed": {
            "value": 14.5,
            "unit": "km/h",
            "unitType": 7
          }
        },
        "windGust": {
          "direction": {
            "degrees": 355.0,
            "localizedDescription": "N"
          },
          "speed": {
            "value": 43.5,
            "unit": "km/h",
            "unitType": 7
          }
        },
        "totalLiquid": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "rain": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "snow": {
          "value": 0.0,
          "unit": "cm",
          "unitType": 4
        },
        "ice": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "hoursOfPrecipitation": 0.0,
        "hoursOfRain": 0.0,
        "hoursOfSnow": 0.0,
        "hoursOfIce": 0.0,
        "cloudCover": 26
      },
      "night": {
        "iconCode": 38,
        "iconPhrase": "Mostly cloudy",
        "hasPrecipitation": false,
        "shortPhrase": "Mostly cloudy",
        "longPhrase": "Mostly cloudy",
        "precipitationProbability": 17,
        "thunderstormProbability": 0,
        "rainProbability": 14,
        "snowProbability": 2,
        "iceProbability": 0,
        "wind": {
          "direction": {
            "degrees": 355.0,
            "localizedDescription": "N"
          },
          "speed": {
            "value": 12.9,
            "unit": "km/h",
            "unitType": 7
          }
        },
        "windGust": {
          "direction": {
            "degrees": 355.0,
            "localizedDescription": "N"
          },
          "speed": {
            "value": 19.3,
            "unit": "km/h",
            "unitType": 7
          }
        },
        "totalLiquid": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "rain": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "snow": {
          "value": 0.0,
          "unit": "cm",
          "unitType": 4
        },
        "ice": {
          "value": 0.0,
          "unit": "mm",
          "unitType": 3
        },
        "hoursOfPrecipitation": 0.0,
        "hoursOfRain": 0.0,
        "hoursOfSnow": 0.0,
        "hoursOfIce": 0.0,
        "cloudCover": 76
      },
      "sources": [
        "AccuWeather"
      ]
    }
  ]
}

上記の結果を読み解くと、品川駅の天気は、
最高気温 11.7度、最低気温 3.3度、天気はおおむね曇りという予報でした。

実際に AccuWeather のページで品川駅の天気を見てみると、、

image.png

このようになり、API で返ってきた結果と一致していることが分かります。
Azure Maps をデプロイするだけで天気予報まで呼び出すことができるのは非常に便利ですね!

参考

Weather
https://docs.microsoft.com/en-us/rest/api/maps/weather

Weather - Get Daily Forecast Preview
https://docs.microsoft.com/en-us/rest/api/maps/weather/getdailyforecastpreview

雨の日も晴れの日も Azure Maps Weather Services で分析情報を取得
https://azure.microsoft.com/ja-jp/blog/rain-or-shine-azure-maps-weather-services-will-bring-insights-to-your-enterprise/

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?