Raster Calculator gives only 0 or 1 values

10819
7
08-09-2011 10:45 AM
NicoleCarlozo
New Contributor
I'm attempting to create a habitat suitability map using the following formula:

(ratser1 * raster2 * raster3 * raster4 * raster5 * raster6 * raster7 * raster8 * raster9 *raster10 * raster11 * raster12)^(1/12)

Raster calculator wouldn't allow decimals, so all raster cell values are between 0 and 100. First, I multiplied the rasters together and the product had a range of cell values. However, when I attempted to raise the cells to the 1/12th, the product had only 0s or 1s. I tried putting "float" before the formula, but that only resulted in a stretched scale bar and an img with values of only 0 or 1.

Does anyone know a way to get around the no decimal rule? Or perhaps I'm doing something else wrong?

Thanks,
nmc
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
type this in at the end
.... ^(1.0/12.0)

you may have been are experiencing integer division since you were dividing 1 by 12
0 Kudos
ErnestDunwoody
New Contributor III
This is not so much a reply as a further question.
Does anyone know where the proper use of the "float" command is described?

Seems to me it is like pot luck.

Sometimes it works and sometimes it doesn't, sometime put the brackets around everything, sometimes put them around each part of the expression. Who knows?

Appreciate any definitive advice.
Thanks,
Edi
0 Kudos
DanPatterson_Retired
MVP Emeritus
Float is common to most programming languages and programs.  It ensures that an operation that could result in an integer is cast to a floating point number.  Division is one of those cases, for example in Python, division returns an integer value unless one of the numbers involved is a floating point number, or one of them is cast to a float, ie
>>> print 1/3
0
>>> print 1.0/3
0.333333333333
>>> print float(1)/3
0.333333333333
>>> 

Float is used in the spatial analyst for this very reason.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z0000008w000000.htm
and there are other examples elsewhere.
So the general rule of thumb is, cast numbers into floating point values by whatever means if you need it as output.
0 Kudos
ErnestDunwoody
New Contributor III
Hello Dan and thank you.

That is basically what I understood. The difficulty I'm having is getting Float to work in Raster Calculator in ArcInfo10. For Example, the expression

(1 + %L%) * ("%Layer_4%" -"%1st step.img%") / ("%Layer_4%" +"%1st step.img%"+ %L%)

where L= 0.5 and the other terms are bona fide 32 bit signed integer rasters, produces a raster of all 0 output.

The following expression

Float((1 + %L%) * ("%Layer_4%" -"%1st step.img%") / ("%Layer_4%" +"%1st step.img%"+ %L%))

produces the same all 0 output raster.

I can construct a model the long way around using  Float, Add, Mult and Divide and I get a valid raster output.

Any ideas would be very much appreciated

Sincerely,
Edi
0 Kudos
ErnestDunwoody
New Contributor III
Hello again Dan,

The following model (attached) produces a valid output raster without the use of "float".


It does the same as the first raster calculator expression I gave before although it is certainly the long way around.

I'm wondering if there is something amis with my raster calculator installation.

Sincerely,
Edi
0 Kudos
ElizabethGraham
Esri Contributor
Hi Edi,

When I try your Raster Calculator expression with integer inputs and a variable equal to 0.5 I am getting a floating point raster as a result, which is what I expect.
I am wondering what variable type are you using for 'L'? If you use type Double your equation should return a floating point raster. To verify what 'L' equals look at the message being returned when you execute the Raster Calculator. The message has the value of 'L' substituted into the equation, make sure that this value is in fact 0.5.

Example of the message being returned:
Start Time: Tue Aug 23 13:36:44 2011
(1 + 0.5) * (Raster(r"layer_4") - Raster(r"1st step.img")) / (Raster(r"layer_4") + Raster(r"1st step.img") + 0.5)
Succeeded at Tue Aug 23 13:36:45 2011 (Elapsed Time: 1.00 seconds)

Please see the attached image of the expression I executed and my inputs.

I hope this helps.

Liz
0 Kudos
ErnestDunwoody
New Contributor III
Hello Elizabeth,

Thank you for trying to help. Yes I defined "L" as double format.

Checked your attachment and that is what I am writing in the raster calculator. Have used the thing for years in earlier versions of ArcInfo. I also tried it with the Float Command around the whole expression and it won't work.

I'm coming to the view that there is something wrong with my Raster Calculator installation because it should create floating point numbers by the mere inclusion of a floating point operator.

Difficult to accept the need to waste time uninstalling and reinstalling ArcMap10 just to see if that is where the problem lies.

Sincerely,
Edi








Hi Edi, 

When I try your Raster Calculator expression with integer inputs and a variable equal to 0.5 I am getting a floating point raster as a result, which is what I expect.  
I am wondering what variable type are you using for 'L'? If you use type Double your equation should return a floating point raster. To verify what 'L' equals look at the message being returned when you execute the Raster Calculator. The message has the value of 'L' substituted into the equation, make sure that this value is in fact 0.5. 

Example of the message being returned: 
Start Time: Tue Aug 23 13:36:44 2011
(1 + 0.5) * (Raster(r"layer_4") - Raster(r"1st step.img")) / (Raster(r"layer_4") + Raster(r"1st step.img") + 0.5)
Succeeded at Tue Aug 23 13:36:45 2011 (Elapsed Time: 1.00 seconds)


Please see the attached image of the expression I executed and my inputs. 

I hope this helps. 

Liz
0 Kudos