มาเริ่มกันที่การคำนวณที่จำเป็นต่อการสร้างแถบที่แสดงพิกเซลซึ่งข้อมูลของ Hansen และคณะแสดงทั้งการสูญเสียและการเพิ่มขึ้น
ชุดข้อมูล Hansen et al. มีแบนด์ที่มีพิกเซลเป็น 1 เมื่อเกิดการสูญเสีย และ 0 ในกรณีอื่นๆ (loss
) และแบนด์ที่มีพิกเซลเป็น 1 เมื่อเกิดการเพิ่มขึ้น และ 0 ในกรณีอื่นๆ (gain
) หากต้องการสร้างแบนด์ที่มีพิกเซลเป็น 1 ทั้งในแบนด์ loss
และ gain
คุณสามารถใช้วิธีตรรกะ and()
กับรูปภาพได้ and()
เมธอดจะเรียกใช้เหมือนกับ
image1.and(image2)
และแสดงผลรูปภาพที่พิกเซลเป็น 1 เมื่อ
ทั้ง image1 และ image2 เป็น 1 และเป็น 0 ในที่อื่นๆ
โปรแกรมแก้ไขโค้ด (JavaScript)
// Load the data and select the bands of interest. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossImage = gfc2014.select(['loss']); var gainImage = gfc2014.select(['gain']); // Use the and() method to create the lossAndGain image. var gainAndLoss = gainImage.and(lossImage); // Show the loss and gain image. Map.addLayer(gainAndLoss.updateMask(gainAndLoss), {palette: 'FF00FF'}, 'Gain and Loss');
ผลลัพธ์ที่ได้เมื่อซูมเข้าไปที่รัฐอาร์คันซอด้วยมุมมองดาวเทียมควรมีลักษณะคล้ายกับรูปที่ 1

เมื่อรวมตัวอย่างนี้กับผลลัพธ์จากส่วนก่อนหน้า ตอนนี้คุณสามารถสร้างกราฟจากตอนต้นของบทแนะนำขึ้นมาใหม่ได้แล้ว
โปรแกรมแก้ไขโค้ด (JavaScript)
// Displaying forest, loss, gain, and pixels where both loss and gain occur. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossImage = gfc2014.select(['loss']); var gainImage = gfc2014.select(['gain']); var treeCover = gfc2014.select(['treecover2000']); // Use the and() method to create the lossAndGain image. var gainAndLoss = gainImage.and(lossImage); // Add the tree cover layer in green. Map.addLayer(treeCover.updateMask(treeCover), {palette: ['000000', '00FF00'], max: 100}, 'Forest Cover'); // Add the loss layer in red. Map.addLayer(lossImage.updateMask(lossImage), {palette: ['FF0000']}, 'Loss'); // Add the gain layer in blue. Map.addLayer(gainImage.updateMask(gainImage), {palette: ['0000FF']}, 'Gain'); // Show the loss and gain image. Map.addLayer(gainAndLoss.updateMask(gainAndLoss), {palette: 'FF00FF'}, 'Gain and Loss');
การวัดปริมาณการเปลี่ยนแปลงของป่าในภูมิภาคที่สนใจ
ตอนนี้คุณคุ้นเคยกับแถบข้อมูลในชุดข้อมูลของ Hansen และคณะมากขึ้นแล้ว เราจึงสามารถ
ใช้แนวคิดที่ได้เรียนรู้มาจนถึงตอนนี้เพื่อคำนวณสถิติเกี่ยวกับการเพิ่มขึ้นและการลดลงของป่าในภูมิภาค
ที่สนใจ เราจึงต้องใช้ข้อมูลเวกเตอร์ (จุด เส้น และรูปหลายเหลี่ยม) ชุดข้อมูลเวกเตอร์จะแสดงเป็น FeatureCollection
ใน Earth Engine
(ดูข้อมูลเพิ่มเติมเกี่ยวกับคอลเล็กชันฟีเจอร์และวิธี
นำเข้าข้อมูลเวกเตอร์)
ในส่วนนี้ เราจะเปรียบเทียบปริมาณการสูญเสียป่าไม้ทั้งหมด ที่เกิดขึ้นในสาธารณรัฐคองโกในปี 2012 กับปริมาณการสูญเสียป่าไม้ ที่เกิดขึ้นในพื้นที่คุ้มครองของประเทศในช่วงเวลาเดียวกัน
ดังที่ได้เรียนรู้ในบทแนะนำเกี่ยวกับ Earth Engine API วิธีหลักในการคำนวณสถิติในภูมิภาคของรูปภาพคือ
reduceRegion()
(ดูข้อมูลเพิ่มเติมเกี่ยวกับการลด
ภูมิภาคของรูปภาพ) ตัวอย่างเช่น สมมติว่าเราต้องการคำนวณจำนวนพิกเซลที่ประมาณ
เพื่อแสดงการสูญเสียป่าไม้ในช่วงระยะเวลาการศึกษา ด้วยเหตุนี้ ให้พิจารณาโค้ดต่อไปนี้
โปรแกรมแก้ไขโค้ด (JavaScript)
// Load country features from Large Scale International Boundary (LSIB) dataset. var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017'); // Subset the Congo Republic feature from countries. var congo = countries.filter(ee.Filter.eq('country_na', 'Rep of the Congo')); // Get the forest loss image. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossImage = gfc2014.select(['loss']); // Sum the values of forest loss pixels in the Congo Republic. var stats = lossImage.reduceRegion({ reducer: ee.Reducer.sum(), geometry: congo, scale: 30 }); print(stats);
ตัวอย่างนี้ใช้ตัวลด ee.Reducer.sum()
เพื่อหาผลรวมของค่าพิกเซลใน lossImage
ภายในฟีเจอร์ congo
เนื่องจาก lossImage
ประกอบด้วยพิกเซลที่มีค่าเป็น 1 หรือ 0 (สำหรับการสูญเสียหรือไม่สูญเสียตามลำดับ) ผลรวมของค่าเหล่านี้จึงเทียบเท่ากับจำนวนพิกเซลของการสูญเสียในภูมิภาค
ขออภัย การเรียกใช้สคริปต์ตามที่เป็นอยู่จะทำให้เกิดข้อผิดพลาด เช่น
จำนวนพิกเซลสูงสุดเริ่มต้นใน
reduceRegion()
คือ 10 ล้านพิกเซล ข้อความแสดงข้อผิดพลาดนี้ระบุว่าสาธารณรัฐคองโกครอบคลุมพิกเซล Landsat ประมาณ 383 ล้านพิกเซล
โชคดีที่ reduceRegion()
รับพารามิเตอร์ได้หลายรายการ ซึ่งหนึ่งในนั้น (maxPixels
) ช่วยให้คุณควบคุมจำนวน
พิกเซลที่ใช้ในการคำนวณได้ การระบุพารามิเตอร์นี้จะช่วยให้การคำนวณสำเร็จ
ได้
โปรแกรมแก้ไขโค้ด (JavaScript)
// Load country features from Large Scale International Boundary (LSIB) dataset. var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017'); // Subset the Congo Republic feature from countries. var congo = countries.filter(ee.Filter.eq('country_na', 'Rep of the Congo')); // Get the forest loss image. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossImage = gfc2014.select(['loss']); // Sum the values of forest loss pixels in the Congo Republic. var stats = lossImage.reduceRegion({ reducer: ee.Reducer.sum(), geometry: congo, scale: 30, maxPixels: 1e9 }); print(stats);
เมื่อขยายออบเจ็กต์ที่พิมพ์ไปยังคอนโซล คุณจะเห็นว่าผลลัพธ์คือ
สูญเสียผืนป่าไป 4,897,933 พิกเซล คุณสามารถล้างข้อมูลที่พิมพ์ออกมาในคอนโซลได้เล็กน้อยโดย
ติดป้ายกำกับเอาต์พุตและรับผลลัพธ์ที่สนใจจากพจนานุกรมที่ส่งคืน
โดย reduceRegion()
:
โปรแกรมแก้ไขโค้ด (JavaScript)
print('pixels representing loss: ', stats.get('loss'));
การคำนวณพื้นที่พิกเซล
คุณเกือบพร้อมที่จะตอบคำถามเกี่ยวกับพื้นที่ที่สูญเสียไปในสาธารณรัฐคองโก
และพื้นที่ที่สูญเสียไปในพื้นที่คุ้มครอง ส่วนที่เหลือคือการแปลงพิกเซล
เป็นพื้นที่จริง Conversion นี้มีความสำคัญเนื่องจากเราไม่ทราบขนาดของอินพุตพิกเซลที่ป้อนไปยัง reduceRegion()
Earth
Engine มีเมธอด ee.Image.pixelArea()
ซึ่งสร้างรูปภาพที่ค่าของแต่ละพิกเซลคือพื้นที่ของพิกเซลในหน่วยตารางเมตร เพื่อช่วยคำนวณพื้นที่ การคูณรูปภาพการสูญเสียกับรูปภาพพื้นที่นี้ แล้วบวกผลลัพธ์เข้าด้วยกันจะทำให้เราได้การวัดพื้นที่
ดังนี้
โปรแกรมแก้ไขโค้ด (JavaScript)
// Load country features from Large Scale International Boundary (LSIB) dataset. var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017'); // Subset the Congo Republic feature from countries. var congo = countries.filter(ee.Filter.eq('country_na', 'Rep of the Congo')); // Get the forest loss image. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossImage = gfc2014.select(['loss']); var areaImage = lossImage.multiply(ee.Image.pixelArea()); // Sum the values of forest loss pixels in the Congo Republic. var stats = areaImage.reduceRegion({ reducer: ee.Reducer.sum(), geometry: congo, scale: 30, maxPixels: 1e9 }); print('pixels representing loss: ', stats.get('loss'), 'square meters');
ตอนนี้ผลลัพธ์คือ 4,372,575,052 ตารางเมตรที่สูญเสียไปในช่วงระยะเวลาการศึกษา
ตอนนี้คุณพร้อมที่จะตอบคำถามที่จุดเริ่มต้นของส่วนนี้แล้ว นั่นคือ พื้นที่ป่าในสาธารณรัฐคองโกสูญเสียไปเท่าใดในปี 2012 และพื้นที่ป่าที่สูญเสียไปนั้นอยู่ในพื้นที่คุ้มครองเท่าใด
โปรแกรมแก้ไขโค้ด (JavaScript)
// Load country features from Large Scale International Boundary (LSIB) dataset. var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017'); // Subset the Congo Republic feature from countries. var congo = ee.Feature( countries .filter(ee.Filter.eq('country_na', 'Rep of the Congo')) .first() ); // Subset protected areas to the bounds of the congo feature // and other criteria. Clip to the intersection with congo. var protectedAreas = ee.FeatureCollection('WCMC/WDPA/current/polygons') .filter(ee.Filter.and( ee.Filter.bounds(congo.geometry()), ee.Filter.neq('IUCN_CAT', 'VI'), ee.Filter.neq('STATUS', 'proposed'), ee.Filter.lt('STATUS_YR', 2010) )) .map(function(feat){ return congo.intersection(feat); }); // Get the loss image. var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015'); var lossIn2012 = gfc2014.select(['lossyear']).eq(12); var areaImage = lossIn2012.multiply(ee.Image.pixelArea()); // Calculate the area of loss pixels in the Congo Republic. var stats = areaImage.reduceRegion({ reducer: ee.Reducer.sum(), geometry: congo.geometry(), scale: 30, maxPixels: 1e9 }); print( 'Area lost in the Congo Republic:', stats.get('lossyear'), 'square meters' ); // Calculate the area of loss pixels in the protected areas. var stats = areaImage.reduceRegion({ reducer: ee.Reducer.sum(), geometry: protectedAreas.geometry(), scale: 30, maxPixels: 1e9 }); print( 'Area lost in protected areas:', stats.get('lossyear'), 'square meters' );
เอาต์พุตระบุว่าจากพื้นที่ป่า 348,036,295 ตารางเมตรที่สูญเสียไปในสาธารณรัฐคองโก ในปี 2012 มีพื้นที่ 11,880,976 ตารางเมตรอยู่ในพื้นที่คุ้มครองตามที่แสดงใน ตารางฐานข้อมูลโลกเกี่ยวกับพื้นที่คุ้มครอง
การเปลี่ยนแปลงเพียงอย่างเดียวระหว่างสคริปต์นี้กับสคริปต์ก่อนหน้าคือการเพิ่ม
ข้อมูลพื้นที่คุ้มครอง และการเปลี่ยนสคริปต์จากการดูการสูญเสียโดยรวมเป็นการดู
การสูญเสียในปี 2012 ซึ่งต้องมีการเปลี่ยนแปลง 2 อย่าง ประการแรกคือlossIn2012
รูปภาพใหม่ซึ่งมีค่า 1 ในตำแหน่งที่มีการบันทึกการสูญเสียในปี 2012 และ 0 ในตำแหน่งอื่นๆ ประการที่ 2 เนื่องจาก
ชื่อวงดนตรีแตกต่างกัน (lossyear
แทน loss
) จึงต้อง
เปลี่ยนชื่อพร็อพเพอร์ตี้ในคำสั่งพิมพ์
ในส่วนถัดไป เราจะมาดูวิธีการขั้นสูงบางอย่าง ในการคำนวณและทำแผนภูมิการสูญเสียป่าไม้ในแต่ละปี แทนที่จะเป็นเพียงปีเดียวอย่างที่เราทำ ในส่วนนี้