Assignment 01

Spatial interpolation

Deadline is 2022-11-29 17:00

Late submission? 10% will be removed for each day that you are late.

This is an individual assignment.



The aim of this assignment is to implement (part of) four interpolation methods used for modelling terrains:

  1. nearest neighbour [NN]
  2. one variant of IDW [IDW]
  3. linear interpolation in TIN (based on a Delaunay triangulation) [TIN]
  4. natural neighbour interpolation [NNI]

You have to complete the 4 functions given and they should return the interpolated value (or specific exceptions, see below).

What you are given to start

Code is in the /hw/01/ folder of the GitLab repository of the course.

We give you the skeleton of the Python program:

  1. geo1015_hw01.py is the main(). You are not allowed to modify this file! This main reads the file params.json, calls the interpolation functions in mycode_hw01.py, and creates a raster file (which you can view in QGIS; use it to test/visualise your solutions).
  2. mycode_hw01.py is where all your code should go. The 4 functions defined there must be completed, and you are not allowed to change the input parameters. You are of course allowed to add any other functions you want in that unit (please do not include any other unit you code, add your code to that single file). You are only allowed to import modules from the Python standard library (anything you installed through pip is thus not allowed, except scipy, numpy, and startinpy).
  3. raster.py contains the class Raster, which is used to store the array of elevation and has a write function to export to a text file.
  4. params.json: a very simple JSON file that defines what the input file is, which interpolation methods to execute, with what parameters, and where to store the output.
  5. samples.xyz: an example of an input file with sample points. All input files that the program reads will be like this one: a CSV file with headers (x y z), each line is one point, and the delimiters between x y z is a space.
  6. the folder /other-samples contains some areas with part of a GeoTIFF raster file we took somewhere, and we generated randomly samples from it in samples.xyz

To run the code you need to install the following libraries:

pip install numpy
pip install scipy
pip install startinpy

What you have to do

You have to write the code for the 4 functions in mycode_hw01.py.

Each function returns the z-value (as a float) of the estimation of the elevation.

However, if the (x, y)-coordinates are outside the convex hull of the input points, then the functions need to throw an Exception: raise Exception("Outside convex hull").

For IDW, if there are no points inside the search radius, then: raise Exception("No point in search radius").

Good to know

Marking

Criterion Points
followed all rules and compiles/runs without modifications 1
nn interpolation 1
idw interpolation 2
tin interpolation 2
natural neighbour interpolation 4

What to submit and how to submit it

You have to submit one file: my_code_hw01.py where your name and student number is clearly identified at the top.

Oh, and no report is necessary.

Upload the file to this Dropbox page.

[last updated: 2022-11-17 08:21]