To the Max!(...imum Gradient...).


Imagine you are an extreme sports holiday company. You've been given raster data of the heights for a hilly area, and you want to find the most extreme gradients on which to set up snowboard runs. The raster data will be text numbers of metres above sea level.

Write a program which does the following.

  1. Pulls in the hillslope heights from a file.

  2. Calculates the maximum slope in all the raster cells.

    To do this use the "D8" algorithm. This calculates the slope between a cell and its eight neighbours, using their height and distance from the cell (this will be one for four of the neightbours, and the square root of two for the other four). The maximum slope is then the greatest of these values. If you get two maximum slopes for the same for a given cell you need to be careful your program doesn't break. You'll also need to think about what to do at the map edges.

  3. Builds an image that has the slope gradients in it rather than the heights.

  4. Has a GUI that displays the heights and the gradients. The images can be greyscale (i.e. set the red, green and blue values for each cell to the associated height).

  5. Saves the gradients to a file in a similar format to the heights.

Additional marks are awarded for the following.

Make the program shade the greyscale heights image different colours depending on the gradient (you may want to look at using the hue, saturation, brightness (HSB) methods for Color objects).

Files for this project.

  • A file of values representing a 300 x 300 raster grid of heights: snow.slope (GIF version for comparison - this should not be used in the project). Each line in the file represents a line in the raster image, starting at the top left.