I have three rasters which represent distance (in metres) from certain things (bus stops, parks, libraries). I would like to reclassify these rasters so that they get integer values based on the following criteria:

between 1 - 1000 = 1
between 1000 - 2000 = 2
between 2000 - 3000 = 3
between 3000 - 4000 = 4
between 4000 - 5000 = 5
between 5000 - 6000 = 6
between 6000 - 7000 = 7
between 7000 - 8000 = 8
between 8000 - 9000 = 9
9000 and above = 10

I know how to do this in Spatial Analyst, but I don't have a license and I'm trying to use Open Source tools. I've attempted to use r.reclass and followed the tips in this question, but the input raster needs to be an integer raster. At the moment, my distance rasters are floats.

I've also tried using the reclassify tool in the Geospatial Modelling Environment but the input raster also needs to be an integer raster.

I've also tried using the Raster Calculator in QGIS by following this example, but it appears that that only works with a single criteria not 10.

I've been pulling my hair out trying to convert the rasters to integer, but can't figure it out.

Does anyone know how to either reclassify a float raster or convert a float raster to an integer raster?

Note, the end goal of this will be to perform a weighted overlay. Eventually, I may have Spatial Analyst in ArcGIS to do this, but I'd like to know how to do it using Open Source tools.

  • for a weighted overlay, you can use r.series. Unfortunately only for grass7 you can specify the weight for each raster. If you have problems with the r.series open a new question.
    – nickves
    Commented Apr 10, 2013 at 1:17
  • 1
    The simplest and computationally most efficient way in this particular example is to divide the values by 1000, take the ceiling, and cap the result at 10. Those three local arithmetic operations will be fast; you won't have to set up a reclassification table; and (because of that) there's no table where typographical entry errors will create subtle errors. But for a weighted overlay operation you would be better off not reclassifying the data at all... .
    – whuber
    Commented Jul 15, 2014 at 22:05
  • this question came up recently: gis.stackexchange.com/questions/116473/… Commented Oct 14, 2014 at 22:58

4 Answers 4


yes, r.reclass is for reclassing thematic rasters, like the Corine Land Cover. It will work for your data, but the routine will cast the float numbers to integers before doing the reclass, so it might lead to unexpected results.

What you are looking for is r.recode

The rules are defined in many formats, one of those is the following:

old_low:old_high:new_val (i.e. new_high == new_low)

So, based on your question the rules should be something along this lines:



So the command should be like this:

r.recode input=oldmap output=newmap rules="/path/to/rules.txt"

Afterwards you can use the r.reclass module for the newmap you created.


You can do this with the raster calculator in QGIS. The example @Fezter refers to, is unfortunately extremely simplified. Lets say you have values from 1 to 360 that you want to reclassify into 3 classes, then the syntax should look like this:

("raster" < 90) * 1 + (("raster" >= 5) AND ("raster" < 180)) * 2 + ("raster" >= 180) * 3

This will create a raster with the values 1, 2 and 3. Everything else will be given a no data value.

Notice that by using the operators a >, <, >=, <=, the * (star) changes its usual multiplication meaning to "replace with". Also notice the syntax for specifying a range with the AND operator. Once you have understood this logic is quite easy to reclassify in QGIS without resorting to cumbersome format changes or other workarounds.


This is how you can do this with R:

r <- raster('your file name')
tab <- cbind(0:9 * 1000, c(1:9,Inf)*1000, 1:10)
x <- reclassify(r, tab, filename='output.tif', datatype='INT2S')

Try open source program GridMap Reclass at SourceForge: http://sourceforge.net/projects/mapgridreclass/

  • 1
    Could you add some more information to your answer (maybe the information from SF) like if you've used it with a non-integral raster and had success?
    – Paul
    Commented Jul 15, 2014 at 17:53

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.