In this post we look at two different ways of creating elevation contours from a DEM.  In one we derive and smooth the contour lines and in the other we smooth the DEM first.

One of the most common questions we get here at GIS Central is about creating elevation contours.  It’s not a difficult thing to do, so in this post we’ll look at two different approaches to do this and in another post we’ll look at labelling and creating index contours.  First off, I imagine most of us are familiar with contours.  They are key bits of map data that help emphasise changes in topography- each line connects points of equal elevation.  As an example, the image below shows the contours for an area on Banks Peninsula from the 1:50,000 scale topo map:

This is pretty standard contour symbology: the contour interval (i.e. the vertical difference between contours) is 20 m and then every 100 m is a darker, thicker index line.  This is an effective way of helping the map reader to get a sense of the changes in terrain.  Where they contours are bunched together, the slope is steeper, like above Mechanics and Breeze Bays.  Conversely, wide spacing between contours indicates flatter areas, such as on top of the ridge.  Let’s see if we can recreate these contours to a decent standard using a 15 m DEM.  I’ve clipped out what I need from the Christchurch_15m_DEM_Sos grid in J:\Data\Digital_Elevation_Models (the “Sos” stands for the Otago School of Surveying who produced this layer).  For many people, hillshades are an easier way of visualising topography and that layer is shown below:

For our first attempt at contours we’ll take the easy road: the Contour tool.  It’s not at all difficult to use (just make sure you use the DEM and not the hillshade):

The input is GHDEM and the output is being saved to my ContourData geodatabase.  The contour interval is set to 20, the base contour to 0 and the Z factor to 1 (its default).  To be honest, I can’t ever think of a time I’ve used the Z factor.  It is mainly used to convert data in feet to metres or vice-versa.  Here’s the output:

At first glance, that’s not too bad, eh?  On closer inspection, well, there are some issues.  Look at the beach of Taylors Mistake and around parts of the coastline – it becomes quite blocky.  What you’re seeing is the effect of the grid cell sizes from the DEM.  We do have a way to try and clean this up – the Smooth Line tool (ArcToolbox > Cartography Tools > Generalization (sic):

This tool tries to smooth out jagged lines using one of two smoothing algorithms.  I won’t go into detail on how they work here, suffice it say that PAEK is the default and you need to set a smoothing tolerance – the smaller this number the more detail it preserves (and the longer it takes).  I’ve set it to “5” above and let’s see what we get:

Well it’s not a whole lot better to be fair; we haven’t really gained much from this.  To be honest, there have been few cases where I have seem Smooth Line make a big difference and that’s why I often use a different approach to creating nice smooth contours.  In this approach, rather than smoothing the contours, we smooth the DEM before deriving the contours.  For this we use the Focal Statistics tool:

This tool works as a bit of a filter.  Envision a window of sorts moving across the DEM from cell to cell. At each cell, it looks around at the neigbouring cells in a window that is seven cells wide and seven cells high and then calculates the mean of that neighbourhood.  This value gets put into the cell at the centre of the window in a new grid and the window them moves onto the next cell.  So I’ve run the tool and then derived a new hillshade to illustrate the result:

To me this looks a bit more “out of focus” compared to above, and that’s a result of the surface being smoothed out.  I’ll run the contour tool on this new DEM and let’s look at the result:

Well this is gives us some very nice smoothed contours, more like what we might see on a topo map but we’ve still got a rather jagged coastline.  We have another issue as well which becomes clearer if I turn on our first contour attempt:

The contours above sea level are smoother and “look” a bit nicer, but as a result of my smoothing the DEM, the zero contour has been spread out, like a bit of melted butter.  Let’s look at bit more closely as the differences between the smoothed DEM contours (blue) and the smoothed contour lines (brownish):

When zoomed in, the smoothed DEM contours look like winners to me and I’d be inclined to use them for mapping – but NOT analysis.  This is a very important caveat with this approach.  On balance, I’d say that smoothing the DEM gives you better looking contours for mapping, but by no means would I want to use that smoothed DEM for any analysis – I’ve removed too much of the useful information to get such a nice result.

So what about my jagged coastline?  I won’t actually go through and do this, but I’d be quite tempted to select those particular 0 contours, delete them and then add in my coastline (line) layer and merge it with this one.  Again, this would be solely for mapping purposes and not suitable for analysis.  For that matter, if I’m just showing these on the map, I might be able to get away with not merging those two layers at all and just making sure I’ve matched the line colours.

One last subtle point: let’s look at the attribute table to illustrate this:

The Contour values have been sorted in ascending order and you can see that in some cases I’ve got several features with the same elevation (e.g. two 100s, three 140s) and 23 records in all for contours ranging from 0 – 240 m in 20 m intervals.  My original contour layer is a bit worse, with 30 records when in the simplest case I should only have 13.  As a next step, I could run the Dissolve tool which would merge all of my contours with the same value into one record, thereby simplifying my layer, on the map and in the table.  It will look exactly the same on the map but the table will have fewer records and this might save me a bit of trouble when I start symbolising and labelling these contours – a topic we’ll address in the next post.

Before we finish, one last evaluation step.  Up at the top of this post I showed the 1:50K topo map – so how do our results here compare against the “official” contours.  Here you go – three sets of contours here – the smoothed DEM ones in blue, the original smoothed contours in darkish brown and the topo map ones in light brown:

You can better see the effect of the melted butter DEM here.  And the smoothed DEM contours are missing out on some of the detail of the undulations in the terrain that both the others capture.  I could address this by maybe going back and using a 3 X 3 neighbourhood rather than a 7 X 7, which would create less smoothing.  I won’t do that here but I hope you can see how easy it would be to do so – five minutes worth of work maybe?

One might have a question about how to set your contour interval.  While it might be tempting to derive, say 1 m contours from this DEM, I wouldn’t have much faith in the results.  A very rough rule of thumb is that your contour interval should be no less than half the resolution of your DEM.  So with the 15 m DEM, I’ve be pretty comfortable doing 10 m contours, but wouldn’t go so far as to do 5 m contours.  I could do 7.5 m but that’s a bit nonsensical.  Nothing will stop you from doing so, but I just wouldn’t put that much faith in what they show.  In this post I’ve used 20 m intervals mainly so that we can do a bit of a comparison with the “official” contours.

Elevation contours are a fundamental way of showing topography on a map.  They’re not all that useful for analysis but are very effective and well-understood ways of showing the terrain.  In this post you’ve seen how relatively straightforward it is to derive them and two different approached to get map quality contours.  Tune in next week for the next phase of making them look nice on a map.

C