An Introduction to: Geographic Resources Analysis Support System Geographic Information System

James Madison University
Integrated Science and Technology
Environment Sector
Author: Cate Wardell
Advisor: Dr. Steve Frysinger
Last updated: 26-Apr-2001



Learning Raster Image Commands

To learn about basic raster commands you will need to load a digital elevation model of Shenandoah National Park.

To import the GLOBE binary digital elevation model to into a GRASS raster file:

  • Type r.in.bin input=shenandoah_dem.bin output=elevation bytes=4
    • input=name: the name of the GLOBE binary digital elevation model
    • output=name: the name of the new raster map
    • bytes=value: number of bytes per cell
      • options: 2, 4, 8

To load the raster image into the monitor:

  • Type d.rast map=elevation
    • map=name: the name of the raster map to open

The digital elevation model should now be visible in the monitor and will look similar to Figure 3.1 below.

Figure 3.1: Digital elevation model in a monitor


Displaying the scale

The scale for a raster map can be plotted over the map. To draw the scale:

  • Type d.scale bcolor=black tcolor=white at=0,0
    • bcolor=name: background color underlying the scale and north arrow
      • options: white, red, orange, yellow, green, blue, indigo, violet, magenta, brown, gray, and black
    • tcolor=name: foreground color in which the text, scale, and north arrow are drawn
      • options: white, red, orange, yellow, green, blue, indigo, violet, magenta, brown, gray, and black
    • at=x,y :geographic coordinates designating the location at which the upper left corner of the scale is to be placed

The raster map will now have a black and white scale on it in the monitor, and will look similar to Figure 3.2 below.

Figure 3.2: Digital elevation model raster map with scale


Displaying the legend

The legend for a raster map can be added to the monitor. Use d.erase to remove the old map and d.rast to reload the digital elevation map. To draw the legend:

  • Type d.legend map=elevation color=white lines=100
    • map=name : the name of the raster map
    • color=name: the color of the legend text
      • options: white, red, orange, yellow, green, blue, indigo, violet, magenta, brown, gray, and black
    • lines=value: number of lines to appear in the map legend
      • options: 1 - 1000

IMPORTANT: This elevation raster map has over 65,000 legend entries. Because not all 65,000 can be viewed in the monitor, the lines value was set to 100 in order to see the first 100. Raster maps with less entries will be able to display the entire legend without specifying the lines value.

The raster map will now have a legend on it in the monitor, and will look similar to Figure 3.3 below.

Figure 3.3: Digital elevation model raster map with partial legend


Finding the coordinates of a point

The coordinates of a particular point in a raster map can be printed to the command line interface. To print the location of a point:

  • Type d.where -1
    • -1: print the location of only the first point clicked on the map

The command line interface will prompt you to use the mouse to click on the location of the point you want to locate. This prompt will look similar to Figure 3.4 below.

Figure 3.4: Where point prompt
  • Place the mouse pointer over the location on the map you want to identify, and click the left mouse button.

The location of the point will be printed to the command line interface. This location will look similar to Figure 3.5 below (your screen may look different depending on what location you clicked on).

Figure 3.5: Where point information


Overlaying cell category values

The numerical cell category values can be printed in each area of a raster map. A grid is drawn to outline each area. The numerical values are printed in black or white depending on the underlying raster color. Due to the large size of the map, in order to see the numerical values you must zoom in (using d.zoom) on a portion of the elevation map before running this command. Use d.erase to remove the old map and d.rast to reload the zoomed-in digital elevation map. To overlay the category values and draw the grid in gray:

  • Type d.rast.num map=elevation grid_color=gray
    • map=name : the name of the raster map
    • grid_color=name: the color of the legend text
      • options: white, red, orange, yellow, green, blue, indigo, violet, magenta, brown, gray, and black

The zoomed-in raster map will now have an overlay of grid areas and cell values on it, and will look similar to Figure 3.6 below (your screen may look different depending on which part of the map you zoomed in on).

Figure 3.6: Digital elevation model raster map with grid areas and cell values


Creating neighbor-manipulated map

A new raster map can be created in which each cell category value is assigned a value based on a calculation applied to the surrounding cells. To create a new map with the average of the category values assigned to the 8 cells around each cell:

  • Type r.neighbors input=elevation output=dem_neighbors method=average size=3
    • input=name: the name of the original raster map
    • output=name: the name of the new raster map with the new cell categories
    • method=name: the operation performed on the neighboring cells
      • options: average, median, mode, minimum, maximum, stddev, variance, diversity, and interspersion
    • size=value: the neighborhood size specifies which cells surrounding any given cell fall into the neighborhood for that cell. The size must be an odd integer.

To view the neighbor-manipulated map use d.erase to remove the old map and d.rast to open dem_neighbors. The neighbor-manipulated map should now be visible in the monitor and will look similar to Figure 3.7 below. You can open the original file, elevation, to compare the two.

Figure 3.7: Neighbor-manipulated digital elevation model raster map


Creating and removing masks

A mask can be placed on a raster map. This mask will block out certain areas of a map from analysis. While a mask is active, GRASS commands will only act on data falling inside the masked area. To create a new mask on the map:

  • Type r.mask

The command line will print a menu that looks like Figure 3.8 below.

Figure 3.8: Mask menu
  • Type 2 to create a new mask on the raster map.

The command line interface will prompt you to name an existing raster map layer for masking. This prompt will look similar to Figure 3.9 below.

Figure 3.9: Prompt for mask creation
  • Type in the name of the raster file.

A listing of the map's categories will be shown, that looks like Figure 3.10 below.

Figure 3.10: Raster map category list for mask creation

The command line interface will prompt you to assign a value of 1 or 0 to each map category. Areas assigned category value 1 will become part of the mask's surface, while areas assigned category value 0 will become "no data" areas in the MASK file. Follow the directions at the bottom of the screen until at entire mask has been set.

To remove the current mask:

  • Type r.mask
  • After the menu shown in Figure 3.9 appears, type 1 to remove the current mask on the raster map.


Creating or modifying the color table

The color table of the raster image can be created (if it does not exist) or modified. To modify color table to a gray scale for the digital elevation model:

  • Type r.colors map=elevation color=grey
    • map=name : the name of the raster map
    • color=type: the color table to use
      • options: aspect (aspect oriented grey colors), grey (grey scale), grey.eq (histogram-equalized grey scale), gyr (green through yellow to red colors), rainbow (rainbow color table), ramp (color ramp), random (random color table), ryg (red through yellow to green colors), wave (color wave)

The digital elevation model should now be visible in a gray scale in the monitor and will look similar to Figure 3.12 below.

Figure 3.12: A gray scale digital elevation model

Use r.colors to reset the color table to a rainbow color table.


Drawing vector features

Vector features can be drawn on top of the raster map. Use d.erase to remove the old map and d.rast to reload the digital elevation map. To draw an area on the digital elevation model:

  • Type r.digit

The command line will print a menu that looks similar to Figure 3.13 below.

Figure 3.13: Menu for drawing vector features
  • Type "A" to define a vector area.

The command line will prompt you to define an area. The prompt will look similar to Figure 3.14 below.

Figure 3.14: Prompt for drawing an area vector feature
  • Click the left button to see a print out of the location of your mouse. These locations will be printed to the command line interface and will look similar to Figure 3.15 below.
Figure 3.15: Mouse locations defined during vector feature creation
  • Click the middle mouse button to define a point on the area.
  • Click the right mouse button to stop defining points and close the area.

The command line will prompt you to enter a category number for the area and a label for the category number. These prompts will look similar to Figure 3.16 below.

Figure 3.16: Define area vector feature characteristics
  • Type the new category number.
  • Type the new label for the category number.

The command line will print your entries and prompt you to double check your definition. This prompt will look similar to Figure 3.17 below.

Figure 3.17: Check area vector feature characteristics
  • Type "y" to accept the new area, type "n" to discard the definition (typing "n" will return the command prompt to Figure 3.16).

The command line will print the menu that looks similar to Figure 3.13 above. The procedures for creating lines or circles are similar to the above procedure for creating an area. Once you have defined all the vector features you would like:

  • Type "Q" to quit and define a new raster map.

The command line will prompt you to enter the name of the new raster map. This prompt will be similar to Figure 3.18 below.

Figure 3.18: Prompt to enter name for new raster file
  • Type the name of the new raster map.

You can use d.erase to remove the old map and d.rast to open the new raster map with the vector features.


Displaying category information

GRASS can print the category information for a raster map to the command line interface. Use d.erase to remove the old map and d.rast to reload the digital elevation map. To print category values (for categories 1, 2, and 5 through 10) and labels for the digital elevation model:

  • Type r.cats map=elevation cats=1,2,5-10
    • map=name : the name of the raster map
    • cats=value or range: the category values to display

A category list will be printed to the command line interface and will look similar to Figure 3.19 below.

IMPORTANT: If this map had labels for each category, they would be listed to the right of the category number.

Figure 3.19: Category list for the digital elevation model


Generating statistics report

Statistics reports about a raster map can be generated and printed to the command line interface. To create a statistics reports for digital elevation map that reports the number of each category, the area covered in square meters and the percent coverage of each category:

  • Type r.report map=elevation units=c,me,p
    • map=name : the name of the raster map
    • units=name(s): the unit(s) to report in
      • options: mi(les), f(eet), me(ters), k(ilometers), a(cres), h(ectacres), c(ounts), p(ercent cover)

A statistics report will be printed to the command line interface. Due to the large number of categories, the entire report can not be reference as a Figure. Instead your report should have a beginning that looks similar to Figure 3.20.1 below, and an end that looks similar to Figure 3.20.2 below.

Figure 3.20.1: Beginning of statistics report for the digital elevation model
Figure 3.20.2: End of statistics report for the digital elevation model


Converting a raster map to a vector map

A raster map can be converted into another vector map. To convert the digital elevation map to a vector map of defined lines:

  • Type r.line input=elevation output=dem_vector type=line
    • input=name: the name of the original raster map
    • output=name: the name of the new vector map
    • type=name: type extracted vectors a linear edges or area edges
      • options: area or line

To convert the digital elevation map to a vector map of area edge features:

  • Type r.poly -l input=elevation output=dem_vector2
    • -l: the new map will have smoothed corners
    • input=name: the name of the original raster map
    • output=name: the name of the new vector map

IMPORTANT: The created vector maps can be viewed using the vector display command which is explained later in the tutorial.


Changing the Mapset

Before continuing you will need to change the mapset to the next area (Rockingham County):

  • Type g.mapsets mapset=rockingham
    • mapset=name: name of existing GRASS mapset under the current location

Click the Next button to learn basic vector manipulations.

 


Start button Previous button Next button End button
Home Page button Help button Index button Links button