API Documentation

ระบบรายงานสาธารณภัยจังหวัดแม่ฮ่องสอน

Version 2.0

แนะนำ

API ของระบบรายงานสาธารณภัยจังหวัดแม่ฮ่องสอน ถูกออกแบบมาเพื่อให้หน่วยงานต่างๆ สามารถเชื่อมต่อและนำข้อมูลไปใช้ประโยชน์ต่อได้

Base URL
https://acdm.mhs-pao.go.th/api/v1/
คุณสมบัติ
  • RESTful API: ใช้ HTTP methods มาตรฐาน (GET, POST)
  • JSON Response: ข้อมูลทั้งหมดส่งกลับในรูปแบบ JSON
  • UTF-8 Encoding: รองรับภาษาไทยอย่างสมบูรณ์
  • CORS Enabled: สามารถเรียกใช้จาก client-side ได้
  • Rate Limiting: จำกัดการเรียกใช้เพื่อความมั่นคง

การยืนยันตัวตน

ปัจจุบัน API เป็นแบบ Public API ไม่ต้องใช้ API Key

หมายเหตุ: หน่วยงานที่ต้องการใช้งาน API กรุณาแจ้งให้ทางผู้ดูแลระบบทราบเพื่อบันทึกข้อมูลการใช้งาน

API Endpoints

GET /api/v1/incidents.php

ดึงข้อมูลเหตุการณ์สาธารณภัย

Parameters
Parameter Type Required Description
year integer No ปี ค.ศ. (เช่น 2025)
start_date date No วันที่เริ่มต้น (YYYY-MM-DD)
end_date date No วันที่สิ้นสุด (YYYY-MM-DD)
incident_type string No ประเภทเหตุการณ์ (อัคคีภัย, อุทกภัย, ฯลฯ)
district string No อำเภอ
severity string No ความรุนแรง (เล็กน้อย, ปานกลาง, รุนแรง)
status string No สถานะ (pending, in_progress, completed)
limit integer No จำนวนข้อมูลต่อหน้า (default: 100, max: 1000)
offset integer No เริ่มต้นจากข้อมูลลำดับที่ (default: 0)
Example Request
curl "https://acdm.mhs-pao.go.th/api/v1/incidents.php?year=2025&limit=10"
Example Response
{
  "success": true,
  "version": "2.0",
  "timestamp": "2025-11-20T12:00:00+07:00",
  "meta": {
    "total": 41,
    "limit": 10,
    "offset": 0,
    "returned": 10
  },
  "data": [
    {
      "id": "123",
      "incident_type": "อัคคีภัย",
      "report_time": "2025-11-20 08:30:00",
      "district": "เมืองแม่ฮ่องสอน",
      "sub_district": "จองคำ",
      "village": "บ้านห้วยปูลิง",
      "latitude": "19.3025",
      "longitude": "97.9647",
      "severity": "ปานกลาง",
      "affected_people": 5,
      "affected_households": 1,
      "deaths": 0,
      "injuries": 0,
      "status_key": "in_progress",
      "status_name": "กำลังดำเนินการ",
      "damage_estimate": 50000
    }
  ]
}

GET /api/v1/statistics.php

ดึงข้อมูลสถิติสาธารณภัย

Parameters
Parameter Type Required Description
year integer No ปี ค.ศ.
start_date date No วันที่เริ่มต้น
end_date date No วันที่สิ้นสุด
group_by string No จัดกลุ่มตาม (type, district, severity, month, all)

GET /api/v1/districts.php

ดึงข้อมูลรายชื่ออำเภอและตำบล

GET /api/v1/types.php

ดึงข้อมูลประเภทเหตุการณ์สาธารณภัย

Rainfall API

API สำหรับเข้าถึงข้อมูลสถานีตรวจวัดปริมาณน้ำฝนและรายงานปริมาณน้ำฝน

GET /api/v1/rainfall/stations.php

ดึงข้อมูลสถานีตรวจวัดปริมาณน้ำฝน

Query Parameters
Parameter Type Required Description
district string No กรองตามอำเภอ
sub_district string No กรองตามตำบล
station_type string No กรองตามประเภทสถานี (manual, automatic)
is_active string No กรองตามสถานะ (1=ใช้งาน, 0=ไม่ใช้งาน, all=ทั้งหมด) Default: all
station_id integer No ID ของสถานีที่ต้องการ
ตัวอย่างการเรียกใช้
// JavaScript
fetch('http://localhost/api/v1/rainfall/stations.php?district=เมืองแม่ฮ่องสอน&is_active=1')
  .then(response => response.json())
  .then(data => console.log(data));

GET /api/v1/rainfall/reports.php

ดึงข้อมูลรายงานปริมาณน้ำฝน

Query Parameters
Parameter Type Required Description
station_id integer No กรองตาม ID ของสถานี
district string No กรองตามอำเภอ
start_date date No วันที่เริ่มต้น (YYYY-MM-DD)
end_date date No วันที่สิ้นสุด (YYYY-MM-DD)
min_rainfall number No ปริมาณน้ำฝนขั้นต่ำ (มม.)
limit integer No จำนวนผลลัพธ์ต่อหน้า (Default: 100, Max: 1000)
offset integer No ข้ามผลลัพธ์กี่รายการ (สำหรับ pagination)
ตัวอย่างการเรียกใช้
# Python
import requests

url = "http://localhost/api/v1/rainfall/reports.php"
params = {
    "start_date": "2024-01-01",
    "end_date": "2024-12-31",
    "min_rainfall": 50,
    "limit": 20
}
response = requests.get(url, params=params)
data = response.json()
print(data)

GET /api/v1/rainfall/statistics.php

ดึงข้อมูลสถิติปริมาณน้ำฝน

Query Parameters
Parameter Type Required Description
group_by string No จัดกลุ่มตาม: station, district, day, month, all (Default: all)
district string No กรองตามอำเภอ (ใช้ได้เมื่อ group_by=station)
start_date date No วันที่เริ่มต้น (YYYY-MM-DD)
end_date date No วันที่สิ้นสุด (YYYY-MM-DD)
Group By Options
  • station - สถิติแยกตามสถานีตรวจวัด
  • district - สถิติแยกตามอำเภอ
  • day - สถิติรายวัน (30 วันล่าสุด)
  • month - สถิติรายเดือน (12 เดือนล่าสุด)
  • all - สถิติภาพรวมทั้งหมด
ตัวอย่างการเรียกใช้
// PHP
$url = "http://localhost/api/v1/rainfall/statistics.php?group_by=district";
$data = json_decode(file_get_contents($url), true);

if ($data['success']) {
    foreach ($data['data'] as $stat) {
        echo "{$stat['district']}: {$stat['total_rainfall']} mm\n";
    }
}

Hotspot API — จุดความร้อน

API สำหรับดึงข้อมูลจุดความร้อน (Fire Hotspot) จาก NASA FIRMS และ GISTDA VIIRS พร้อมระบบ Deduplication อัตโนมัติ

Dashboard: ดูข้อมูลแบบแผนที่ได้ที่ https://acdm.mhs-pao.go.th/hotspot/index.php

GET /get_fire_hotspots_api.php

ดึงข้อมูลจุดความร้อนจาก NASA FIRMS และ/หรือ GISTDA VIIRS พร้อม Dedup อัตโนมัติ

Cache: 5 นาที (ข้าม cache ด้วย nocache=1)
Parameters
ParameterTypeRequiredDefaultDescription
hoursintegerNo24ชั่วโมงย้อนหลัง (ใช้เมื่อไม่ระบุ start_date/end_date)
start_datedateNoวันเริ่มต้น YYYY-MM-DD (override hours)
end_datedateNoวันสิ้นสุด YYYY-MM-DD (override hours)
districtstringNoกรองตามอำเภอ (ชื่อภาษาไทย)
sourcestringNoแหล่งข้อมูล FIRMS: VIIRS หรือ MODIS
include_firmsbooleanNotrueรวมข้อมูล NASA FIRMS
include_gistdabooleanNofalseรวมข้อมูล GISTDA VIIRS
resolve_adminbooleanNofalseResolve อำเภอ/ตำบล/หมู่บ้าน ผ่าน PostGIS
resolve_levelstringNofullfull = อำเภอ+ตำบล+หมู่บ้าน, district = อำเภอเท่านั้น (เร็วกว่า)
include_outsidebooleanNofalseรวมจุดนอกเขตแม่ฮ่องสอน
nocachebooleanNofalseข้าม cache 5 นาที
Example Request
curl "https://acdm.mhs-pao.go.th/get_fire_hotspots_api.php?include_firms=1&include_gistda=1&start_date=2026-03-01&end_date=2026-03-10"
Example Response
{
  "success": true,
  "fires": [
    {
      "id": 123,
      "latitude": 19.123,
      "longitude": 98.456,
      "brightness": 312.5,
      "acq_date": "2026-03-09",
      "acq_time": "0654",
      "satellite": "N20",
      "instrument": "VIIRS",
      "confidence": "nominal",
      "frp": 2.4,
      "daynight": "N",
      "district": "เมืองแม่ฮ่องสอน",
      "tambon": "ปางหมู",
      "source": "VIIRS",
      "provider": "FIRMS"
    }
  ],
  "stats": {
    "total": 1673,
    "last_24h": 279,
    "last_48h": 1664,
    "high_confidence": 1287,
    "moderate_confidence": 386,
    "by_district": { "แม่ฮ่องสอน": 220, "แม่สะเรียง": 7, "ไม่ระบุอำเภอ": 1446 },
    "by_source": { "VIIRS": 205, "MODIS": 22, "GISTDA": 1446 }
  },
  "meta": {
    "firms_db_max_acq_date": "2026-03-09",
    "gistda_db_max_acq_date": "2026-03-09"
  }
}
หมายเหตุ Deduplication: เมื่อเปิดทั้ง FIRMS + GISTDA ระบบจะลบจุด VIIRS ซ้ำอัตโนมัติ (GISTDA เป็นหลัก) ด้วยระยะ 375m + เวลา 24 ชม. MODIS ไม่ถูก dedup

GET /get_fire_hotspot_years_api.php

ดึงรายชื่อปีที่มีข้อมูลจุดความร้อน พร้อมจำนวนรวมรายปี

Parameters
ParameterTypeRequiredDescription
sourcestringNoกรองแหล่ง: VIIRS, MODIS
include_gistdabooleanNoรวมจำนวนปีของ GISTDA VIIRS
Example Response
{
  "success": true,
  "years": [2023, 2024, 2025, 2026],
  "year_totals": {
    "2023": 15420,
    "2024": 18310,
    "2025": 22100,
    "2026": 5030
  }
}

GET /get_hotspot_daily_snapshot.php

ดึงสแนปชอตรายวันของจำนวนจุดความร้อน (บันทึกอัตโนมัติทุกวัน)

Parameters
ParameterTypeRequiredDefaultDescription
datedateNoเมื่อวานวันที่ต้องการ YYYY-MM-DD
Example Response
{
  "success": true,
  "found": true,
  "date": "2026-03-09",
  "snapshot": {
    "snapshot_date": "2026-03-09",
    "total_count": 1673,
    "firms_count": 227,
    "gistda_count": 1446,
    "captured_at": "2026-03-10 00:05:00"
  }
}

GET /get_gistda_disaster_hotspot_api.php

Proxy ไปยัง GISTDA Sphere Disaster API — ค้นหาจุดความร้อนรอบพิกัดที่ระบุ

Parameters
ParameterTypeRequiredDefaultDescription
lonfloatYesลองจิจูด (-180 ถึง 180)
latfloatYesละติจูด (-90 ถึง 90)
radiusfloatNo1000รัศมีค้นหา (เมตร)
Example Request
curl "https://acdm.mhs-pao.go.th/get_gistda_disaster_hotspot_api.php?lat=19.30&lon=97.97&radius=5000"

Burn Scar API — พื้นที่เผาไหม้

API สำหรับคำนวณและแสดงผลพื้นที่เผาไหม้จากข้อมูลดาวเทียม GISTDA รองรับทั้ง GeoJSON Features และ WMS Image Analysis

GET /get_burn_scar_area.php

คำนวณพื้นที่เผาไหม้รวม จาก GISTDA GeoJSON features หรือ WMS PNG cache

Parameters
ParameterTypeRequiredDefaultDescription
sourcestringNofeaturesfeatures = GISTDA GeoJSON, png/wms = cached WMS image
bboxstringNoBounding box: minLon,minLat,maxLon,maxLat
pv_tnstringNoแม่ฮ่องสอนจังหวัด (ภาษาไทย)
start_datedateNoวันเริ่มต้น
end_datedateNoวันสิ้นสุด
limitintegerNoจำนวน features สูงสุด

GET /get_burn_scar_area_by_admin_wms.php

พื้นที่เผาไหม้แยกตามเขตการปกครอง (อำเภอ/ตำบล/หมู่บ้าน) จาก WMS Pixel Analysis

Parameters
ParameterTypeRequiredDefaultDescription
levelstringNodistrictsระดับ: district / subdistrict / village
cache_idintegerNoล่าสุดID ของ burn_scar_cache
include_zerobooleanNotrueรวมพื้นที่ที่ไม่มีเผาไหม้
pageintegerNo1หน้า
page_sizeintegerNo0 (ทั้งหมด)จำนวนต่อหน้า (สูงสุด 200)
min_area_raifloatNo0พื้นที่เผาไหม้ขั้นต่ำ (ไร่)
strideintegerNo8Pixel sampling stride (1-32)
color_thresholdintegerNo40Burn pixel detection threshold (0-765)

GET /get_burn_scar_cache_list.php

รายการ cache ข้อมูลเผาไหม้รายสัปดาห์ (metadata เท่านั้น) พร้อมความเปลี่ยนแปลงรายสัปดาห์

Example Response
{
  "success": true,
  "count": 12,
  "data": [
    {
      "id": 5,
      "week_start": "2026-01-06",
      "week_end": "2026-01-12",
      "iso_week": "2026-W02",
      "width": 1024,
      "height": 768,
      "burn_area_rai": 1234.56,
      "weekly_change_rai": 150.30,
      "fetched_at": "2026-01-13 01:00:00"
    }
  ]
}

GET /get_burn_scar_latest_image.php

ส่งภาพ PNG เผาไหม้ล่าสุด สำหรับ overlay แผนที่

Parameters
ParameterTypeRequiredDefaultDescription
idintegerNoล่าสุดCache ID ที่ต้องการ
renderstringNoboost = เพิ่มความชัด, red = แสดงพิกเซลเผาเป็นสีแดง
Response เป็น Binary PNG (Content-Type: image/png) ไม่ใช่ JSON
APIs เกี่ยวข้อง
EndpointDescription
/get_burn_scar_latest_meta.phpMetadata ภาพเผาไหม้ล่าสุด (JSON)
/get_burn_scar_cumulative_image.php?weeks=4ภาพเผาไหม้สะสมหลายสัปดาห์ (PNG)
/get_burn_scar_cumulative_meta.php?weeks=4Metadata ภาพเผาไหม้สะสม (JSON)

GET เผาไหม้ตามการใช้ที่ดิน

วิเคราะห์พื้นที่เผาไหม้จำแนกตามประเภทการใช้ที่ดิน (ป่าไม้, เกษตร, ฯลฯ)

EndpointระดับParameters หลัก
/get_burn_scar_landuse_by_district.phpอำเภอdistrict_code, cache_id
/get_burn_scar_landuse_by_subdistrict.phpตำบลdistrict_code, subdistrict_code, cache_id
/get_burn_scar_landuse_by_village_wms.phpหมู่บ้านdistrict_code, subdistrict_code, village_id, cache_id
Example Response
{
  "success": true,
  "district_code": "01",
  "district_name": "เมืองแม่ฮ่องสอน",
  "cache_id": 15,
  "rows": [
    {
      "category": "ป่าไม้",
      "description": "ป่าเบญจพรรณ",
      "area_m2": 1600000,
      "area_rai": 1000.0,
      "pct": 45.5
    }
  ],
  "total": { "area_m2": 3520000, "area_rai": 2200.0 }
}

GET เผาไหม้ตามชั้นคุณภาพลุ่มน้ำ

วิเคราะห์เผาไหม้จำแนกตามชั้นคุณภาพลุ่มน้ำ (1A, 1B, 2, 3, 4, 5)

EndpointระดับParameters หลัก
/get_burn_scar_watershed_by_admin.phpRouterdistrict_code, cache_id, subdistrict_code(optional)
/get_burn_scar_watershed_by_district.phpอำเภอdistrict_code, cache_id
/get_burn_scar_watershed_by_subdistrict.phpตำบลdistrict_code, subdistrict_code, cache_id
/get_burn_scar_watershed_by_village_wms.phpหมู่บ้านdistrict_code, subdistrict_code, village_id, cache_id
สถิติจุดความร้อนตามลุ่มน้ำ (Realtime)
ParameterTypeDefaultDescription
GET /get_watershed_hotspot_stats_realtime_api.php
daysinteger30ย้อนหลังกี่วัน (สูงสุด 365)
start_datedateวันเริ่มต้น
end_datedateวันสิ้นสุด
categorystringชั้นลุ่มน้ำ: 1A, 1B, 2, 3, 4, 5
formatstringgeojsonjson หรือ geojson
include_burn_scarbooleanfalseรวมพื้นที่เผาไหม้ overlay

Air Quality API — คุณภาพอากาศ

API สำหรับดึงข้อมูลคุณภาพอากาศ PM2.5 / PM10 / AQI จากหลายแหล่ง (Air4Thai, DustBoy)

GET /get_air_quality_api.php

ดึงข้อมูลคุณภาพอากาศ Real-time จาก Air4Thai (กรมควบคุมมลพิษ) กรองเฉพาะสถานีในแม่ฮ่องสอน

Example Response
{
  "success": true,
  "data": [
    {
      "station_id": "58t",
      "station_name": "ต.จองคำ อ.เมือง จ.แม่ฮ่องสอน",
      "lat": 19.303,
      "lng": 97.965,
      "aqi": { "value": 120, "level": "มีผลกระทบต่อสุขภาพ", "color": "#FF7E00" },
      "pm25": { "value": 45.2, "unit": "µg/m³" },
      "pm10": { "value": 62.0, "unit": "µg/m³" }
    }
  ],
  "statistics": {
    "pm25": { "max": 45.2, "min": 30.1, "avg": 37.6 },
    "aqi": { "max": 120, "min": 85, "avg": 102 }
  },
  "source": "Air4Thai - กรมควบคุมมลพิษ"
}

GET /get_air_quality_history.php

ข้อมูลคุณภาพอากาศย้อนหลัง รายวัน/รายเดือน/รายปี พร้อมเปรียบเทียบปีก่อน

Parameters
ParameterTypeRequiredDefaultDescription
periodstringNodailydaily / monthly / yearly
start_datedateNo30 วันก่อนวันเริ่มต้น
end_datedateNoวันนี้วันสิ้นสุด
compare_yearintegerNoเปรียบเทียบกี่ปีก่อน (เช่น 1 = ปีที่แล้ว)
detailstringNosummarysummary = รวม, stations = แยกสถานี

GET /get_all_pm25_sensors.php

รวมข้อมูล PM2.5 จากทุกแหล่ง — Air4Thai + DustBoy (CMUCCDC) พร้อมคำนวณ AQI และระดับภาษาไทย

Example Response
{
  "success": true,
  "total_sensors": 35,
  "sensors": [
    {
      "id": "air4thai_58t",
      "lat": 19.303,
      "lon": 97.965,
      "pm25": 45.2,
      "aqi": 120,
      "color": "#FF7E00",
      "level": "มีผลกระทบต่อสุขภาพ",
      "name": "สถานี Air4Thai จองคำ",
      "source": "Air4Thai",
      "update_time": "2026-03-10 10:00:00"
    },
    {
      "id": "dustboy_5621",
      "lat": 19.350,
      "lon": 98.020,
      "pm25": 68.0,
      "aqi": 155,
      "color": "#FF0000",
      "level": "เริ่มมีผลกระทบต่อสุขภาพ",
      "name": "DustBoy ID-5621",
      "source": "DustBoy"
    }
  ],
  "sources": { "Air4Thai": 3, "DustBoy": 32 }
}

Wind / Environment API

API สนามลม GFS, วิเคราะห์ PM2.5 Spike, และ Environment Insights สำหรับการตัดสินใจ

GET /get_wind_field_api.php

ข้อมูลสนามลม GFS 10m สำหรับ Leaflet Velocity overlay (ไม่มี parameter)

Example Response
{
  "success": true,
  "meta": {
    "source": "GFS",
    "ref_time": "2026-03-10T00:00:00Z",
    "forecast_hour": 0
  },
  "field": [
    { "header": { "lo1": 97.0, "la1": 21.0, "dx": 0.25, "dy": 0.25, "nx": 10, "ny": 15 }, "data": ["..."] },
    { "header": { "...":"..." }, "data": ["..."] }
  ]
}

GET /get_wind_pm25_spike_summary.php

วิเคราะห์ลม (GFS + Open-Meteo) รวมกับ PM2.5 Spike Detection สำหรับประเมินการเคลื่อนตัวของควัน

Parameters
ParameterTypeDefaultDescription
provincestringแม่ฮ่องสอนจังหวัด
thresholdfloat5.0Spike threshold PM2.5 (µg/m³)
hoursinteger3ย้อนหลังกี่ชั่วโมง (1-24)
include_open_meteoboolean1รวมข้อมูลลม Open-Meteo
cache_ttlinteger120Cache TTL (วินาที)

GET /get_hotspot_environment_insights.php

วิเคราะห์ความสัมพันธ์จุดความร้อน × PM2.5 × สภาพอากาศรายวัน พร้อม Pearson Correlation

Parameters
ParameterTypeRequiredDescription
start_datedateYesวันเริ่มต้น YYYY-MM-DD
end_datedateYesวันสิ้นสุด YYYY-MM-DD
include_gistdabooleanNoรวม GISTDA VIIRS
provincestringNoกรองจังหวัด
districtstringNoกรองอำเภอ
tambonstringNoกรองตำบล
Example Request
curl "https://acdm.mhs-pao.go.th/get_hotspot_environment_insights.php?start_date=2026-02-01&end_date=2026-03-10&include_gistda=1"

Response Format

Response ทั้งหมดจะอยู่ในรูปแบบ JSON และมีโครงสร้างพื้นฐานดังนี้:

{
  "success": true,        // สถานะการทำงาน (true/false)
  "version": "2.0",       // เวอร์ชัน API
  "timestamp": "...",     // เวลาที่สร้าง response (ISO 8601)
  "meta": {},            // ข้อมูล metadata (ถ้ามี)
  "data": [],            // ข้อมูลที่ร้องขอ
  "error": {}            // ข้อมูล error (ถ้ามี)
}

Error Codes

HTTP Code Error Code Description
400 BAD_REQUEST Request ไม่ถูกต้อง
404 NOT_FOUND ไม่พบข้อมูลที่ร้องขอ
429 RATE_LIMIT_EXCEEDED เรียกใช้ API เกินจำนวนที่กำหนด
500 INTERNAL_ERROR เกิดข้อผิดพลาดภายในระบบ

ตัวอย่างการใช้งาน

JavaScript (Fetch API)
fetch('https://acdm.mhs-pao.go.th/api/v1/incidents.php?year=2025&limit=10')
  .then(response => response.json())
  .then(data => {
    console.log('Total incidents:', data.meta.total);
    console.log('Incidents:', data.data);
  })
  .catch(error => console.error('Error:', error));
Python
import requests

url = 'https://acdm.mhs-pao.go.th/api/v1/incidents.php'
params = {'year': 2025, 'limit': 10}

response = requests.get(url, params=params)
data = response.json()

print(f"Total incidents: {data['meta']['total']}")
for incident in data['data']:
    print(f"- {incident['incident_type']} at {incident['district']}")
PHP
$url = 'https://acdm.mhs-pao.go.th/api/v1/incidents.php?year=2025&limit=10';
$response = file_get_contents($url);
$data = json_decode($response, true);

echo "Total incidents: " . $data['meta']['total'] . "\n";
foreach ($data['data'] as $incident) {
    echo "- {$incident['incident_type']} at {$incident['district']}\n";
}