Path: blob/master/tutorials/Image/13_cumulative_cost_mapping.ipynb
2313 views
Cumulative Cost Mapping
Use image.cumulativeCost() to compute a cost map where every pixel contains the total cost of the lowest cost path to the nearest source location. This process is useful in a variety of contexts such as habitat analysis (Adriaensen et al. 2003), watershed delineation (Melles et al. 2011) and image segmentation (Falcao et al. 2004). Call the cumulative cost function on an image in which each pixel represents the cost per meter to traverse it. Paths are computed through any of a pixel's eight neighbors. Required inputs include a source image, in which each non-zero pixel represents a potential source (or start of a path), and a maxDistance (in meters) over which to compute paths. The algorithm finds the cumulative cost of all paths less than maxPixels = maxDistance/scale in length, where scale is the pixel resolution, or scale of analysis in Earth Engine.
The following example demonstrates computing least-cost paths across a land cover image:
Install Earth Engine API and geemap
Install the Earth Engine Python API and geemap. The geemap Python package is built upon the ipyleaflet and folium packages and implements several methods for interacting with Earth Engine data layers, such as Map.addLayer(), Map.setCenter(), and Map.centerObject(). The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its dependencies, including earthengine-api, folium, and ipyleaflet.
Important note: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only (source). Note that Google Colab currently does not support ipyleaflet (source). Therefore, if you are using geemap with Google Colab, you should use import geemap.foliumap. If you are using geemap with binder or a local Jupyter notebook server, you can use import geemap, which provides more functionalities for capturing user input (e.g., mouse-clicking and moving).
Create an interactive map
The default basemap is Google Satellite. Additional basemaps can be added using the Map.add_basemap() function.
Add Earth Engine Python script
The result should look something like Figure 1, in which each output pixel represents the accumulated cost to the nearest source. Note that discontinuities can appear in places where the least cost path to the nearest source exceeds maxPixels in length.
View source on GitHub
Run in Google Colab