0

I am trying to use GRASS on the command line, specifically the r.thin module. It seems to execute properly but I have no output raster dataset to work with afterwards, it is as if it just gets swallowed into the void. This is the exact command:

grass79 -c /data/mapset/PERMANENT --exec r.thin input=dummy_img output=thinned

And I get the following output:

Starting GRASS GIS...
WARNING: Mapset </data/mapset/PERMANENT> already exists. Ignoring the request to create it. Note that this warning may become an error in future versions.
Cleaning up temporary files...
Executing <r.thin input=dummy_img output=thinned> ...
Raster map <dummy_img> - 658 rows X 658 columns
Execution of <r.thin input=dummy_img output=thinned> finished.
Cleaning up temporary files...

So it seems that it executed properly.

But when I look inside the /data/mapset/PERMANENT folder, I see only the dummy_img (which was already there) and no mention of thinned:

$ ls data/mapset/PERMANENT
dummy_img

Am I doing something wrong? here is the docpage but I don't see any specific caveats to this.

I am executing it inside of a docker container with several other commands, this is the full list of commands to be executed, in case they provide any clues (formatted for readability):

sudo docker run -v /home/ibtravel/grass_data:/data neteler/grassgis7 /bin/bash -c 
'rm -r /data/mapset;
grass79 -c /data/paths.TIFF -e /data/mapset;
grass79 -c /data/mapset/PERMANENT/ --exec r.external input=/data/paths.TIFF output=dummy_img;
grass79 -c /data/mapset/PERMANENT/ --exec r.null map=dummy_img setnull=0;
grass79 -c /data/mapset/PERMANENT/ --exec r.thin input=dummy_img output=thinned;
grass79 -c /data/mapset/PERMANENT/ --exec r.to.vect input=thinned output=vectorized type=line;
grass79 -c /data/mapset/PERMANENT/ --exec v.out.ogr input=vectorized output=/data/out/out_lines.shp format=ESRI_Shapefile'

https://grass.osgeo.org/grass76/manuals/r.thin.html

I also downloaded a docker image with GRASS 7.6 instead of 7.9, as it is supposed to be stable, but it still did not work, just seemingly no output whatsoever.

Furthermore, this algorithm seems to work when I run it in QGIS 2.18.23 so there must be something going on...

In response to @Micha's answer:

I have put everything into a shell script as suggested, and indeed it is much cleaner. This is the script as it stands now:

r.external -o input=/data/paths.TIFF output=dummy_img
g.region -ap raster=dummy_img
#r.reclass input=dummy_img output=dummy_img_nulled rules=/data/reclass_rules.txt
r.null map=dummy_img setnull=0
#r.thin input=dummy_img_nulled output=thinned
r.thin input=dummy_img output=thinned
r.to.vect thinned output=vectorized type=line
v.out.ogr input=vectorized output=/data/out/out_lines2.shp format=ESRI_Shapefile --overwrite

But now it seems to segfault when I run r.null map=dummy_img setnull=0. You can see in the commented lines that I have come up with a patch solution by using r.reclass to just mimic the intended effect of r.null, but I still find it odd that r.null is giving me such grief with this

  • r.null does not work on external images. You must import the data before you can modify it. – mankoff Aug 11 at 12:00
  • This was documented on the r.external page, but not the r.null page. I've added a pull request to improve the GRASS r.null documentation: github.com/OSGeo/grass/pull/91 – mankoff Aug 11 at 12:14
1

A few comments might help:

  1. The -c flag is used to create a new Location using a georefenced file or EPSG code. You should not put the path to your GRASS Location as the value for -c.
  2. FAQ #0: Always set the GRASS computational region before you do any raster processing. So before r.null do:

    g.region -ap raster=dummy_img

  3. Instead of starting up GRASS 6 times, with 6 single commands, I think it's prefereable to start once and run all the commands in one go from a script. More details at this wiki page. The short version: put your list of commands into a shell script (without the repeated grass79 -c...) then

    export GRASS_BATCH_JOB="/path/to/your/shell_script.sh"

  4. (Added after wfgeo's comment). Can you try actually importing the paths.TIFF rather than r.external? I think that you cannot modify external rasters as r.null is trying to do. So the first command should be:

    r.import -o input=/data/paths.TIFF output=dummy_img

If this is indeed the issue, then it would be helpful to report to GRASS developers. r.null should fail more gracefully in a case like this.

Then when you strart GRASS, it runs those commands and exits.

  • Thank you so much for the tips. GRASS is very much new territory to me and I definitely felt like I have just been flailing about. I have put all the commands into a single shell script instead of individual calls, which is much cleaner, but I am still having problems with `r.null. I did define the region with ´g.region´ like you said, but it segfaults when I try to run ´r.null map=dummy_img setnull=0´. I'll put more info up in the question so it's easier to read – wfgeo Aug 9 at 8:08
  • Added another suggestion in the answer above – Micha Aug 9 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.