用Google Earth Engine存取Sentinel衛星影像來計算火燒山面積

網路媒體於20190204關於火燒山的報導


在今年年假近尾聲時,雪霸國家公園管轄的雪山主東峰線步道369山莊附近失火了!身為森林系畢業的我自然對這樣的新聞特別關心,畢竟是曾經去過的地方。關注新聞的同時也想知道到底燒了多大的範圍,畢竟從網路報導所提供的照片實在是無法很清楚的了解。利用Open data中可以取得的最高解析度之衛星影像,Sentinel-2,就讓我們來看看這個火燒山的面積鳩近有多大吧?~

//下面先貼上成果圖,等有時間再補上施作細節
利用Google公司最近正式上線的GIS新兵器,Google Earth Engine,我們介接了Sentinel-2衛星的MSI(MultiSpectral Instrument, Level-1C)影像產品,找到火燒前、後最接近日期的369山莊影像(20190131和20190210,20190205雖有影像紀錄但大多數畫面被雲層所遮住),根據RGB套色的火燒範圍標定多邊形圖徵,計算總面積。計算結果:火燒面積約為25.33公頃(新聞好像只報導了3公頃,看來是有誤差的);火燒範圍大概就是登山走到369山莊時,眼前所見白木林跟箭竹草原的範圍,下方照片為20181117拍攝於雪山東峰(往369山莊方向),照片中間的箭竹草原基本上在這次的火燒中整個都燒掉了XD。

火燒山面積的測定

20171117由雪山東峰往369山莊拍攝


//20190223更新
說好要放上來的code在這邊(沒清乾淨的部分請忽略)
//20190203開始火燒
//20190131、20190205、20190210,Sentinel-2各有拍攝任務飛過台灣上空。故我們抓出這幾張圖片。

/**
 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
 */
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

// Map the function over one year of data and take the median.
// Load Sentinel-2 TOA reflectance data.
var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2019-01-31', '2019-02-01')
                  // Pre-filter to get less cloudy granules.
    //這一行是依照雲的比例進行分類,只找出雲面積占pixel 20%以下的畫面,所以如果是要看單次飛行影像,可能會直些篩掉很多。我們使用100去得到所有的影像。
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 100)) 
    //套用消除雲朵的function
                  .map(maskS2clouds);

var dataset2 = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2019-02-05', '2019-02-06')
                  // Pre-filter to get less cloudy granules.
    //這一行是依照雲的比例進行分類,只找出雲面積占pixel 20%以下的畫面,所以如果是要看單次飛行影像,可能會直些篩掉很多。我們使用100去得到所有的影像。
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 100)) 
    //套用消除雲朵的function
                  .map(maskS2clouds);

var dataset3 = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2019-02-10', '2019-02-11')
                  // Pre-filter to get less cloudy granules.
    //這一行是依照雲的比例進行分類,只找出雲面積占pixel 20%以下的畫面,所以如果是要看單次飛行影像,可能會直些篩掉很多。我們使用100去得到所有的影像。
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 100)) 
    //套用消除雲朵的function
                  .map(maskS2clouds);

var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};

//zoom設定選16剛剛好;修正座標至369山莊。
Map.setCenter(121.254755, 24.392263, 16);      
Map.addLayer(dataset.median(), rgbVis, 'RGB0131');
Map.addLayer(dataset2.median(), rgbVis, 'RGB0205');
Map.addLayer(dataset3.median(), rgbVis, 'RGB0210');

//下方為根據火燒區域插入多邊形,以計算面積。Earth engine可以選取換成feature插入的型式。
var geometry = /* color: #d63000 */ee.Geometry.Polygon(
        [[[121.25340103694282, 24.395151518044415],
          [121.25310062953315, 24.39522968562599],
          [121.25297188350044, 24.395444646225936],
          [121.25269293376289, 24.39554235546864],
          [121.25228523799262, 24.395698690099767],
          [121.2520277459272, 24.39554235546864],
          [121.25179171153388, 24.395307853159206],
          [121.25153421946845, 24.39540556250769],
          [121.25134110041938, 24.395288311280428],
          [121.25123381205879, 24.395073350414474],
          [121.25108360835395, 24.394995182736178],
          [121.25123381205879, 24.3946043436192],
          [121.25138401576362, 24.394291671455083],
          [121.2512552697309, 24.39411579302271],
          [121.25123381205879, 24.393959456432828],
          [121.25086903163276, 24.393568614111814],
          [121.25093340464912, 24.3929041793913],
          [121.25106215068183, 24.39257196072075],
          [121.2512552697309, 24.392259283526997],
          [121.2514698464521, 24.392024775123907],
          [121.25164150782905, 24.391790266285565],
          [121.25177025386176, 24.391555757012],
          [121.25232815333686, 24.391399417254494],
          [121.25254273005805, 24.391301704807827],
          [121.25262856074653, 24.3911258222134],
          [121.25286459513984, 24.39098902447071],
          [121.25310062953315, 24.390793598867102],
          [121.2538301903852, 24.390852226579923],
          [121.25408768245063, 24.391301704807827],
          [121.2542808014997, 24.39171209657608],
          [121.25481724330268, 24.391614384371195],
          [121.25520348140083, 24.391731639007986],
          [121.25563263484321, 24.391848893535965],
          [121.2558472115644, 24.39194660555949],
          [121.25610470362983, 24.392024775123907],
          [121.256855722154, 24.392239741176702],
          [121.25683426448188, 24.39245470686377],
          [121.25576138087592, 24.39247424918083],
          [121.25558971949897, 24.392747841302203],
          [121.2557399232038, 24.393138686162217],
          [121.25610470362983, 24.393549071964014],
          [121.2561905343183, 24.393744493305892],
          [121.25655531474433, 24.3938031196495],
          [121.25676989146552, 24.39392037225514],
          [121.25726341792426, 24.394018082676705],
          [121.25739216395698, 24.39431121348801],
          [121.25737070628486, 24.394623885603767],
          [121.25724196025214, 24.394975640809047],
          [121.2573063332685, 24.395171059944346],
          [121.25687717982612, 24.39540556250769],
          [121.256855722154, 24.395600980977985],
          [121.25644802638374, 24.39565960646012],
          [121.25623344966255, 24.395796399145986],
          [121.25576138087592, 24.39565960646012],
          [121.25556826182685, 24.395679148281467],
          [121.25524639674506, 24.39593319168373],
          [121.25492453166328, 24.396011358781656],
          [121.2544953782209, 24.39575731553657],
          [121.25402330943427, 24.395698690099767],
          [121.25378727504096, 24.395600980977985],
          [121.25350832530341, 24.39554235546864],
          [121.2533795792707, 24.395386020644032]]]);

print(geometry);
print('Polygon area: ', geometry.area().divide(1000 * 1000));
//Polygon area: 0.25330297939272167 km^2

留言