# How do I find least cost path over a DEM based on slope magnitude and direction?

What sort of algorithms can I use to find a least cost path through a DEM where it costs more to traverse a cell going downhill or uphill than it does to follow the contour of the land?

All the examples I've seen involve creating a least cost surface where the magnitude of the slope is part of the cost - but the direction isn't.

Additionally, the examples assume the cost to travel through a cell does not depend on the direction of travel.

-
Have you reviewed the ArcGIS `PathDistance` command for Spatial Analyst? If you're interested in algorithms rather than just software, it may help to notice this is an example of a Calculus of variations problem. In fact, by introducing a third dimension to represent all possible orientations at each point (the circle bundle over the region of interest), this becomes a least-cost problem within a 3D space (which can be gridded into voxels for a raster-based solution). – whuber Apr 19 '12 at 22:52
+1 even if you are not using ArcGIS (you don't say), the ESRI explanations that whuber points you towards are a great overview from which you can work out how to do it in some other application. – MappaGnosis Apr 20 '12 at 8:30
@whuber Thanks, I overlooked the vertical cost component in the PathDistance. If I run into bugs with the PathDistance it would be nice to have an algorithm for Plan B. Although the Calculus of variations is a bit over my head. It mentions "functionals" ... does that imply I could use functional programming and not have to worry about learning the math? – Kirk Kuykendall Apr 20 '12 at 15:01
LOL! That's a nice example of a collision of technical terms in GIS. In mathematics, the term "functional" is usually used for a function whose domain itself consists of functions. (The Riemann integral is a good example: it assigns a number to real-valued functions.) When you find an optimal corridor for a pipeline, your functional assigns a "score" or "value" to any possible route. Because a route would be described as a path--that is, assignment of a point in space to the interval of times needed to traverse that route--"functional" is apt. – whuber Apr 20 '12 at 15:16
@whuber Thanks. I think I'll stick with PathDistance, and remain functionally illiterate for the time being. – Kirk Kuykendall Apr 20 '12 at 15:45