User:Astronautics~enwiki/GRASS
GRASS is complex and its interface can be difficult to learn. This tutorial is written to get technically inclined users a grasp of the basics of GRASS and over the first speed bump in its steep learning curve. After that, you're on your own. If you need more information, check out some heftier GRASS documentation, especially the "Tutorials/Courses" section. You may also want to talk to the friendly people at Wikipedia:WikiProject Maps.
Don't try any of this on Windows unless you have cygwin or something installed and are prepared to deal with extra grief.
This tutorial is in my userspace but anybody can work on it.
Introduction
[edit]GRASS GIS is a powerful open source Geographic Information System (GIS) program. It is suitable for analysing and manipulating geographic data as well as producing representations of it. For Wikipedia, GRASS can be used to produce maps and useful visualisations.
This tutorial uses the "Spearfish" sample data set of a region of South Dakota that is distributed for GRASS 6. You can download it here.
GRASS concepts
[edit]GRASS executes within a custom bash environment with an non-mandatory (but standard and very useful) TCL/TK frontend. It is extremely modular and its commands are all executable from the shell. In fact, the GUI frontend is really just that; it performs all its operations by calling these commands according to parameters the user sets within the GUI.
- Bold terms are key:
GRASS expects a directory in the filesystem to be designated as a master database. Under this database are any number of directories that represent locations, which are geographically distinct regions of study. The Spearfish data set unpacks to one such location. Inside a location directory are directories that represent mapsets. These mapsets are collections of various items of actual geographical data. As an elementary GRASS user you do not need to deal with the actual data files within a mapset; the interface will abstract the component files as the named raster maps, vector maps, etc. that you will work with.
Every location has a mapset named PERMANENT which holds the source data. In a multi-user environment, you would probably not be able to write to this mapset. Even in a single user environment, it is generally left unaltered. The Spearfish data set comes with a blank mapset called "user1" that you will use to do actual work in. When you work with your own location, you can create a similar user mapset for yourself.
Starting out with the GUI
[edit]First, create your GRASS database directory and unpack the spearfish data set inside it. Run GRASS 6 by typing "grass" at an open terminal (this is important later).
Welcome to GRASS.
All it's missing is a few tumbleweeds, but we can liven that up pretty quick. You selected the "spearfish60" location and the "user1" mapset. (You may want to rename "user1" to something personal, like "GRASS on Wheels".) No matter what mapset you are using, it is not necessary to copy data from the PERMANENT mapset, because you can draw from it directly (technically, this is because PERMANENT is automatically part of your default search path).
Open the "GIS" menu, select "Manage maps and grid3D files", and select "List maps". Select "rast" from the dropdown data type selection menu and click the "Run" button.
Notice how the top of the list says "g.list type=rast"? Open the shell you started GRASS in. You'll notice that it now has a new prompt. You are in a custom bash session with all the powerful GRASS commands in your $PATH. Go ahead and try a couple GNU commands to prove it to yourself. Now try typing the command that the GUI executed for you, "g.list type=rast".
The results are exactly the same. Now you understand how the GUI works - many of its functions operate in a similar fashion.
Displaying a raster map
[edit]Now that we have a starting list of raster maps that is available to us, we can start working with one. Close the map list and click the tenth button on the toolbar, the "Add raster" button. An item called "raster1" will appear in the workspace tree below the toolbar. You can rename it to whatever you want by double clicking on it. Highlight this item and type "elevation.dem" as the "Raster name" in its properties pane that will appear below the item tree.
Now that you have a data item in your workspace, you can display it. Click the first button in the toolbar, "Display selected layers (current region)". A GRASS monitor window will appear and your map will be drawn inside it.
Adding a vector layer
[edit]Use the process described above to list the maps of type "vect" in the PERMANENT mapset of the spearfish60 location. You'll see that some of the vector data has fairly descriptive names. Let's add the "roads" and "streams" vector data to our workspace. Click the "Add vector" toolbar button (it is next to the "Add raster" button that you used). You'll see that vector data items have considerably more properties than raster items. That's fine, because all you really need is to enter the "Vector name" - but let's set the "Line color" of the roads to grey and the streams to blue while we're at it.
Display the new map on the monitor.
Visualization with NVIZ
[edit]NVIZ is an n-dimensional visualisation tool. As an example of its power, let's set up the same map we are using above as an NVIZ visualisation. Click the "Display" menu and select the first item, "Start NVIZ".
You'll want to supply some elevation data and a couple of vector overlays. Specify "elevation.dem" as our raster elevation data, and "roads@PERMANENT,streams@PERMANENT" as the vector overlay string.
Click "Run" and be amazed. With a bit of tweaking of the controls, you can produce a visualisation like this: