0

I'm trying to export a reclassify map in grass to a Geotiff format to pass it to DinamicaEgo platform.

I have 6 classes in grass but when I export it, the exported map show me 255 classes and they are numbered from 0 to 255. The classes 1 to 6 are my classification but the other not.

It's a problem when I load the raster to DinamicaEGO because it compare two classified images and make a probability matrix. So I only need the 6 classes not 255 classes.

Any one knows how can I make the exported raster only with the 6 classes?

I used the command r.reclass for reclassify the image and r.out.gdal for export it.

2 Answers 2

1

I think that you're just seeing the full color table that r.out.gdal creates by default. If you add the -c switch to avoid outputting a color table, you will get only the values you expect.

BTW, the answer by Jun Folledo might be misleading. There is nothing wrong with exporting a reclass raster directly to Geotiff. No need for recode. Here's a simple example:

r.mapcalc -s "r = rand(1,100)"
r.reclass r output=r_reclass rules=- << EOF
> 1 thru 50 = 1
> 51 thru 100 = 2
> EOF
r.out.gdal -c r_reclass out=r_reclass.tif

Now I check the output Geotff with gdalinfo:

gdalinfo -stats r_reclass.tif 
Driver: GTiff/GeoTIFF
Files: r_reclass.tif
Size is 580, 580
Coordinate System is:
PROJCS["Transverse Mercator",
.....
Band 1 Block=580x14 Type=Byte, ColorInterp=Gray
  Minimum=1.000, Maximum=2.000, Mean=1.505, StdDev=0.500
.....
    Generated_with=GRASS GIS 7.0.0
    STATISTICS_MAXIMUM=2
    STATISTICS_MEAN=1.5045749108205
    STATISTICS_MINIMUM=1
    STATISTICS_STDDEV=0.49997906975291
0
0

You can try r.recode

r.recode input=landcov_detailed output=landcov_reclassed << EOF
    1:3:1:1 forest
    4:7:2:2 grassland
    8:12:3:3 others
EOF

The above code reclassifies the original landcover map with 12 classes into 3 classes. Original classes 1 - 3 is classified into 1 and labeled as forest; orig. classes 4-7 are reclassified into 2 and labeled as grassland; while classes 8-12 are reclassified to a new value of 3 and labeled as others.

2
  • This answer is misleading! The r.out.gdal function treats a reclass layer like a normal raster layer, i.e., your geotif file should have values 1 - 6. I would guess that Micha is right, and you are seeing the full colour table.
    – Ecodiv
    Mar 2, 2016 at 15:50
  • thanks, I'll edit my answer. I first used r.reclass but I got more difficulty with it so now I use r.recode. Mar 2, 2016 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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