Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Generate a Contour Map Layer from a DEM

Operations

Slice Filter Mathematical Operators Recode Scan

What Do I The generation of a DEM (Digital Elevation Model) from contour map data Need? is a common Raster GIS application. However, sometimes contour maps
give a more familiar representation of terrain than a DEM. Digitizing contours from a scan of a topographic map is a slow and tedious process, and often the only alternative elevation data available in digital form is a DEM.

To generate contours automatically, all you need is a DEM. If the area you are interested in spans more than one DEM, it is recommended that you mosaic the DEM map layers before you generate contours to ensure that all the contours line up perfectly at the DEM boundaries. Older contour maps use Imperial units of measure such as feet and miles for elevation and distance; however, most DEMs are measured in metres. If you wish to generate Imperial contours, convert the DEM from Metric before you begin. Converting Metric DEMs to Imperial DEMs To convert a Metric DEM to Imperial measure you must multiply the cell values by a constant (3.4014). Use the Script window to perform this mathematical operation. To open a new Script window select New Script from the Windows menu. When the Script window opens, enter and execute the following script, substituting the names of the map layers from your own project: DEM (feet) = DEM *3.4014;

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-1

The above script statement can be added to the contouring model below if you want to batch process Metric DEMs to Imperial DEMs. Now that you have converted the elevations to feet, convert the cell resolution as well. Open the Information window for your Imperial DEM and select no units from both the Data Units and the Cell Resolution dropdown lists. Most USGS (United States Geological Survey) DEMs have a cell resolution of 30m. To convert this measure to feet, calculate the number of feet in the cell resolution (e.g., 30 m x 3.4014 feet/m = 102.042 feet) and enter this value as the cell resolution:

Example Generating Contours from a DEM


MFworks uses a simple six step model to generate contours from a DEM (Digital Elevation Model). This model will generate contours at intervals of 25 units. The model presented here is for you to copy and paste into your own Script window, substituting your own map layer names, and execute it: steps = Slice DEM By 25 Range 06000 UseBottomValue; vert = Filter steps DiffVert; horiz = Filter steps DiffHoriz; verthoriz = vert+horiz;

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-2

onecontour = Recode verthoriz Assigning VOID To 0,VOID Assigning 1 To -2,-1,1,2; Contours = Scan steps Maximum Around onecontour; To use this model you will need to know a few simple text editing techniques so that you can adjust the parameters of the Slice operation and change the map layer names to match those in your project. You can use the dialog box interface to edit the Slice statement. Syntax and type conventions Using the Script window interface Using the operation dialog box interface Using the dialog box interface to create or edit scripts How the Generate Contours Model Works This model assumes that you are generating a 25 metre contour interval topographic map from a Metric DEM (Digital Elevation Model). You can easily change this value to generate 5 metre, 10 metre, 100 metre, or any other contour interval that you wish. You must decide what contour interval suits your needs. This is partially dependent on the cell resolution of the map layer and the topography of the map layer coverage. Generally map layers with a low cell resolution will be more suitable for higher contour intervals. If you want to convert your DEM to Imperial measure first, add the script statement from the section Converting Metric DEMs to Imperial DEMs above to the beginning of the model. Note: The images in the following section are best viewed on screen at a viewing scale of 150% or printed on a good quality colour printer.

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-3

Begin with a standard DEM map layer:

The map layer named Donation is a USGS (United States Geological Survey) DEM. The Information window shows that it has the standard USGS cell resolution of 30m; elevations are measured in metres.

Grouping Elevation Data with the Slice Operation Contours, by definition, represent the location of points with the same elevation. The Slice operation groups the elevation data into equal intervals. The boundaries between groups represent the location of the contour lines. The following model employs the Slice operation:
Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-4

steps = Slice Donation By 25 Range 06000 UseBottomValue; The UseBottomValue modifier assigns the lowest group value as the value for all the cells in the group. This operation will group all the elevations into 25m intervals beginning at 0. The intervals would, therefore, be 0m, 25m, 50m, 75m and so on up to 6000m. If the data range of your map layer exceeds this range you will have to edit the range values. Be sure to round the initial range value to the closest interval value. For example, if your DEM includes values such as 120m below the datum (0m), change the range to -1256000. The same holds true if your data range exceeds 6000m. Change the final value to the nearest interval value up. If your DEM includes values such as 7002m, change the range to 07025. If you wish to use a contour interval other than 25m, change the By modifier parameter to the new contour interval. For example, if you want 10m contours change By 25 to By 10. Executing the Slice statement produces the following map layer:

The map layer named steps has a data range from 175m to 475m in 25m increments. A red through purple colour sequence has been applied to this map layer to make the elevation increments easier to see. The boundaries between the elevation groups represent the locations of the contours. To isolate these boundaries, an edge detection filter must be applied to the map layer.

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-5

Detecting Boundaries with the Filter Operation Two different edge detection filters will be applied to the map layer named steps to isolate the boundaries between elevation increments. The MFworks Filter operation has several standard image enhancement filters that can be used for edge detection. The DiffVert and the DiffHoriz filters detect changes in value in the vertical and horizontal directions respectively. For example, if you execute the Filter DiffVert operation on a map layer each cell that has the same value as its neighbour to the right will be assigned a value of 0 indicating no change. If the cell value is greater than the neighbour to the right, a value of +1 will be assigned. If the cell value is less than the neighbour to the right, a value of -1 will be assigned. Here is the result of executing the following Filter DiffVert statement on the map layer named steps: vert = Filter steps DiffVert;

The Filter DiffHoriz operation works the same as the Filter DiffVert operation except that differences are calculated with the neighbour below. Here are the results of executing the following Filter DiffHoriz statement on the map layer named steps:

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-6

horiz = Filter steps DiffHoriz;

The contours are already becoming apparent, but if you examine these map layers closely you will see that there are still many breaks in the contour lines. Adding the two directional difference filtered map layers together will fill in the breaks in the contour lines of each separate map layer. Adding Map Layers (Mathematical Operators) The MFworks Script window allows you to perform simple and complex mathematical operations on map layers. You can add two or more layers together. You can subtract, multiply, or divide map layers or develop a complex series of mathematical formulae. This is called Map Layer Algebra. The mathematical operators are applied cell by cell in the order in which you specify the map layers according to the rules of the Order of Operations. The following addition is applied to the vert and horiz map layers: verthoriz = vert+horiz;

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-7

This map algebra statement means add each cell in vert to the corresponding cell in horiz. The following map layer is the result of this expression:

The cells in this map layer with the values -2, -1, 1, and 2 are the result of edge cells being added together or added to non-edge cells. These four values are the contour cells. Cells with the value 0 are the noncontour cells. The values must be reassigned so that non-contour cells have the value VOID and contour cells have a value reflecting their elevation. The Scan operation can be used to extract values from the stepped elevation map layer named steps and assign them to the contour lines. To make the Scan operation assign only values to contour cells and not to non-contour cells, a mask map layer must be created. The Scan operation assigns values to cells in the mask map layer that have a value other than VOID. Therefore, the mask map layer should have the value VOID where there are no contours and some other value where there are contours. Reassigning Values Using Recode The Recode operation is used to explicitly assign values to existing values. In this case the value VOID is to be assigned to all the non-contour cells and 1 to all the contour cells in the map layer named verthoriz:

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-8

onecontour = Recode verthoriz Assigning VOID to 0,VOID Assigning 1 To -2,-1,1,2;

The map layer named onecontour is ready for use as a mask map layer for the Scan operation. Assigning Elevation Values to Contours Using the Scan Operation The Scan operation generates a new map layer where values are assigned to cells based on the values of the cells that surround that cell in the input map layer. The Scan operation below uses the default 3 cell by 3 cell diameter roving window to search for values in the stepped elevation map layer. The mask map layer onecontour, specified by the Around modifier, will restrict the cells that will be assigned a value to all those cells in onecontour that have a value other than VOID. The Maximum modifier specifies that the highest value found in the window for each cell will be assigned to the contour: Contours = Scan steps Maximum Around onecontour;

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-9

The resulting map layer is a 25m topographic map named Contours:

Copyright ThinkSpace Inc., 1998, Version 1

HD-CTR-10

You might also like