34935-vm/api/wildfires.php
Flatlogic Bot 0dc274f7fa wildfires
2025-10-13 17:02:37 +00:00

41 lines
1.3 KiB
PHP

<?php
// Fetches wildfire data from WFIGS and returns as JSON
header('Content-Type: application/json');
// The ArcGIS REST API endpoint for current wildfire perimeters
$url = 'https://services3.arcgis.com/T4QMspbfLg3qTGWY/arcgis/rest/services/WFIGS_Interagency_Perimeters_Current/FeatureServer/0/query?where=1=1&outFields=poly_IncidentName,poly_Acres_AutoCalc,attr_InitialResponseDateTime,attr_PercentContained&f=geojson';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'worldsphere.ai bot'); // Some APIs require a user agent
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
echo json_encode(['error' => 'Could not fetch wildfire data.']);
exit;
}
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo json_encode(['error' => 'Could not parse wildfire data.']);
exit;
}
$features = $data['features'] ?? [];
$wildfires = [];
foreach ($features as $feature) {
$properties = $feature['properties'];
$wildfires[] = [
'name' => $properties['poly_IncidentName'],
'acres' => $properties['poly_Acres_AutoCalc'],
'started' => $properties['attr_InitialResponseDateTime'],
'percent_contained' => $properties['attr_PercentContained'],
];
}
echo json_encode($wildfires);
?>