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 onexternal
images. You must import the data before you can modify it.r.external
page, but not ther.null
page. I've added a pull request to improve the GRASSr.null
documentation: github.com/OSGeo/grass/pull/91