PyGRASS equivalent of piping results from one function to another

When using GRASS commands on the command line, one very neat little trick is to ‘pipe’ results from one function directly to another. An example I used in an earlier post is:

r.category My_map | r.category My_map rules=-

So, how does that works in python using pygrass?
Continue reading “PyGRASS equivalent of piping results from one function to another”


Start R inside GRASS but keep the terminal prompt

I often run R from within GRASS GIS. For example using R as a scripting language to automate GIS analysis. Or to use statistical models in R on spatial data in GRASS.

I used to open R in the terminal. However, I am using more and more RStudio instead. This has one drawback. When opening RStudio in the terminal (or any other program for that matter), you cannot use that command prompt anymore. Continue reading “Start R inside GRASS but keep the terminal prompt”

Getting action into your layer

QGIS provides the option to perform an action based on the attributes of a feature. This is useful if you want to run an external application or view a web page based on one or more values in your vector layer. How to define and run an action is explained in the user guide (, check the section on ‘Action tab’.

I needed this feature to extract information from a vegetation map for Tanzania I am working on. The layer has fields for the vegetation type and an unique ID. I want list both the ID and name of the vegetation type for a number of polygons and export them to a text file. Following the user guide I tried:

 bash -c "echo \"%cat %PNVs2\" >> /home/paulo/output.txt"

Unfortunately nothing was written to the file ‘output.txt’. After trying different options, I found out that the following syntax does work.

bash -c "echo '%cat %PNVs2' >> /home/paulo/output.txt"

I am not terribly familiar with bash syntax (OK, make that a not at all), but it seems things might work slightly different depending on the system you are working on (I am for example working on Ubuntu).

Accessing your file system from within R

R includes some powerful yet easy to use functions that provide a direct interface to the computer’s file system. In the example below I use two of these functions ( and file.copy) to copy a random selection of the songs on my computer to my mp3 player, while making sure that the combined size of these files does not exceed 500MB. Continue reading “Accessing your file system from within R”