Showing results for 
Search instead for 
Do you mean 

Calculating a Least Cost Path using a DEM

by Technical Evangelist on ‎08-09-2016 07:30 AM - edited on ‎02-24-2020 03:28 AM by Community Manager (2,288 Views)

 Download model (and sample data)




Calculates the least cost path for cross-country mobility between a user defined start and end point and using a Digital Elevation Model. The initial Model only uses the DEM and DEM-derived (Slope) friction layers. But other layers could be added as needed to increase the accuracy, such as land cover to identify impassable water areas or a building layer to impede progress.


The results can be created as a raster representation of the least cost path (with per-pixel costs as DN values) or alternatively a Shapefile name can be provided to instead produce a polygon shapefile of the route.


 Path results displayed over the input DEM (displayed and styled using the Relief Image Chain)
 Least Cost Path Results.png


As well as demonstrating the capabilities provided by the Least Cost Path operator, the model also shows a use of the new (for ERDAS IMAGINE 2016) Define Processing Area operator, which replaces the old, global Processing Properties option in Spatial Modeler. Define Processing Area provides a more robust way of controlling when and where in your model, characteristics of the data (such as pixel size or projection) are changed. In this model you have to consider that there are three input datasets: a DEM, a shapefile with the start location; and a shapefile with an end location point. All three of these have different spatial extents. Calculating Least Cost Path is a very intensive operator and takes time to complete since every pixel has to have a cost calculated before the least cost path can be determined. So when performing this type of operation you want to minimize the extent that has to be processed. One way to do this would be to require the user to always draw a bounding box (fed into the Define Processing Area operator) for the processing area before the model runs, but that then requires user input. Instead you may want to automatically determine a reasonable extent to search. A good starting point is to take the union of the two vector inputs. 


But prior to ERDAS IMAGINE 2016 (and with the default behavior of the Spatial Modeler) you would have hit a problem in that Processing Properties were defined based on all the inputs. So if you have the three inputs, you had the options to set an automatically generated processing area based on either the Union of all inputs or the Intersection of all inputs. If you look at the screenshot of results above you can see that Union of all inputs generally resulted in using the extent of the DEM, which could be your entire country! Whereas if you defaulted to Intersection nothing would be processed because there's no intersection of the extents of the input point and the output point.


So we fine-tune the boundary rules by using the Define Processing Area operator. The general rule for a model is Intersection of inputs. However this model adds a  Define Processing Area which takes in the two shapefile extents (and the extents of a couple of buffers - we'll discuss that in a second) and generates the Union of those extents. When the data coming out of the Define Processing Area operator is later combined with other data (the DEM and Slope information) with different extents in the Least Cost Path operator, the default behavior takes over and the processing extent is limited to the Intersection of the Union of the points and the DEM extent. Hence the calculations are limited to a reasonable extent.


But why does the model buffer the points? You can see why if you take a look at the screenshot above and imagine the union boundary extent that would be formed by the start and end points. The least cost path that has been calculated has gone outside of that extent. So you don't want to simply use the union of the two point extents. The worst case scenario there would be if the two points were in line North-South or East-West - the union bounding box would be a straight line between the two and therefore your least cost path would be forced to be a straight line between the two as well. So instead, the two points have had a Buffer operator applied to them. These buffer extents are then also fed into the Define Processing Area operator so that the Union includes that buffer around the points. That is all the buffer is used for  - to simply help extend the boundary a reasonable distance. The distance is set to 750m in the model and obviously should be adjusted to suit your specific data. It could even be exposed as an input parameter to the user if you wished by adding another Port Input.


Finally, please remember that this model is merely intended to demonstrate the principles of calculating a least cost path. To derive a true path between locations you will always want to generate the Cost (friction) Surface from more variables than just the slope of a DEM.


Because of the use of several newly introduced Operators this Model requires ERDAS IMAGINE 2016 or later to run.

 Least Cost Path.PNG




Input parameters: (indent content below)


Input DEM: Input raster surface over which travel cost will be calculated. Distances travelled are greater for sloping pixels, and steep slopes are used to increase the friction of travel across the surface (by calculating the Degree Slope)

Start Point: Input shapefile layer containing a single point representing the start location.

End Point: Input shapefile layer containing a single point representing the end (destination) location.

Raster Path: Name of the output raster representing the least cost path between the two points. Pixel values represent the accumulated cost at each point along the path. If you want a vector output leave this field blank and provide a Vector Path name instead.

Vector Path: Name of the output vector shapefile representing the least cost path between the two points. If you want a raster output leave this field blank and provide a Raster Path name instead.


 Least Cost Path Inputs.PNG


Example data:


The download zip file includes the example model as well as three datasets for testing the model. These are


ned19_n40x25_w106x00_co_grandco_2010_chip.img – A section of DEM extracted from the National Elevation Dataset (NED) 1/9th elevation database, provided courtesy the U.S. Geological Survey

start.shp – A shapefile containing a single point geometry to represent the starting point for the desired least cost path

end1.shp – A shapefile containing a single point geometry to represent the destination point for the desired least cost path


on ‎01-16-2017 03:22 PM

So given a lidar map of a golf green one could compute the proper putting line?  If so, this model is worth a fortune!!!

on ‎08-07-2020 06:06 AM

Hi Ian 

I created a model that makes use of the least cost operator and I am getting the following errors on the Least Cost Path operator:



When I was researching about this error I then came across this post. I have also downloaded the model you have here and tested and i still get the same error.
I tested this using 30m srtm data and two point files projected as follows:
- all files projected to EPSG 32735
- all files projected to EPSG 4326
I keep on geeting the same error, I then reprojected my data to EPSG 4269 and I still get the same error.

The model however runs with the data provided in this post and doesnt give the same error. This therefore showed me that the operator works and the issue is with the data I am using. Is there a detailed guideline on the supported data by this operator?

Error from Session log:

ERROR: HexGeo:Smiley FrustratedpatialModeler:Smiley Surprisedperator:Smiley FrustratedetErrorMessage failed
ERROR: #2010 from HexGeo:Smiley FrustratedpatialModeler:Smiley Surprisedperator:Smiley FrustratedetErrorMessage
ERROR: Spatial Model failed in SpreadInternal 2. The error was "erdas::sb_grid::RasterAdaptorOperator:Smiley TonguerocessBlock failed

Reading operator result values failed! One possible cause is that the image projection is either not defined or not supported.".

What am I possibly doing wrong here?


Kind Regards

by Technical Evangelist
on ‎08-07-2020 12:28 PM

Hi @Nizza ,


HAve you reviewed the tips provided in the Help page for Least Cost Path, such as the NoData requirements, etc?:


If you want to send me your data and model  I can take a quick look.




on ‎08-11-2020 12:25 AM

Hi Ian 


Thanks for this I had also seen the same from the help menu.


Let me change a few things on my data and get back to you asap.


Kind Regards



on ‎08-27-2020 03:29 AM

Hi Ian

Thanks for the link you shared on how to handle the null values.


I managed to run the model after changing the null values in my datasets.


Kind Regards