Assignment 02
Processing gridded DTMs
Deadline is 2025-12-16@18:00

- What you are given to start
- How to compute the slope
- How to compute the hillshade
- How to calculate and export the isocontours
- Good to know
- Marking
- What to submit and how to submit it
In this assignment, you have to process the DTM of an area stored in a grid. You have to perform the following four tasks:
- extract/generate the gradient (one component of the slope)
- extract/generate the aspect (one component of the slope)
- extract/generate the hillshade
- extract the isocontours
This will require you to write one Python program that reads a GeoTIFF, and outputs a new one for the gridded output (gradient, aspect, or hillshade) and a GeoJSON file for the isocontours. Your software should work for any GeoTIFF used as input, the CRS will always be in meters (eg EPSG:7415 for the Netherlands).
What you are given to start
The help code is in the /hw/02/ folder of the GitLab repository of the course and implements that behaviour, just use it.
Your Python program should follow those rules:
- should be called
geo1015_hw02.py -
should take 4 arguments as input:
- the command:
gradient,aspect,hillshade, orisocontours - the input file to read, a GeoTIFF
- if the sub-command
isocontoursis chosen, then the range must be passed as argument (see below)
- the command:
- should output, in the current folder:
gradient.tiff,aspect.tiff, orhillshade.tiff, depending on the option chosen by the user- or
out.geojsonifisocontourswas the chosen sub-command
- should not import any other modules you wrote; add functions only in that module
The range is a Python range that defines what isocontours need to be extracted. It is given as a string: (100, 500, 100) means range(100, 500, 100) which means 4 contour heights would be extract: 100, 200, 300, and 400.
python geo1015_hw02.py aspect myinput.tiff
outputs a file aspect.tiff in the current folder
python geo1015_hw02.py isocontours myinput.tiff '(100, 500, 50)'
outputs a file iso.geojson in the current folder
How to compute the slope
You should use the Finite difference method to calculate the slope (see p.89 of the book).
For the gradient, the output should be in percentage.
For the aspect, the output should be a cartographical azimuth in degrees: 0 is the North, 90 is East, 180 is South, 270 is East, etc.
How to handle the no_data values as input? You should implement the same behaviour as what GDAL does (you can use QGIS to test), which means you will have no_data in the output grid too.
If the aspect is unknown (flat area), you should assign -9999 as value, as GDAL does.
How to compute the hillshade
It should be calculated as explained in the book (p.95), and the default values of GDAL/QGIS should be used.
Handle no_data values the same way GDAL does it.
How to calculate and export the isocontours
Your isocontours need to be output in the format GeoJSON.
Each straight-line segment will be a LineString with an attribute height, as shown here for 2 straight-line segments:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [ [0.1, 0.2], [10.0, 10.0] ]
},
"properties": {
"height": 100,
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [ [10.0, 10.0], [15.2, 21.8] ]
},
"properties": {
"height": 100,
}
}
]
}
There shouldn’t be any duplicate line segments. The orientation of the line segments is not important.
There exist Python libraries to read and write GeoJSON, but I don’t recommend using them.
Python can natively read and write JSON (import json); I give an example in the starting code.
Good to know
- the GeoTIFF input file can contain
no_datavalues, be warned! - you can reuse the given code, modify it as you wish, add functions, etc. Please put all the code in the same file.
- no external libraries can be used, except startinpy, numpy, and rasterio. Everything from the Python standard library is fine (math, json, sys, etc.)
- the time it takes for your program to terminate has no influence on the marks you’ll get
Marking
| Criterion | Points |
|---|---|
| followed all rules and compiles/runs without modifications | 1.0 |
| gradient results | 2.0 |
| aspect results | 2.0 |
| hillshade results | 2.0 |
| isocontour results | 3.0 |
What to submit and how to submit it
You have to submit one file:
geo1015_hw02.py(write your name at the top of the file where it’s indicated)
Oh, and no report is required.
Upload your file to this SURFdrive page and when prompted for your name put your student number

[last updated: 2025-12-01 16:53]