Tips and Tricks

From GRASS-Wiki
Revision as of 00:54, 18 December 2006 by HamishBowman (talk | contribs) (Using QGIS as a frontend to GRASS: explain the connection)

Jump to: navigation, search

Tips and Tricks

Using QGIS as a frontend to GRASS

  • QGIS started as a simple viewer for geodata. And that's really what it still is: a simple-to-use geodata viewer with some editing capabilities. That's what it was designed to be and that's what it can do really well. QGIS does not have built-in capabilities for geodata processing and analysis.
However, a while back, Radim Blazek, who was then a core developer of the GRASS 6 system, decided to write a plugin for QGIS that would make it possible to access GRASS functionality from within the QGIS GUI.
And that's what you get today, when you download a binary version of QGIS for your platform: QGIS + GRASS 6 plus a plugin that makes using GRASS from QGIS simple and fun.

QGIS can run as a frontend to GRASS. There is support for displaying maps, editing maps, and execution of simple GIS functions. The GDAL/OGR library is a requirement for that (but for GRASS anyway):

To use the two together, the GDAL-GRASS plugin must be installed:

Test that the GDAL-GRASS plugin is available with this command:

  gdalinfo --formats

Look for a line like "GRASS (ro): GRASS Database Rasters (5.7+)"

Enable the QGIS GRASS plugin from QGIS:

  GUI: Plugins / Plugin Manager / Check the GRASS checkbox

The GRASS toolbar should now be visible. While not a firm requirement, it is easier to start QGIS from within a GRASS session.

Importing SRTM30plus data

SRTM30plus data consists of 33 files of global topography in the same format as the SRTM30 products distributed by the USGS EROS data center. The grid resolution is 30 second which is roughly one kilometer.

Land data are based on the 1-km averages of topography derived from the USGS SRTM30 grided DEM data product created with data from the NASA Shuttle Radar Topography Mission. GTOPO30 data are used for high latitudes where SRTM data are not available.

Ocean data are based on the Smith and Sandwell global 2-minute grid between latitudes +/- 72 degrees. Higher resolution grids have been added from the LDEO Ridge Multibeam Synthesis Project and the NGDC Coastal Relief Model. Arctic bathymetry is from the International Bathymetric Chart of the Oceans (IBCAO).

All data are derived from public domain sources and these data are also in the public domain.

GRASS 6 script described in GRASSNews vol. 3 won't work with this dataset (as it was made for the original SRTM HGT files). But you can import SRTM30plus tiles into GRASS this way: -sb input=e020n40.Bathmetry.srtm output=e020n40_topex bytes=2 north=40 south=-10 east=60 west=20 r=6000 c=4800
r.colors e020n40_topex rules=etopo2
GRASS Users Mailing List
Getting SRTM30plus tiles

Exporting GRASS maps to GMT

GMT (Generic Mapping Tools) is a Free software package for creating publication quality cartography.

GMT homepage:

Exporting GRASS maps to GMT:
(Supplied by the GRASS Users Group of Davis, California)

Currently there are several *.out.GMT permutations, several in different languages (bash, python, etc.), and each of which with relative pros/cons. An effort to unify these approaches would save much of the current difficulties in moving complex raster+vector data into a GMT-friendly format. A simple road map toward this goal is outlined:

Proper conversion of GRASS raster color data into GMT compatible CPT files

David Finlayson's does a nice job of this. Once we decide on an optimal language to implement the routines in this may need translation.

Proper conversion of GRASS raster data to GMT compatible binary grids

A combination of r.out.bin | xyz2grd can accomplish this. Several attempts at generalizing this procedure have been proposed:, r.out.gmt (Hamish and Dylan), (Dylan, based Hamish's work).

Proper conversion of GRASS vector data to GMT compatible ascii files

There is currently an effort (with some funding!), see some of the chatter on the GRASS and GMT mailing lists: GRASS-list GMT-help

Automatic conversion of symbology data stored in a gis.m or QGIS saved state to GMT options

Ideas expressed on various mailing list, haven't seem much since. It should be a relatively simple excercise in XML parsing to convert symbology stored in a QGIS project file into something that GMT can use.

General approach

Since GMT relies on a sequence of specialized programs to "build-up" a postscript file, some thought must be put into how the conversion should take place. As usual, form should follow function- maximum flexibility, robustness, and accuracy being primary objectives. However, a simple means of creating high quality 2D maps would be a tremendous (I think) addition to the GRASS toolset. Especially since this is something frequently cited by critics. --DylanBeaudette 02:47, 10 December 2006 (CET)

1. should we continue down the well troden path of single-use, highly efficient programs for the various conversion steps: i.e v.out.GMT, r.out.GMT, etc.?

2. should there be a unified approach to the process: something akin to - ?

Interfacing R-Statistics with GRASS

  • All the necessary functions for the GRASS 6 interface are now in packages on CRAN, so that on Linux/Unix (or Mac OSX) installing rgdal from source with PROJ4 and GDAL installed, or Windows installing from binary, the required packages are: sp; maptools (now includes spmaptools); rgdal (now includes spGDAL, spproj); spgrass6 - now all on CRAN.
  • Using R and GRASS with cygwin: It is possible to use Rterm inside the GRASS shell in cygwin, just as in Unix/Linux or OSX. You should not, however, start Rterm from a cygwin xterm, because Rterm is not expecting to be run in an xterm under Windows, and loses its input. If you use the regular cygwin bash shell, but need to start display windows, start X from within GRASS with startx &, and then start Rterm in the same cygwin shell, not in the xterm.

Using GRASS with an on-line Web-GIS


(please expand)

Starting and running GRASS from a script

See GRASS and Shell.

Running GRASS remotely on OS X

Tiger (OS 10.4) changed the default configuration of SSH from previous versions of OS X. You can no longer start an ssh session with the -X flag and display the Tcl/Tk components of the GRASS GUI remotely. If you are running grass on OS X (10.4) between hosts on a network (i.e. running it on one machine but displaying it on another), you will need to use the "trusted forwarding" mode of SSH in order for the Tcl/Tk generated graphics, such as d.m or gis.m in order for the GUI graphics to make it through your connection. This can be done using the -Y flag when you start the ssh session:

ssh -Y remotehost

or add this to ~/.ssh/config:

Host hostname
  ForwardX11 yes
  ForwardX11Trusted yes

Using the -X flag, or simply turning on X11Forwarding in the SSH configuration files, is not enough: the symptoms in this case are that a d.mon window will function fine, but none of the Tcl/Tk dialogues will work, failing with an error message complaining either about Wish not behaving as expected, or a "Bad Atom".