|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ridvanbaluyos\Noah; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* A PHP Library built for the Project NOAH API. |
|
7
|
|
|
* |
|
8
|
|
|
* See: http://noah.up.edu.ph/apidocs/ |
|
9
|
|
|
* |
|
10
|
|
|
* @package Project NOAI API |
|
11
|
|
|
* @author Ridvan Baluyos <[email protected]> |
|
12
|
|
|
* @link https://github.com/ridvanbaluyos/noah |
|
13
|
|
|
* @license MIT |
|
14
|
|
|
*/ |
|
15
|
|
|
class Noah |
|
16
|
|
|
{ |
|
17
|
|
|
const API_URL = 'http://noah.up.edu.ph/api/'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Constructor |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* |
|
30
|
|
|
* Displays a dataset of 8. Each gives details about a doppler radar |
|
31
|
|
|
* that shows the cloud cover within its respective locations (indicated |
|
32
|
|
|
* by the verbose name) and surrounding areas in a specific time period. |
|
33
|
|
|
* The processed data is a representation of the estimated direction of |
|
34
|
|
|
* cloud formation and the amount of rain that they contain. |
|
35
|
|
|
* |
|
36
|
|
|
* @return array $response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getDoppler(): array |
|
39
|
|
|
{ |
|
40
|
|
|
$url = 'doppler'; |
|
41
|
|
|
$response = $this->getData($url); |
|
42
|
|
|
|
|
43
|
|
|
return $response; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* |
|
48
|
|
|
* Displays the weather forecast for given locations for the next four days. |
|
49
|
|
|
* For each day, weather-indicating values are taken in 3-hour intervals. |
|
50
|
|
|
* |
|
51
|
|
|
* @param int $stationType - the station type |
|
52
|
|
|
* @param int $stationId - the station ID |
|
53
|
|
|
* |
|
54
|
|
|
* @return array $response |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getStationByTypeAndId($stationType = 0, $stationId = 0): array |
|
57
|
|
|
{ |
|
58
|
|
|
$url = 'station/' . $stationType . '/' . $stationId; |
|
59
|
|
|
$response = $this->getData($url); |
|
60
|
|
|
|
|
61
|
|
|
return $response; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* |
|
66
|
|
|
* Displays data about all the stations which measure the weather. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array $response |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getStations(): array |
|
71
|
|
|
{ |
|
72
|
|
|
$url = 'stations'; |
|
73
|
|
|
$response = $this->getData($url); |
|
74
|
|
|
|
|
75
|
|
|
return $response; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* |
|
80
|
|
|
* Flood maps show a contour map of flood extent and estimated water |
|
81
|
|
|
* level on an area based on recurrence interval, or the probability |
|
82
|
|
|
* of a flood event to occur. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array $response |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getFloodMaps(): array |
|
87
|
|
|
{ |
|
88
|
|
|
$url = 'flood_maps'; |
|
89
|
|
|
$response = $this->getData($url); |
|
90
|
|
|
|
|
91
|
|
|
return $response; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Displays all flood reports for the given year |
|
96
|
|
|
* |
|
97
|
|
|
* @param int $year - the year |
|
98
|
|
|
* |
|
99
|
|
|
* @return array $response |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getFloodReport($year = 2000): array |
|
102
|
|
|
{ |
|
103
|
|
|
$url = 'reports/flood/' . $year; |
|
104
|
|
|
$response = $this->getData($url); |
|
105
|
|
|
|
|
106
|
|
|
return $response; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* |
|
111
|
|
|
* Documentation for WMS getmap request can be found here in the geoserver site |
|
112
|
|
|
* See (http://docs.geoserver.org/stable/en/user/services/wms/reference.html). |
|
113
|
|
|
* |
|
114
|
|
|
* @return array $response |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getLandslideMaps(): array |
|
117
|
|
|
{ |
|
118
|
|
|
$url = 'landslide_maps'; |
|
119
|
|
|
$response = $this->getData($url); |
|
120
|
|
|
|
|
121
|
|
|
return $response; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* |
|
126
|
|
|
* Documentation for WMS getmap request can be found here in the geoserver site |
|
127
|
|
|
* See (http://docs.geoserver.org/stable/en/user/services/wms/reference.html). |
|
128
|
|
|
* |
|
129
|
|
|
* @return array $response |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getStormSurgeMaps(): array |
|
132
|
|
|
{ |
|
133
|
|
|
$url = 'storm_surge_maps'; |
|
134
|
|
|
$response = $this->getData($url); |
|
135
|
|
|
|
|
136
|
|
|
return $response; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* |
|
141
|
|
|
* Displays the rain forecast for given locations for the next four hours, measured every 10 minutes. |
|
142
|
|
|
* |
|
143
|
|
|
* @return array $response |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getFourHourForecast(): array |
|
146
|
|
|
{ |
|
147
|
|
|
$url = 'four_hour_forecast'; |
|
148
|
|
|
$response = $this->getData($url); |
|
149
|
|
|
|
|
150
|
|
|
return $response; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* |
|
155
|
|
|
* Displays the weather forecast for given locations for the next seven days. For each day, |
|
156
|
|
|
* weather-indicating values are taken in 3-hour intervals. |
|
157
|
|
|
* |
|
158
|
|
|
* @param int $locationId - the location ID (i don't know yet what this is). |
|
159
|
|
|
* @return array $response |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getSevenDayForecast($locationId = null): array |
|
162
|
|
|
{ |
|
163
|
|
|
$url = 'seven_day_forecast'; |
|
164
|
|
|
if (!is_null($locationId)) { |
|
165
|
|
|
$url .= '/' . $locationId; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$response = $this->getData($url); |
|
169
|
|
|
|
|
170
|
|
|
return $response; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* |
|
175
|
|
|
* Displays a dataset of 4. Each gives information about a |
|
176
|
|
|
* contour map highlighting a weather-indicating measurement. |
|
177
|
|
|
* |
|
178
|
|
|
* @return array $response |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getLatestContour(): array |
|
181
|
|
|
{ |
|
182
|
|
|
$url = 'latest_contour'; |
|
183
|
|
|
$response = $this->getData($url); |
|
184
|
|
|
|
|
185
|
|
|
return $response; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* |
|
190
|
|
|
* Displays a dataset of 6, (2 for HIMAWARI8 2 for GSMAP). |
|
191
|
|
|
* HIMAWARI. Displays HIMAWARI8 imagery updated every 10 minutes. |
|
192
|
|
|
* In the presence of a tropical cyclone within the bounds of the |
|
193
|
|
|
* imagery, clouds are seen swirling around the eye of the typhoon. |
|
194
|
|
|
* The NOAH website shows the latest 12 animated HIMAWARI8 images |
|
195
|
|
|
* which provides a crude direction of the typhoon’s path. |
|
196
|
|
|
* |
|
197
|
|
|
* GSMAP. Displays GSMAP imagery updated every 30 minutes. GSMAP |
|
198
|
|
|
* shows the satellite-estimated precipitation. |
|
199
|
|
|
* This displays 5 datasets: the current GSMAP estimate, and the |
|
200
|
|
|
* GSMAP estimate for 1hr, 3hr, 6hr, and 12hrs. |
|
201
|
|
|
* |
|
202
|
|
|
* If these satellite images are to be used, please include the following |
|
203
|
|
|
* as usage disclosure, “Use of the Himawari/GSMAP images are limited to |
|
204
|
|
|
* non-profit purposes, such as research and education.” |
|
205
|
|
|
* |
|
206
|
|
|
* @return array $response |
|
207
|
|
|
*/ |
|
208
|
|
|
public function getMtSat(): array |
|
209
|
|
|
{ |
|
210
|
|
|
$url = 'mtsat'; |
|
211
|
|
|
$response = $this->getData($url); |
|
212
|
|
|
|
|
213
|
|
|
return $response; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* This function sends the CURL request to the NOAH API Server and |
|
218
|
|
|
* decodes the json response to an array. |
|
219
|
|
|
* |
|
220
|
|
|
* @return array $response |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getData($url): array |
|
223
|
|
|
{ |
|
224
|
|
|
$ch = curl_init(); |
|
225
|
|
|
curl_setopt($ch, CURLOPT_URL, self::API_URL . $url); |
|
226
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
227
|
|
|
$response = curl_exec($ch); |
|
228
|
|
|
curl_close($ch); |
|
229
|
|
|
|
|
230
|
|
|
$response = json_decode($response, true); |
|
231
|
|
|
|
|
232
|
|
|
return $response; |
|
233
|
|
|
} |
|
234
|
|
|
} |