I'm curious how GIS systems actually generate a hill-shade from input data like a raster DEM layer. I'd like to implement my own in software (mostly for fun/learning) but I want to start with a plausible algorithm so I don't waste an incredible amount of time.

Naively, I'd think you could scan the elevation data, calculate the slope from point to point in a given direction (say left to right), then color all of either the positive or negative slopes. If the min and max slopes in the elevation tile were known, it seems like it might also be nice to scale the color based on that.

Is that a plausible way to go about the problem?

  • It's a bit more complicated than that. There are also a number of different implementations, even in one organization. In order to avoid having this closed as too broad or opinion-based you may need to focus on a single implementation, without looking for validation of your own algorithm. – Vince Mar 3 '16 at 21:57
  • 1
    If you want to see some actual code have a look at gdaldem, the code can be downloaded, inspected (and even modified) here. – Ian Turton Mar 4 '16 at 7:33
  • 1
    There is some nice .js scripting for doing Hillshades in OpenLayers, I don't understand the detail much myself but if you like .js this should give you a good intro to one method. – Sethinacan Mar 4 '16 at 8:04

It is important to remember that when computing hillshading, you need to have an illumination source. Using the sun as an illumination source may mean that a cell is shaded at noon, when the sun is directly overhead, but not at 4:00 p.m. Without an illumination point, your example seems more like a color coded slope map.

ESRI calculates illumination of each cell relative to its neighboring cells and has better explanations and examples of their algorithm than I can offer:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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