Assignment 2

In this assignment you will start your GIS C programming. You will use dyanamic 2D-arrays, command line arguments, file I/O; and, you will start working with grid terrain data.

Terrain data in GIS is represented by sampling the values of the terrain and recording the coordinates and the sampled values. This is called a Digital Elevation Model (DEM) of the terrain. There are several types of DEMs, depending on the distribution of the points that are sampled, and how they are connected.

The most commonly used DEM in GIS is the raster or grid. In a grid DEM, the terrain is sampled with a uniform grid and the values are recorded essentially as a matrix of elevations. A grid does not need to store explicitly the coordinates of the sampled points, because they can be infered from the coordinates of, say, the upper-left corner of the grid. Grids are widely used in GIS because of their simplicity and because data comes in grid form from satellites.

Connect to the class directory Finder -> Connect to server -> smb://microwave/courses/csci350/ and take a look at the data in the Materials/DEM folder. All the data that I put there represents grid elevation data for real-life terrains that I collected over the years. This data is usually publicly available. It is in grid arcascii format. You will be able to figure out what it is, but you can always google for help. Note the NODATA value. Can you guess what that represents?

Note that some of the data is pretty large (use ls -l to list sizes). Do not copy this data in your home directory!

The goal of this assignment is to implement a multiply operation on a grid dataset. Your program will read the input grid from file, print out basic information about the grid, multiply the elevations by a given constant, and write the resulting grid to a file. Your program should be invoked as follows:

mult maine.asc maine-5.asc 5

The arguments, in order, are:

  1. the name of the input grid datatset
  2. the name of the output (rescaled) grid dataset
  3. the rescale factor

The input and output datasets are assumed to be in the current directory (you do not need to worry about paths). If your program correctly handles arbitrary path names you will get extra credit. When invoked with a wrong number of arguments your program should display a help message just like a standard unix command:

 mult set1.asc
 usage: mult  in-grid out-grid rescale-factor

Your program should correctly handle the situations when the input file does not exist and other common error scenarios. Your code should include four functions (at least), one to read the grid from a file into an array, one to print info about a grid, one to write the grid from an array to a file, and one to do the actual rescaling. You should design the interface of your code carefully since you will be using it for the next projects. For instance, you may want to define a grid structure to hold all the information about a grid dataset (name, dimensions, data).

Note: Your program should not multiply NODATA values.

To test your program use the (small) grid datasets in the class directory. Some of the datasets are big, so to save space, do not copy them in your directory, but link them.
(to link, use ln -s ...path../Materials/DEM/hawaii.asc . ).

The smallest terrain contains at least 200K elements. For testing purposes, I suggest that you create a small (say 10 by 10) grid dataset, say test.asc. Run your program on it and look at the output to see whether it works.

To submit your code, make a tar file and email it to me by the due date (man tar).