Select to view content in your preferred language

Round Raster decimal values

3143
1
09-04-2012 10:53 AM
DavidMendoza
Emerging Contributor
Hi!

I hope someone can help me. I need to make round the decimal values from a raster, there are only two python functions to do it:

-RoundUp(inRaster)
-RoundDown(inRaster)

However, I need a function that returns the floating point value x rounded to n digits after the decimal point. If n is omitted, it defaults to zero. The result is a floating point number. Values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done away from 0 (so. for example, round(0.5) is 1.0 and round(-0.5) is -1.0).
0 Kudos
1 Reply
DavidMendoza
Emerging Contributor
We gave a solution using a python script to make the Round. I apologize, but the solution is written in spanish:


Suponiendo que tenemos un raster de temperaturas positivas y negativas con valores decimales. Se usa la herramienta de python: �??Python window�?�.

Se separan en dos rasters, uno con valores positivos y otro con los valores negativos, dando como resultado dos rasters: tmpPos y tmpNeg.

rasterPos=Con(Raster("tmp")>=0,1,0)
rasterNeg=Con(Raster("tmp")>0,1,0)
tmpPos=(Raster("tmp") * Raster("rasterPos"))
tmpNeg=(Raster("tmp") * Raster("rasterNeg"))

Para postivos y negativos, se separan en raters, uno de puros valores enteros y otro para decimales, quedando 4 nuevos rasters:

tmpPosInt=Int("tmpPos")
tmpPosDec=(Raster("tmpPos") - Raster("tmpPosInt"))
tmpNegInt=Int("tmpNeg")
tmpNegDec=(Raster("tmpNeg") - Raster("tmpNegInt"))

Se hace una reclasificación con la herramienta Reclass. Con esto se trabaja en los rasters de decimales:
En el caso de los decimales positivos:
Si decimal es mayor igual a 0.5 entonces cambia a 1
Si decimal es menor a 0.5 entonces cambia a 0
Se genera el nuevo raster: decPosRecla

En el caso de los decimales negativos:
Si decimal es mayor igual a -0.5 entonces cambia a 0
Si decimal es menor a 5 entonces cambia a 1
Se genera el nuevo raster: decNegRecla

Se hacen los rasters redondeados para los positivos y los negativos

tmpRedPos=(Raster("tmpPosInt")+Raster("decPosRecla"))
tmpRedNeg=(Raster("tmpNegInt") - Raster("decNegRecla"))

Por último, se suman estos dos últimos rasters y da el raster redondeado de temperaturas.

tmpRedondeado=(Raster("tmpRedNeg")+Raster("tmpRedPos"))
0 Kudos