生育予測情報:GrowingForecast
- 公開日
 
- 更新日 2024-11-19
 
利用条件
概要
API名称
カテゴリー
説明
本APIはビジョンテック提供の生育予測情報を取得する為のAPIです。 本APIの利用には、ビジョンテックとのライセンス契約が必要となります。 ライセンス契約につきましては、ビジョンテック(tec@vti.co.jp)にお問い合わせください。
添付ファイル
ー
データの更新頻度
リクエスト
新URL
New!
ー
旧URL(2025年度末で終了予定)
https://api.wagri.net/API/Public/GrowthVti/GrowingForecast?userid={userid}&authkey={authkey}&padlat={padlat}&padlng={padlng}&cropid={cropid}&varid={varid}&calctype={calctype}&transtype={transtype}&transdate={transdate}&transdvi={transdvi}&leafage={leafage}&posture={posture}&constgv0={constgv0}&constth={constth}&consta={consta}&constlc={constlc}&constb={constb}&constdviborder={constdviborder}&constgr={constgr}&consttcr={consttcr}&constkcr={constkcr}&correctionearemergence={correctionearemergence}&correctionmaturation={correctionmaturation}&pasttransdate1={pasttransdate1}&pasttransdvi1={pasttransdvi1}&pastleafage1={pastleafage1}&pastposture1={pastposture1}&pastearemergence1={pastearemergence1}&pastmaturation1={pastmaturation1}&pasttransdate2={pasttransdate2}&pasttransdvi2={pasttransdvi2}&pastleafage2={pastleafage2}&pastposture2={pastposture2}&pastearemergence2={pastearemergence2}&pastmaturation2={pastmaturation2}&pasttransdate3={pasttransdate3}&pasttransdvi3={pasttransdvi3}&pastleafage3={pastleafage3}&pastposture3={pastposture3}&pastearemergence3={pastearemergence3}&pastmaturation3={pastmaturation3}&callback={callback}&help={help}
説明
本メソッドは水稲発育予測メソッドです。
水稲の発育ステージの予測に利用できます。 また、実測データをもとに予測結果を調整することができます。
本メソッドの利用には、認証キー発行メソッドから認証キーを取得してパラメータにセットする必要があります。 認証キーの取得につきましては、認証キー発行メソッド(AuthenticationKey)の説明をご参照ください。
圃場位置、播種/移植日、品種をパラメータとして、幼穂形成期、出穂期、成熟期の年月日を出力します。 移植の場合は葉齢などの状態から移植日時点の生長度(DVI)を求めた上で計算が行われます。 「過去の移植日、苗の状態、出穂期」を入力すると出穂期モデルの調整をすることができます。 「過去の移植日、苗の状態、成熟期」を入力すると成熟期モデルの調整をすることができます。
また、パラメータに「help=true」をセットにして送信することで、 このAPIで使用できるパラメータの一覧や必須項目情報、フォーマットなどを出力します。
HTTPメソッド
パラメータ
URLデータ定義
発育予測情報取得
| 名称 | 型 | サイズ | 値の説明 | 
|---|---|---|---|
| userid | ユーザーID | string | Required | 
| authkey | 認証キー | string | Required | 
| padlat | 圃場緯度 | number | Required | 
| padlng | 圃場経度 | number | Required | 
| cropid | 作物ID | integer | Required | 
| varid | 品種ID | integer | Required | 
| calctype | 発育計算式区分 | integer | |
| transtype | 播種/移植区分 | integer | |
| transdate | 播種/移植日 | string | Required Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$  | 
| transdvi | 移植時DVI値 | number | |
| leafage | 葉齢 | number | |
| posture | 苗姿 | integer | |
| constgv0 | 発育予測係数 – Gv0 | number | |
| constth | 発育予測係数 – Th | number | |
| consta | 発育予測係数 – A | number | |
| constlc | 発育予測係数 – Lc | number | |
| constb | 発育予測係数 – B | number | |
| constdviborder | 発育予測係数 – DVI | number | |
| constgr | 発育予測係数 – Gr | number | |
| consttcr | 発育予測係数 – Tcr | number | |
| constkcr | 発育予測係数 – Kcr | number | |
| correctionearemergence | 出穂期の発育補正係数 | number | |
| correctionmaturation | 成熟期の発育補正係数 | number | |
| pasttransdate1 | 実測の播種/移植日1 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pasttransdvi1 | 移植時DVI値1 | number | |
| pastleafage1 | 実測の葉齢1 | number | |
| pastposture1 | 実測の苗姿1 | integer | |
| pastearemergence1 | 実測の出穂期1 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pastmaturation1 | 実測の成熟期1 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pasttransdate2 | 実測の播種/移植日2 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pasttransdvi2 | 移植時DVI値2 | number | |
| pastleafage2 | 実測の葉齢2 | number | |
| pastposture2 | 実測の苗姿2 | integer | |
| pastearemergence2 | 実測の出穂期2 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pastmaturation2 | 実測の成熟期2 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pasttransdate3 | 実測の播種/移植日3 ※以降「pasttransdate」+連番で追加 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pasttransdvi3 | 移植時DVI値3 ※以降「pasttransdvi」+連番で追加 | number | |
| pastleafage3 | 実測の葉齢3 ※以降「pastleafage」+連番で追加 | number | |
| pastposture3 | 実測の苗姿3 ※以降「pastposture」+連番で追加 | integer | |
| pastearemergence3 | 実測の出穂期3 ※以降「pastearemergence」+連番で追加 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| pastmaturation3 | 実測の成熟期3 ※以降「pastmaturation」+連番で追加 | string | Pattern: ^[0-9]{4}/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])$ | 
| callback | コールバック識別子 | string | |
| help | ヘルプモードフラグ | string | 
新呼出例
New!
ー
旧呼出例(2025年度末で終了予定)
ー
レスポンス
レイアウト
レスポンスデータ定義
Result
| 名称 | 型 | サイズ | 値の説明 | 
|---|---|---|---|
| Result | string | ||
| ResultStatus | リザルトステータス | string | |
| ErrCode | エラーコード | string | |
| ErrMsg | エラーメッセージ | string | |
| ServerTime | APIサーバの処理日時 | string | Format: yyyy-MM-dd HH:mm:ss.ffff | 
| ForeCastDates | 推測日群 | string | |
| Panicle | 幼穂形成期 | string | Format: yyyy-MM-dd | 
| EarEmergence | 出穂期 | string | Format: yyyy-MM-dd | 
| Maturation | 収穫期 | string | Format: yyyy-MM-dd | 
| TransitionDvis | 移植日からのDVI値 | array of TransitionDvis | Remarks: 播種/移植日~成熟期まで | 
| AdjustmentConsts | 発育予測係数 | string | |
| constgv0 | 発育予測係数 – Gv0 | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constth | 発育予測係数 – Th | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| consta | 発育予測係数 – A | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constlc | 発育予測係数 – Lc | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constb | 発育予測係数 – B | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constdviborder | 発育予測係数 – DVI | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constgr | 発育予測係数 – Gr | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| consttcr | 発育予測係数 – Tcr | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
| constkcr | 発育予測係数 – Kcr | string | Format: 000000.000 Remarks: 計算に使用した係数  | 
レスポンス例
ー
ステータスコード
| コード | 名称 | 値の説明 | 
|---|---|---|
| 400 | Bad Request | リクエストが不正です。 | 
| 401 | Unauthorized | 認証情報が不正です。 | 
| 403 | Forbidden | リソースのアクセスが禁止されています。 | 
| 500 | Internal Server Error | サーバー内部でエラーが発生しました。 | 
サンプルソースコード
プログラム記述例(WAGRI共通)
import requests
url = "https://api.wagri.net/API/Public/AgriculturalLand/SearchByCityCode"
payload = {
'CityCode': '432041'
}
headers = {
'X-Authorization': 'アクセストークン',
}
response = requests.get(url, headers=headers, params=payload)
print(response.text)
プログラム記述例(個別API)
PHP
1)WAGRIアクセストークン認証用スクリプト
WAGRIのアクセストークンを取得する為のスクリプトです。
WAGRI_checkAuth.php
<?php
require_once 'FileController.php';
$client_id="****";
$client_secret="****";
$url = "https://api.wagri.net/Token";
$headers = array(
    'Content-Type: application/x-www-form-urlencoded',
);
$data = array(
    'grant_type' => "client_credentials",
    'client_id' => $client_id,
    'client_secret' => $client_secret
);
$content = http_build_query($data);
$options = array('http' => array(
    'method' => 'POST',
    'content' => $content,
    'header' => implode("\r\n", $headers),
    'ignore_errors' => true,
));
$out = file_get_contents($url, false, stream_context_create($options));
preg_match("/[0-9]{3}/", $http_response_header[0], $stcode);
if((int)$stcode[0] >= 200 && (int)$stcode[0] <= 299){
    $result = json_decode($out);
    print_r($result);
    $controller = new FileController();
    $controller->setToken($result);
} else {
    throw new Exception("リクエストが不正です。\n");
}
?>
4行 $client_id=””; 5行 $client_secret=””; の「****」にWAGRIのclient_id、client_secretの入力が必要です。
2)GrowthVtiを使うための認証用スクリプト
GrowthVtiを使用するための認証キーを取得する為のスクリプトです。
checkAuth_token.php
<?php
require_once 'FileController.php';
$controller = new FileController();
$token = $controller->getToken();
if($token === false){
    return false;
}
$url = "https://api.wagri.net/API/Public/GrowthVti/AuthenticationKey?";
$header = array("X-Authorization:" . $token);
$context = array(
    "http" => array(
        "method"  => "GET",
    "content-type" => "json",
        "header"  => implode("\r\n",$header),
        'ignore_errors' => true,
    )
);
$userid="****";
$pass="****";
$url = $url . "userid=" .$userid ."&password=" .$pass;
$out = file_get_contents($url, false, stream_context_create($context));
preg_match("/[0-9]{3}/", $http_response_header[0], $stcode);
if((int)$stcode[0] >= 200 && (int)$stcode[0] <= 299){
    $result = json_decode($out);
    print_r($result);
    $controller->setAuthKey($userid, $result);
} else {
    throw new Exception("リクエストが不正です。\n");
}
?>
22行 $userid=””; 23行 $pass=””; の「****」にビジョンテックが提供したユーザID、パスワードの入力が必要です。
3)水稲発育予測API実行スクリプト
水稲発育予測APIを実行するためのスクリプトです。
checkGrowing_token.php
<?php
require_once 'FileController.php';
$controller = new FileController();
//== ID設定 ==
$Authorization = $controller->getToken();
if($Authorization === false){
    return false;
}
$auth = $controller->getAuthKey();
if($auth === false){
    return false;
}
$userid=$auth['userid'];
$authkey=$auth['authkey'];
$url = "https://api.wagri.net/API/Public/GrowthVti/GrowingForecast?";
//== パラメータ設定 ==
$padlat="35.4692";
$padlng="134.245";
$cropid="1";
$varid="1";
$calctype="1";
$transtype="1";
$transdate="2015-05-10";
$transdvi="0.2";
$constgv0="51.3000";
$constth="17.8000";
$constta="0.3650";
$constlc="16.0000";
$constb="0.5660";
$constdviborder="0.2300";
$constgr="28.8000";
$consttcr="12.7000";
$constkcr="0.1180";
//=====================
$header = array("X-Authorization:".$Authorization);
$context = array(
    "http" => array(
        "method"  => "GET",
    "content-type" => "json",
        "header"  => implode("\r\n",$header),
    )
);
$url = $url.
"userid=" .$userid .
"&authkey=" .$authkey.
"&padlat=" .$padlat.
"&padlng=" .$padlng.
"&cropid=" .$cropid.
"&varid=" .$varid.
"&calctype=" .$calctype.
"&transtype=" .$transtype.
"&transdate=" .$transdate.
"&transdvi=" .$transdvi.
"&constgv0=" .$constgv0.
"&constth=" .$constth.
"&constta=" .$constta.
"&constlc=" .$constlc.
"&constb=" .$constb.
"&constdviborder=" .$constdviborder.
"&constgr=" .$constgr.
"&consttcr=" .$consttcr.
"&constkcr=" .$constkcr;
$out = file_get_contents($url, false, stream_context_create($context));
$result = json_decode($out);
print_r($result);
?>
4)取得したキーをファイル入出力するスクリプト
取得したキーをファイル入出力するスクリプトです。 ※当スクリプトではファイル出力を行っておりますが、トークンの盗難防止の為本来はデータベース等への保存を推奨しています。
FileController.php
<?php
class FileController{
    private $token_file = "files/token.txt";
    private $auth_file = "files/authkey.txt";
    private $get_token_file = "WAGRI_checkAuth.php";
    private $get_authkey_file = "checkAuth_token.php";
    public function deleteToken(){
        if($this->existsToken()){
            unlink($this->token_file);
        }
    }
    public function deleteAuthKey(){
        if($this->existsAuthKey()){
            unlink($this->auth_file);
        }
    }
    public function existsToken(){
        return file_exists($this->token_file);
    }
    public function execWAGRIGetToken(){
        $cmd = "php " . $this->get_token_file;
        system($cmd, $return_var);
        return $return_var;
    }
    public function setToken($tokenObject){
        if(empty($tokenObject) || empty($tokenObject->access_token)){
            echo "Tokenの取得に失敗しました。\n";
            return false;
        }
        return file_put_contents($this->token_file, $tokenObject->access_token);
    }
    public function getToken(){
        if(!$this->existsToken()){
            $result = $this->execWAGRIGetToken();
            if($result !== 0){
                echo "Tokenの取得に失敗しました。\n";
                return false;
            }
        }
        $token = file_get_contents($this->token_file);
        if($token === false || empty($token)){
            echo "Tokenの読み込みに失敗しました。\n";
            $this->deleteToken();
            return false;
        }
        return $token;
    }
    public function existsAuthKey(){
        return file_exists($this->auth_file);
    }
    public function execGetAuthKey(){
        $cmd = "php " . $this->get_authkey_file;
        system($cmd, $return_var);
        return $return_var;
    }
    public function setAuthKey($userid, $authObject){
        if(empty($authObject) || $authObject->Result->ResultStatus->ErrCode != 0){
            echo "AuthenticationKeyの取得に失敗しました。\n";
            return false;
        }
        $content = array(
            'userid' => $userid,
            'authkey' => $authObject->Result->AuthenticationKey->Key,
        );
        return file_put_contents($this->auth_file, json_encode($content));
    }
    public function getAuthKey(){
        if(!$this->existsAuthKey()){
            $result = $this->execGetAuthKey();
            if($result !== 0){
                echo "AuthenticationKeyの取得に失敗しました。\n";
                return false;
            }
        }
        $authkeyjson = file_get_contents($this->auth_file);
        if($authkeyjson === false || empty($authkeyjson)){
            echo "AuthenticationKeyの読み込みに失敗しました。\n";
            $this->deleteAuthKey();
            return false;
        }
        $authkey = json_decode($authkeyjson, true);
        if(empty($authkey['userid']) || empty($authkey['authkey'])){
            echo "AuthenticationKeyの読み込みに失敗しました。\n";
            $this->deleteAuthKey();
            return false;
        }
        return $authkey;
    }
}
?>
実行例:
$ php WAGRI_checkAuth.php $ php checkAuth_token.php $ php checkGrowing_token.php

