I want to convert a raster map encoding directional flows (the output of r.terraflow) to a vector map. I'm using r.thin to process the output. It terminates successfully with 0 pixels removed during the last iteration. Yet when I try to vectorise the result with r.to.vect and feature=line, I get the following error message:

Extracting lines...
ERROR: Raster map is not thinned properly.
   Please run r.thin.

I have tried rerunning r.thin on the already thinned output, with the same result. I did not find anything in the documentation of either r.thin or r.to.vect to suggest what might be the problem here or how to fix it.


In case it is relevant:

r.thin changed behaviour from GRASS 6 to GRASS 7. In GRASS 6, cells with non-0 values are considered for thinning, while in GRASS 7, cells with non-null values are considered for thinning.

This means that you may have to change your 0 cells to null cells before r.thin will work as expected. All cells with non-null values are considered by r.thin in GRASS 7, so if the input raster contains cells with value 0, the result could also contain cells with value 0.


The r.thin module will thin only the non-zero cells in a raster map. Please check that this condition is fulfilled. Perhaps you have to r.null on the map to set no data pixels to NULL beforehand.

  • Thanks for the suggestion. I've tried both adding a null map and removing it with r.null and I get the same result. Any other ideas? – Lars Kotthoff Mar 10 '12 at 12:03

I know this question is history now but in case anybody else comes by looking for help:

I'm not sure why to be honest, but running r.grow and r.reclass and then r.thin seems to work to prepare rasters for r.to.vect conversion.

The code should look something like:

# reclassify raster, mapping raster values that you want to turn into lines to 1, others to NULL
r.reclass input=my_raster output=my_reclassed_raster rules=reclass_rules.txt 

# grow this reclassified raster a bit (not too much or it will obscure your data)
r.grow input=my_reclassed_raster output=reclassed_grown radius=2

# reclassify this raster by the same rules as before 
# this changes data type of r.grow output back to CELL
r.reclass input=reclassed_grown output=my_grown_reclassed_raster rules=reclass_rules.txt 

# finally we can now run r.thin
r.thin input=my_grown_reclassed_raster output=thinned type=line

After all that, r.to.vect should work properly on thinned

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.