Assignment 02

Processing gridded DTMs

Deadline is 2025-12-16@18:00



In this assignment, you have to process the DTM of an area stored in a grid. You have to perform the following four tasks:

  1. extract/generate the gradient (one component of the slope)
  2. extract/generate the aspect (one component of the slope)
  3. extract/generate the hillshade
  4. 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:

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

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:

  1. 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]