"Open Source GIS: A GRASS GIS Approach" - Book Online Supplement  
Software        

Datasets:
- 1st Edition
- 2nd Edition
- 3rd Edition

Code examples:
- 1st Edition
- 2nd Edition
- 3rd Edition

Internet links:
- 1st Edition
- 2nd Edition

Errata:
- 1st Edition
- 2nd Edition
- 3rd Edition

Sample chapter:
- Unix basics
- Unix commands
- Aerial + Ortho

GRASS Changes:
- 1st Edition
- 2nd Edition


Short courses
Presentations

[HOME]


Excerpt from

Open Source GIS:

A GRASS GIS Approach, First Edition, 2002

www.grassbook.org

Chapter 2

PREREQUISITES TO USE GRASS

   GRASS is a software package designed to run under various UNIX com- pliant systems, such as Linux , SUN-Solaris, Irix, MacOS X as well as under MS-WindowsNT/2000/XP (with Cygwin). Recently, it was also used on a handheld iPAQ device. Both 32 bit and 64 bit architectures are supported. Effective use of GRASS therefore requires certain familiarity with UNIX and an adequate computer hardware.

2.1 HARDWARE AND SOFTWARE REQUIREMENTS

   The modular structure of GRASS allows it to run with a very small memory overhead, therefore the hardware requirements are quite moderate. When running GRASS on a PC workstation or a notebook, standard equipment is generally sufficient. The bare minimum is a 586 compliant processor and 64 MB RAM, however, for efficient processing of large data sets (for example raster maps with millions of grid cells) RAM around 1 GB can significantly speed up the performance. For geospatial data, more RAM is generally more effective than a faster CPU. Heavy users of visualization tools can greatly benefit from a high-end graphics card with OpenGL hardware acceleration. The GRASS binaries compiled for a Linux system require about 100 MB, other UNIX systems may need up to 180 MB. The GRASS on MS-Windows version needs about 90 MB plus some space for the Cygwin environment. To comfortably work with GRASS a three-button mouse and a 17" or preferably a larger monitor is recommended.

   Probably the most cost-effective system can be built by combining GRASS with Linux or other freely available UNIX compliant operating system. Commercial Linux distributions often include a wide range of application programs in easy to install packages on a CD-ROM.

   The GRASS source code is written in C programming language and can be compiled with free (e.g. GNU C compiler) as well as proprietary compilers. The compilation temporarily requires at least 250 MB hard drive capacity. After compilation and installation the allocated space can be cleaned up. The entire GRASS source code consists of more than 1.5 million lines of C code, making it one of the top ten Open Source projects based on the code size. Due to modern configuration tools implemented in the source code, the local compilation is quite simple after fulfilling the requirements for additional libraries. Most of these libraries are currently available with the operating system or can be downloaded from the Internet using the links on the GRASS website ( http://grass.itc.it/ ). Details about the compilation requirements are described in the INSTALL file which is provided within the source code. However, for the beginner it is recommended to download the current binaries.

2.2. UNIX BASICS

   If you are already a UNIX expert you may skip the following subsections and go straight to the Section 2.3 (Downloading and installing GRASS). However, if you have just started to work in UNIX compliant systems, learning the basics is essential for efficient use of GRASS. Contrary to general belief, UNIX is relatively easy to learn. You need to understand the overall system's structure and know a few commands to survive. Then you can manage files and run applications such as GRASS. The commands presented in this section are valid for all UNIX systems.

2.2.1 What is UNIX?

   UNIX is an operating system originally designed in 1969 for mainframe computers and later used for high end workstations. Over the past decade, several versions were developed for PC with Linux emerging as the best known system. Because UNIX itself is a registered trademark, various names are used for the UNIX derivatives (Solaris for SUN, HP-UX for Hewlett-Packard, IRIX for SGI, FreeBSD). The popularity of Linux has greatly stimulated the GRASS development.

   Working under Linux does not require special expertise thanks to the choice of several graphical user interfaces. A wide range of applications is available, including Office-type packages (e.g., StarOffice) and image manipulation tools (e.g., Gimp). Well known graphical software (e.g. CorelPaint/CorelDraw) was ported to Linux too.

    UNIX allows different programs to run at the same time (multitasking). Several users can be working on the same computer at the same time (multiuser) through the network with different users working within individual protected environments. System crashes are nearly unknown and even if a program freezes, it can be removed from the memory with a special command (kill) without endangering the system's stability. Moreover, UNIX compliant systems are almost free of viruses, as the internal protection concept prevents their distribution and the system security focuses on prevention of cracker attacks in the network environment. The long development history of UNIX has lead to its exceptional robustness and stability.

    Some UNIX commands, valid for all UNIX derivatives, are described in the following subsections.

2.2.2 Login and X Window

    Before starting to work in UNIX, it is important to know that UNIX is case sensitive. Keep this in mind when going through the login procedure and while using file names and commands.

    After starting your UNIX computer you are welcome by a login screen. The login procedure protects your data and enables different users to share one system in protected environments. The system administrator has to add each user to the system's user list and provide him with a disk space (usually his home directory) and a password. Every user is assigned to a work group. Depending on the system installation you will either see a graphical or a text based login screen. In case of the graphical login, you simply enter user name and password and you will get to your desktop environment. In the case of the text login screen, you have to enter your user name and password and start up the X Window by typing

startx   (for Linux)

or

openwin (for Solaris) which opens your desktop environment.

    In UNIX, the graphical user interface is separated into a server and a window manager. The server X Window (sometimes called X11 or simply X) runs the window manager which controls the windows, drag-and-drop menus, icons and other GUI components. Different window managers are available for the X server, for example, Solaris provides Openlook and CDE, in Linux you can choose among fvwm, KDE, Gnome, and others. The main elements of these

KDE snapshot

    Figure 2.1. GRASS used in the KDE environment on Linux interfaces are identical, but the look-and-feel may be different. Figure 2.1 shows GRASS running in the KDE window manager.

   While you can do a lot of work using applications and utilities available through your window manager menus, often the most efficient use of UNIX is through its commands which are typed in the terminal window. The start button for a terminal is found under Utilities in the window manager menu or on the toolbar on the bottom of your screen. After opening a terminal window you will see the prompt, for example, [yourname@yourmachine] or something similar (the appearance of the prompt can be customized). Here you can enter the UNIX commands and start applications. Within the terminal window the so called shell interprets your commands. It receives the commands from the keyboard and transfers them to the operating system. The shell is loaded automatically, when you open a terminal window. There are different shells available: csh (C-shell), bash (GNU Bourne-Again shell) and the tcsh (TC-shell). All shells will accept every command but they differ in their behavior, for example, how they handle cursor keys and file name completion. Automatic file name completion saves a lot of typing because you only need to input the first character(s) of the file or command name and the shell will complete it after pressing the shell-specific completion key. The name completion key in tcsh is <ESC> (press twice), in bash it is <TAB>. Previous commands can be selected and edited with <Arrow-up> and <Arrow-down>. Also, you can transfer text from a terminal window to another one using "copy-and- paste" with a mouse. Use the left mouse button to mark and copy the text and then drop it wherever you need it by the right or middle mouse button (paste).

    You can customize the appearance and behavior of your terminal(s) using a menu which will appear, when you click with right mouse button within your window. For example, if you want to enlarge the fonts in your terminal press the right mouse button and choose Preferences in the menu and then choose Browse for the font in the General section of the Preferences. The desktop can be customized using the menu which is accessed by clicking with right mouse button within the desktop background. Besides terminal windows, your preferred window manager provides also an electronic mailbox (some GRASS modules will send mails to report progress), a watch, a tool displaying the current system's workload, and a console window. The latter shows system messages sent by the operating system. As you may learn, especially messages like file system full are important. GIS data sets can be really large and you may sometimes reach the file space limits of your computer.

2.2.3 Managing files

    At startup time, your home directory is selected as working directory. You can store your files here and organize them under various subdirectories. Listing files and their properties. Let us start with a command which dis- plays all files in the current directory. Typing ls at your prompt will display the list of files and subdirectories stored within your current directory. If you want a more complete information about your files type

ls -l The displayed list resulting from this command may look similar to Figure 2.2. The first column (permissions) shows information about the file type and the usage permissions. The next column shows the number of subdirectories. To the right of that, the owner (user) of the file and the user's group (group) are listed. Following the column of the individual file sizes (size), the date (with time) at which the file has been created or modified is shown. The last column contains the filename (file) or the name of the subdirectory (directory).   The current directory is listed as " . ", the parent directory as " .. ". For example, in the Figure 2.2, the directory grassdata is a subdirectory, identifiable by d in the first column. The file latex is a link (l in the first column). These links refer to files or directories located elsewhere in the system. The file nations.ps is a real file (in this case we have a postscript file with the extension .ps) recognizable by the dash in the first column.

   Important feature in UNIX are the file/directory permissions. They define who is allowed to read, write to files or, in case it is an executable program (with one to three x in the permissions column), who may run this particular program. The permissions are subdivided into three groups: the user (owner) permissions, the members of the working group and the members of other groups (other) permissions. For directories the x permission defines which person may change (enter) into that directory. For example, the file nations.ps (see Figure 2.2) is readable for all users, but it can only be changed (written) by the user paul. The directories mail and projects are only accessible by paul. The directory grassdata is accessible by all users but limited to reading. The file ps4mf.txt can be read by all users, but only members of the working group users may change it (including the user paul). The file permissions are usually set correctly by the operating system, however, for security reasons you should check the permissions regularly. The following

Unix directory

      Figure 2.2. Structure of a directory listing in UNIX example shows how you can change the file permissions with chmod, but we don't want to go into further details of the related commands chown and

chgrp:

chmod ug+w nations.ps The file permissions of nations.ps are now set to -rw-rw-r-- which means that paul and all members of the group users can read and write the file, while all other users can only read it. Organization of files. UNIX files are stored on a hard disk which is usually divided into different areas called partitions. Each partition corresponds to a directory with optional subdirectories. In UNIX, there is a common directory structure which is similar (but not always the same) in all UNIX derivatives. The important directories are (Figure 2.3):

  • / is the root directory: all directories are subordinated to this directory like for example the /home tree. Do not mix this up with the user "root" who has administrator rights in UNIX.

  • /home is keeping the directories of all users on the system except the "root" user who may have his home directory either in /root or directly in the root directory (/).

  • /home/paul/ is your home directory: here your personal files are stored. Normally only you have the permission to store data here.

  • /usr is the directory tree used for the application programs, help texts, etc.

  •  /lib is the directory used for the libraries shared by different applications. These libraries correspond to the "DLL" files in the MS-Windows world. However, there is no registry as in MS-Windows.

You can create a new subdirectory projects in your home directory and then change into it by

mkdir projects

cd projects With cd you will get back to your home directory. File management, floppy disk and CD-ROM access. If you want to copy a file you can either use a File Manager from the window manager menu or directly use the copy command in a terminal window. You must specify the filename and the destination (new filename or destination directory). For example to copy a file nations.ps from the current directory into the subdirectory projects type (Figure 2.3):

cp nations.ps projects/ Files can be moved or renamed using the command mv. To change into our projects subdirectory and rename the file nations.ps to nationsold.ps we type:

cd projects

mv nations.ps nationsold.ps You can remove a file using the command rm. For example, we can change back to the parent directory (" .. ") and remove the nations.ps file:

cd ..

rm -i nations.ps The parameter -i is very important because it ensures that you will be asked whether you really want to remove the file (instead of silently removing it). This setting may be already predefined on your system. Note that UNIX files are really deleted and cannot be restored.

   The star symbol " " and the question mark are used as wildcards e.g. for file extensions. Be careful with the use of wildcards in the remove command!

   You can read a text file (output it onto the screen) using one of the following commands

more myfile.txt

cat myfile.txt Most UNIX systems (like Linux) permit to use floppies from the MS-Windows world. To simplify life, a nice collection of programs exist ­- the "mtools".

Unix directory structure

  Figure 2.3. Structure of a directory tree in UNIX If this collection is installed on your system simply add m to your known MS-DOS commands (if you remember them). The following command displays the contents of a floppy:

mdir a: The command:

mcopy a:myfile.txt . copies the file myfile.txt from the floppy to the current directory (" . "). The mcopy requires a destination where to store the file, so we use the dot as an alias for the current directory. With

mcopy yourfile.txt a: we copy a file from the UNIX system to the MS-DOS floppy.

   If you want to read data from CD-ROM it requires one more step (if you omit a graphical filemanager). CD-ROM drives as well as tape and floppy drives are so called "devices". With a certain command you can integrate (mount) such device, in this example the CD-ROM, into the filesystem. With

mount /cdrom the directory structure of the CD-ROM becomes visible in the /cdrom directory (see Figure 2.3). You may need to have the "root" (the UNIX administrator) privileges to perform this command. With su you become root, if you have the password, alternatively with

sudo mount -t iso9660 /dev/cdrom and your own password. On some computer systems CD-ROMs are automatically detected and integrated with the automount function. To release (unmount) a CD-ROM from the system, enter

umount /cdrom and you can remove the CD-ROM from the drive.

2.2.4 Running applications

   You can start an application (e.g. GRASS) by typing the program's name into a terminal window. Some programs can be selected from the menus of the window manager or by clicking on an icon on your desktop. File managers also allow to open programs by clicking on the particular program name. While the applications usually provide their own help texts, manuals for the UNIX commands can be displayed with the man command, for example the manual for the command mkdir can be displayed by:

man mkdir

If you are starting an application with its own graphical user interface by typing its name in the terminal window, the terminal becomes busy and you cannot do any other work from that window. This can be avoided by adding the character " & " after the program name. Then the application will be started independently from the terminal (in the background), enabling you to continue using this terminal. However, this is useful only if the application doesn't run in text mode. An example (start of a clock):

xclock & The clock window will appear, and you can still continue to use the terminal window for other commands. The processes xclock and shell in your terminal window now run in parallel (multitasking). In case you forgot to add the " & " character on startup time, you can enter <CTRL><Z> in the terminal window (stops the application), followed by bg. This adds the " & " character to the previous command and releases the application into the background operation mode. Note: you cannot start GRASS with " & " character because it requires the shell. If you accidentally started GRASS like this, type fg into the terminal. The fg command brings the process to the foreground.

    A useful capability of UNIX is the so called piping. Using pipes (|, <, >) program output can be redirected to another program to become its input data. So different programs can be directly connected through a data stream. In GRASS you can use such pipes if you want to redirect the output of modules to a file

module > file.txt The direction of the arrowhead defines the direction of the data stream. The character " | " is used for the data exchange between programs, and the characters " < " and " > " are used for redirecting from (" < ") and to (" > ") a file. This offers a variety of options for script programming to automate GIS processing. GRASS, as a modular GIS, offers high potential here, for details see Section 11.2.

    In principle, you can use any number of programs (e.g. terminal windows) at the same time, the only limitation is the memory of the computer and the processing time.

    We will end this section with some practical notes for making your work more efficient. With <SHIFT><Page-up>/<Page-down> you can scroll in the xterm (to see previous commands). A method to reduce typing efforts is to recall a command by only starting it with an exclamation mark and its prefix. So !ne may start, if present in the command history, the last netscape ... command. You can also use the command history to see the numbered sequence of commands that you have used. For example, you can then re-run the 23rd command by typing !23.

   For the GIS work it makes sense to write protocols. Using xedit, nedit or another editor you can save commands to a text file by copy-paste. Mark the text (commands) row by row with the left mouse button and input them with the middle mouse button into the editor. Leaving programs and UNIX. If you only intend to leave the computer for a while, for example, to get your cup of coffee, you can simply lock the screen (use the related menu entry) and all applications remain running.

   If you are leaving for a longer time (e.g. at the end of the day) you may want to logout of your UNIX session. First, finish all the active applications, how- ever, the programs running in the background do not need to be interrupted. Then select "logout" from the window manager's menu, where you will have 3 options: "logout", "halt", "reboot". If you just want to leave and keep the computer running choose "logout" and you will be brought to the login screen.

   If you want to switch off the computer you have to finish both the active applications and the programs that you may be running in the background because they will be aborted. When working in a network environment, you also have to check whether there are other users working on the machine with the w command. Then you select "logout" from the window manager's menu and choose "halt". You may be prompted for a password at this point and then you will be brought to the text mode which will report the procedures going on during the shut down. When it is finished, you can switch off your computer.

   On the following page (Table 2.1) you will find an overview of important UNIX commands. The following different command structures are used:

  • to start an application like GRASS, enter:

    command, for example, grass5

  • to use a UNIX utility, enter:

    command filename, for example, gimp myimage.jpg

  • to use a UNIX utility with options, enter:

    command options filename, for example, rm -i myfile.dat

Suggestions for further reading on UNIX are Peek et al., 2001, Robbins and Gilly, 1999, and Siever et al., 2000.

Peek, J., G. Todino, and J. Strang, 2001. Learning the Unix Operating System. A Concise Guide for the New User. 5th ed. Cambridge: O'Reilly & Associates.

Robbins, A., and D. Gilly, 1999. Unix in a Nutshell: A Desktop Quick Reference for SVR4 and Solaris 7. 3rd ed. Cambridge: O'Reilly & Associates.

Siever, E. (ed), J.P. Hekman, S. Figgins, and S. Spainhour, 2000. LINUX in A Nutshell: A Desktop Quick Reference. 3rd ed. Cambridge: O'Reilly & Associates.

Tab. 2.1: Important UNIX commands

$Date: 2008-05-18 21:14:49 +0200 (Sun, 18 May 2008) $
© 2002, 2004, 2007-2009 Helena Mitasova and Markus Neteler (Send your comment)
"Open Source GIS: A GRASS GIS Approach"