Tips and Tricks: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
No edit summary
 
 
(48 intermediate revisions by 9 users not shown)
Line 3: Line 3:
===Using QGIS as a frontend to GRASS===
===Using QGIS as a frontend to GRASS===


QGIS can run as a frontend to GRASS. There is support for displaying maps, editing maps, and execution of simple GIS functions.
* 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.


QGIS homepage:  http://qgis.org
: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.


To use the two together, the GDAL-GRASS plugin must be installed.
: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.
<!-- Benjamin Ducke on grass-user 18 Dec 2006 -->


GDAL homepage:  http://www.gdal.org
 
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):
 
* QGIS homepage:  http://qgis.org
* GDAL homepage:  http://www.gdal.org
 
Here is a nice tutorial for editing vectors using QGIS as a frontend to GRASS: [[Editing_GRASS_vectors_with_QGIS]] (''where did it go? unported from old wiki site?'' )
 
To use GDAL and GRASS together, the GDAL-GRASS plugin must be installed:
 
* [[Compile and install GRASS and QGIS with GDAL/OGR Plugin]]


Test that the GDAL-GRASS plugin is available with this command:<BR>
Test that the GDAL-GRASS plugin is available with this command:<BR>
Line 25: Line 36:
While not a firm requirement, it is easier to start QGIS from within a GRASS session.
While not a firm requirement, it is easier to start QGIS from within a GRASS session.


Related: How to compile/install [GrassQgisGdalOgrPlugin][GRASS and QGIS with GDAL/OGR Plugin]]
* [[QGIS GRASS Cookbook]] - Recipes for common tasks
 
===Importing SRTM30plus data===
 
See [[Global_datasets#SRTM30plus_data|Global datasets]] page


===Exporting GRASS maps to GMT===
=== GMT (The Generic Mapping Tools) ===
 
* [[GRASS and GMT]]


GMT (Generic Mapping Tools) is a Free software package for creating publication quality cartography.
GMT (Generic Mapping Tools) is a Free software package for creating publication quality cartography.
Line 33: Line 50:
GMT homepage:  http://gmt.soest.hawaii.edu
GMT homepage:  http://gmt.soest.hawaii.edu


Exporting GRASS maps to GMT:  http://169.237.35.250/~dylan/grass_user_group/ (Supplied by the GRASS Users Group of Davis, California)
=== Interfacing R-Statistics with GRASS ===


===Interfacing R-Statistics with GRASS===
* [[GRASS_and_Rstat|GRASS and R]]


see:  http://grass.ibiblio.org/statsgrass/index.php#grassR
GRASS may be combined with R-Statistics to create a very powerful geostatistical analysis platform.


R-Statistics homepage: http://www.r-project.org
R-Statistics homepage  http://www.r-project.org
 
(please expand)


===Using GRASS with an on-line Web-GIS===
===Using GRASS with an on-line Web-GIS===


see: http://grass.itc.it/start.html
see:


UMN Mapserver homepage:  http://mapserver.gis.umn.edu
* [[GRASS and MapServer]]
* [[GRASS and PHP]]
* [[GRASS and Python]]


(please expand)
(please expand)
Line 53: Line 70:
===Starting and running GRASS from a script===
===Starting and running GRASS from a script===


You have to set a couple of variables
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".
 
==Quick tips ==
 
=== Checking categories pertaining to more than one feature ===
<!--====Discover multiple features having the same category====-->
v.build op=cdump map=mymap | gawk -F"|" '{print $1}' | uniq -dc
returns, e.g.<br />
5    35347<br />
(5 features with cat 35347)


<pre>
  export GISBASE=/usr/local/grass60
  export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
  export GISRC=$HOME/.grassrc6
  export GRASS_PNGFILE=/tmp/grass6output.png
  export GRASS_TRUECOLOR=TRUE
  export GRASS_WIDTH=900
  export GRASS_PNG_COMPRESSION=1
  export GIS_LOCK=$$


  #test:
=== Applying [[v.edit]] tools on a whole map ===
  g.version
[[v.edit]] allows many powerful geometrical manipulations. Operations are performed on certain features you must point out with arguments like ''ids='', ''cats='', ''coords='', and so on. When you need to run a tool on the whole map (e.g. every boundary), then it can be annoying to describe them (e.g. provide a ''cats'' list). A common way is to use the -r (reverse selection) flag in combination with pointing at feature-ids equal to zero (i.e. empty selection) :
v.edit map=mymap type=boundary tool=merge ids=0 -r


  #this should print the GRASS version used.
</pre>


Then you can launch GRASS commands. This works within Shell scripts and also in the command line terminal.
=== Compensate the lack of line ends symbology in ps.map ===
[[ps.map]] does not allow to specify line-end (from- and to-nodes) symbols oriented in the same direction as the last (resp. first) segment. Typically you want to add arrowheads to a line vector. Here we suggest a one-line gas (grep/awk/sed) solution. The idea is to output a bunch of selected lines ("where" argument), extract concerned couples of vertices, calculate a position and an angle for each tip, then import this set of data in a point vector. This point vector can latter be invoked in a ps.map command file.


===Running GRASS remotely on OS X===
The next example illustrates the process for line vector ''mylines''. We want to be able to draw an arrow head at the to-node lines for which attribute ''code'' equals 3 or 5 :
<source lang="bash">
for i in `v.out.ascii input=mylines format=standard where="code=3 or code=5" \
  | grep -n 'L  ' | sed s/\:/' '/ | sed s/'  '/' '/ | awk '{print $1+$3-1}'`; do
    v.out.ascii input=mylines format=standard where="code=3 or code=5" \
      | sed -n ${i},$((i+2))p | \
      awk \
        'NR == 2 {x=$1;y=$2} NR == 1 {xi=$1;yi=$2} \
        NR == 3 {cat=$2} END {pi=3.14159;OFS="|"; \
        print cat,x,y,atan2(yi-y,xi-x)/pi*180}';
done \
  | v.in.ascii -n out=myarrowheads x=2 y=3 cat=1 \
      columns='cat int, x double precision, y double precision, angle double precision'
</source>


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:
''Warning: intended to be a set of piped commands, it does not handle temporary maps/files. Obvioulsly it is not an optimized solution in terms of calculations (v.out.ascii is run within the loop as many times as the number of processed lines). But it is reasonably fast and leaves no traces when completed.''


ssh -Y remotehost
It results in a point vector named ''myarrowheads''. Attribute field ''angle'' contains the rotation angle value fitting with to-node last segment direction.


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".
ps.map command allowing to hardcopy arrows would look like this :
<pre>
vlines mylines
width 0.6
color black
end
vpoints myarrowheads
color black
symbol extra/n_arrow1
rotatecolumn angle+90
size 2
end
</pre>
[[Category:Documentation]]

Latest revision as of 08:47, 10 May 2013

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):

Here is a nice tutorial for editing vectors using QGIS as a frontend to GRASS: Editing_GRASS_vectors_with_QGIS (where did it go? unported from old wiki site? )

To use GDAL and GRASS 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

See Global datasets page

GMT (The Generic Mapping Tools)

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

GMT homepage: http://gmt.soest.hawaii.edu

Interfacing R-Statistics with GRASS

GRASS may be combined with R-Statistics to create a very powerful geostatistical analysis platform.

R-Statistics homepage http://www.r-project.org

Using GRASS with an on-line Web-GIS

see:

(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".

Quick tips

Checking categories pertaining to more than one feature

v.build op=cdump map=mymap | gawk -F"|" '{print $1}' | uniq -dc

returns, e.g.
5 35347
(5 features with cat 35347)


Applying v.edit tools on a whole map

v.edit allows many powerful geometrical manipulations. Operations are performed on certain features you must point out with arguments like ids=, cats=, coords=, and so on. When you need to run a tool on the whole map (e.g. every boundary), then it can be annoying to describe them (e.g. provide a cats list). A common way is to use the -r (reverse selection) flag in combination with pointing at feature-ids equal to zero (i.e. empty selection) :

v.edit map=mymap type=boundary tool=merge ids=0 -r


Compensate the lack of line ends symbology in ps.map

ps.map does not allow to specify line-end (from- and to-nodes) symbols oriented in the same direction as the last (resp. first) segment. Typically you want to add arrowheads to a line vector. Here we suggest a one-line gas (grep/awk/sed) solution. The idea is to output a bunch of selected lines ("where" argument), extract concerned couples of vertices, calculate a position and an angle for each tip, then import this set of data in a point vector. This point vector can latter be invoked in a ps.map command file.

The next example illustrates the process for line vector mylines. We want to be able to draw an arrow head at the to-node lines for which attribute code equals 3 or 5 :

for i in `v.out.ascii input=mylines format=standard where="code=3 or code=5" \
  | grep -n 'L  ' | sed s/\:/' '/ | sed s/'  '/' '/ | awk '{print $1+$3-1}'`; do
    v.out.ascii input=mylines format=standard where="code=3 or code=5" \
      | sed -n ${i},$((i+2))p | \
      awk \
        'NR == 2 {x=$1;y=$2} NR == 1 {xi=$1;yi=$2} \
         NR == 3 {cat=$2} END {pi=3.14159;OFS="|"; \
         print cat,x,y,atan2(yi-y,xi-x)/pi*180}';
done \
  | v.in.ascii -n out=myarrowheads x=2 y=3 cat=1 \
       columns='cat int, x double precision, y double precision, angle double precision'

Warning: intended to be a set of piped commands, it does not handle temporary maps/files. Obvioulsly it is not an optimized solution in terms of calculations (v.out.ascii is run within the loop as many times as the number of processed lines). But it is reasonably fast and leaves no traces when completed.

It results in a point vector named myarrowheads. Attribute field angle contains the rotation angle value fitting with to-node last segment direction.

ps.map command allowing to hardcopy arrows would look like this :

vlines mylines
	width 0.6
	color black
	end
vpoints myarrowheads
	color black
	symbol extra/n_arrow1
	rotatecolumn angle+90
	size 2
end