I need to calculate cost distance for each cell in my raster (bounding box: Sumatera island) to points (palm oil mills), with slope as its cost. The cost layer (slope) has float data type (val: 0-90), and I can't seem to get the right code to make the variable cost calculation works.

// Add features
var sumatera = ee.FeatureCollection("users/putraditama/sumatera"); // Sumatera island boundary (polygon)
var po_mills = ee.FeatureCollection("users/putraditama/po_mills"); // palm oil mills (points)

// Add raster
var elev = ee.Image("USGS/SRTMGL1_003");

// Clip elev to Sumatera boundary
var elevsmrt = elev.clip(sumatera);

// Get slope
var slopesmrt = ee.Terrain.slope(elevsmrt);

// Create a source image (palm oil mill=1, others=0)
var sources = ee.Image().toByte().paint(po_mills, 1);

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

// The cost data is generated from slope 
var cover = slopesmrt.select(0);

// Variable cost
var cost =

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

1 Answer 1


Found the solution. Changed the variable cost script into this:

var cost = 
  • Please mark this answer as the correct one using the grey/green tick to the left.
    – Kersten
    Dec 5, 2017 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.