累計費用對應

使用 image.cumulativeCost() 計算成本地圖,其中每個像素都包含前往最近來源位置的最低成本路徑總費用。這個程序在各種情境中都很實用,例如棲息地分析(Adriaensen 等人,2003)、集水區劃分(Melles 等人,2011)和圖像區隔(Falcao 等人,2004)。在圖片上呼叫累積成本函式,其中每個像素代表每公尺的成本。路徑會透過像素的八個相鄰像素計算。必要輸入內容包括 source 圖片,其中每個非零像素代表潛在來源 (或路徑起點),以及用於計算路徑的 maxDistance (以公尺為單位)。這個演算法會找出所有路徑的累積成本,其長度小於 maxPixels = maxDistance/scale,其中 scale 是像素解析度,或 Earth Engine 中的分析比例

以下範例說明如何在土地覆蓋圖像中計算最低成本路徑:

// A rectangle representing Bangui, Central African Republic.
var geometry = ee.Geometry.Rectangle([18.5229, 4.3491, 18.5833, 4.4066]);

// Create a source image where the geometry is 1, everything else is 0.
var sources = ee.Image().toByte().paint(geometry, 1);

// Mask the sources image with itself.
sources = sources.selfMask();

// The cost data is generated from classes in ESA/GLOBCOVER.
var cover = ee.Image('ESA/GLOBCOVER_L4_200901_200912_V2_3').select(0);

// Classes 60, 80, 110, 140 have cost 1.
// Classes 40, 90, 120, 130, 170 have cost 2.
// Classes 50, 70, 150, 160 have cost 3.
var beforeRemap = [60, 80, 110, 140,
                   40, 90, 120, 130, 170,
                   50, 70, 150, 160];
var afterRemap = [1, 1, 1, 1,
                  2, 2, 2, 2, 2,
                  3, 3, 3, 3];
var cost = cover.remap(beforeRemap, afterRemap, 0);

// Compute the cumulative cost to traverse the land cover.
var cumulativeCost = cost.cumulativeCost({
  source: sources,
  maxDistance: 80 * 1000  // 80 kilometers
});

// Display the results
Map.setCenter(18.71, 4.2, 9);
Map.addLayer(cover, {}, 'Globcover');
Map.addLayer(cumulativeCost, {min: 0, max: 5e4}, 'accumulated cost');
Map.addLayer(geometry, {color: 'FF0000'}, 'source geometry');

結果應類似圖 1,其中每個輸出像素代表到最近來源的累積成本。請注意,如果最接近來源的代價最低路徑長度超過 maxPixels,就可能出現中斷情形。

costMap
圖 1. 來源像素的累積成本,成本取決於土地覆蓋率類別。低成本為黑色,高成本為白色。