Digital Terrain Model (DTM) creation (1/2)

In this exercise a Digital Terrain Model (DTM) will be built starting from vector contour lines.

Contour lines import in shapefile format and their rasterization

One of the recurring tasks when using GRASS is data import from a non native GRASS format: in this exercise the import of a vector file in the Shape format is shown. The map will be then transformed into a raster and it will be used to create a DTM.

Data import

First of all download the SHAPE contours.tgz and decompress it in your home directory. Then start from the GRASS menu the command File -> Import vector map -> Common import formats.
The program requires the full path to the shape file (already decompressed) to be imported, in this case it should be /home/user-name (replace your user-name); most of the available options should be leaved to their default. The name of the importad map in GRASS is automatically set to the name of the shape file, but it can be changed by double-clicking on it (in the third column, Name for GRASS map). Here the default "contours" name will be used.

ESRI-shapefile import

The process' output is shown in the following window:

Data import result

Vector map visualization

First of all, clear the Layer Manager of all the maps. Select each map from the list and click the icon to delete it. This operation does NOT physically delete maps, it just removes them from the list of the maps to be drawn on the current display.

To view the contour level map that has just been created, locate in the GIS layer Manager the button . A window in which it is possible to set all the parameters of the vector map to be displayed will appear. Click and select from the list the contours vector map just created. Check the next image to make sure you have carried out the procedure correctly (it is similar to that used to view a raster map).

Procedure to view a vector map
To show the map in the display click now the icon in the Map Display window.

View of the contours map

The height of each contour line of the imported map are stored as attributes and they can be queried directly using the icon on the Map Display and clicking on the contour line: attributes are shown in the Output window of the GIS Layer Manager:

Data query
Once you have finished querying the map, exit from the query mode by clicking on the icon . To display the whole table click the icon of the GIS Layer Manager.

Transformation of the vector contour lines into raster contour lines

Obtaining a raster map from a vector one always implies an approximation. In this case, since linear objects are transformed, a suitable resolution must be set to limit the approximation. First of all, use g.region: Settings -> Region -> Set region, and select the tab: Resolution. Set the resolution using the field Grid resolution 2D inserting the value 1 (the measurement unit being the meter). Select the tab: Existing and insert in the field Set region to match this vector map the name of the vector map that must be converted into a raster, in our case contours. Once you are done click Run. Now the current region covers the whole contours map with 1 meter resolution.

Now, to carry out the conversion, open the window by selecting File -> Map type conversions -> Vector to raster.

The name chosen for the output map is contours_raster, by checking the first option as shown in the figure, the new created map will be added to the GIS Layer Manager list.
Clicking on the tab Attributes it is possible to define the name of the column used to get the height attribute of each line, in our case: level.

Conversion of a vector map to a raster one
Click the Run button to start the conversion (if the processing is too slow, set the resolution, as shown above, to 2 meters). If you do not have selected "Add created map into Layer tree" use contours_raster in Gis Layer Manager to view the raster map (and remove the other maps), as shown beforehand. Depending on the Map Display window size, it could be difficult to see the (raster) contour lines: in this case zoom in.

Conversion result (1m resolution)

To check the correspondence between vector contour lines and the newly created map, zoom in a small area and overlay the contours vector map to the contours_raster raster map, adding the first one to the Layer Manager (make sure the vector map is on top of the raster one). You should see perfect correspondence.

Comparison between vector contour lines and raster ones obtained converting the vector ones