Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 at 21:57
If you want to see some actual code have a look at gdaldem, the code can be downloaded, inspected (and even modified) here. – iant Mar 4 at 7:33
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 at 8:04
up vote 4 down vote accepted

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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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