Hack 73. Make Your Own Contour Maps
Why buy expensive contour maps when you can make your own, using free elevation data?
Anyone who's done a bit of hiking or other outdoor activity is probably familiar with the idea of a contour map. Contour lines offer a convenient way of visualizing the lay of the land on a flat map by showing successive increments of ground elevation as nested lines or figures. When the lines are spaced far apart, elevation change is gradual, and when they are closer together, steeper terrain is indicated. A good contour map can cost a pretty chunk of change, but it's easy to use GRASS to make one of your own.
All you need to get started is a working version of GRASS and some elevation data for the area you're interested in mapping. Any elevation data will do, from the kilometer-resolution GTOPO30 data available from NASA for the whole world, all the way down to the really nice 10-meter resolution digital elevation models available for parts of the U.S. from the U.S. Geological Survey. For simplicity's sake, we'll make a contour map of San Francisco, using the data we imported in [Hack #72] .
Start GRASS in the San_Francisco location used earlier [Hack #72] . Start a new monitor with d.mon and use g.region to center the display on San Francisco with the region we saved previously, without actually displaying anything in particular yet:
GRASS:~/contour > d.mon start=x0 GRASS:~/contour > g.region San_Francisco
Next, we'll use the r.contour tool that ships with GRASS to create a vector layer containing our contour lines. This program just samples the elevation model, noting where the terrain crosses a particular threshold and generating an outline of the contour at each of these points. We'll start our contour lines at sea level and show a new line for every 50-meter rise in elevation. You will be prompted with the minimum and maximum contour values foundgo ahead and accept them. Finally, use d.vect to display the new vector layer on the monitor:
GRASS:~/contour > r.contour in=sf_elevation out=sf_contour min=0 step=50 GRASS:~/contour > d.vect sf_contour color=blue
Figure 6-38 shows the contours of San Francisco, shown in blue, with 50-meter steps between contour lines. The result looks pretty good, but the map is a bit busy.
Figure 6-38. A contour map of San Francisco, with 50 m steps between contour lines
We can use the cut parameter for r.contour to clean up the more spurious bits, by discarding contour lines with fewer than a certain number of points. We'll use a value of 200 to demonstrate the effect:
GRASS:~/contour > r.contour in=sf_elevation out=sf_contour min=0 step=50 cut=200 GRASS:~/contour > d.redraw
If we place the two maps side by side (perhaps by writing to a different layer and starting another X11 monitor), we can see that our new map sacrifices detail for the sake of clarity. Such is always the prime trade-off inherent in the art of cartography! Another approach we can take, if the contour map still looks too busy, is to raise the step parameter to a higher increment, say, 100 meters:
GRASS:~/contour > r.contour in=sf_elevation out=sf_contour min=0 step=100 cut=50 GRASS:~/contour > d.redraw
Figure 6-39 shows the resulting map, which is enormously simpler, but with the basic information still conveyed. Obviously, you should play with the options for r.contour when mapping your own data and see which set of trade-offs looks best to you.
Figure 6-39. A contour map of San Francisco, with 100 m steps between contour lines.
Finally, just to prove to ourselves that this is indeed the elevation data we think we're looking at, let's plot our 100-meter contour map on top of the original elevation data:
GRASS:~/contour > r.colors sf_elevation color=aspect GRASS:~/contour > d.erase GRASS:~/contour > d.rast sf_elevation GRASS:~/contour > d.vect sf_contour color=blue
Sure enough, all the terrain features are still shown in Figure 6-40, now outlined in blue by our contour layer. That's all there is to it!
Figure 6-40. The same contour map, draped over the original elevation model
Now you can use this layer to make new maps or augment other maps in GRASS. You can generate a PostScript rendition of your new contour map for printing to hardcopy [Hack #75] . You can even work with your new contour layer in other mapping applications by exporting it to an ESRI Shapefile:
GRASS:~/contour > v.out.ogr in=sf_contour dsn=. layer=sf_contour type=line GRASS:~/contour > ls sf_contour* sf_contour.dbf sf_contour.shp sf_contour.shx
|