Skip to main content
Solved

Expression evaluator / Attribute Creator

  • February 17, 2015
  • 6 replies
  • 42 views

Forum|alt.badge.img
Hi All, 

 

 

I have output some shapefiles with counts from an amalgamation of some points and some polygons.

 

For example: I have produced a shapefile with the number of house fires in each county for all the UK.

 

All is good.

 

 

But what I want to do is now, is produce a rate, based on population in each county.

 

So for example: I want the rate of House Fires (HF) per county per 1000 population.

 

 

Rate = (HF / Population) * 1000

 

 

Both Expression evaluator and Attribute Creator are producing 0(zeros), this is frustrating.

 

 

Please help?

 

 

 

 

Best answer by takashi

Hi,

 

 

Probably both HF and Population values don't have decimal places.

 

The / operator returns integer when both operands are integer.

 

e.g. "1 / 2" returns "0", it doesn't return "0.5".

 

 

Even though the data type is shown as "64 bit real" in Data Inspector, it will be interpreted as integer when the expression is evaluated, if it doesn't have decimal places.

 

 

To avoid the "integer division trap", try adding decimal places to at least one operand of the / operator.

 

e.g.

 

Rate = 1000.0 * HF / Population

 

Rate = @double(HF) / Population * 1000

 

Rate = (HF + 0.0) / Population * 1000

 

and so on.

 

 

It's the spec of the / operator in FME 2014 or earlier.

 

But be aware that the spec has been changed in FME 2015.

 

In FME 2015, "1 / 2" returns "0.5".

 

 

Takashi
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

Forum|alt.badge.img
  • Author
  • February 17, 2015
Oh by the way, I have added an inspector to the data just before trying Expression evaluator or Attribute Creator and both the HF and Population attribute information are showing as (64 bit real). The output values are also set as numbers.

Forum|alt.badge.img
  • Author
  • February 17, 2015
I am using FME DEsktop 2014 SP3 

Forum|alt.badge.img
  • Author
  • February 17, 2015
I have tracked it down.I think I may have hit a bug in FME.

 

I tried the following caluculations where

 

HF = 1 and Population = 1000

 

HF + Population = 1001

 

HF * Population = 1000

 

HF / Population = 0 , this should be 0.001.

 

 

Forum|alt.badge.img+1
  • February 17, 2015
Si,

 

In your calculation try *1000.000 (for example) as opposed to 1000 OR somewhere in your calculation put in *1.000

 

This should then make FME reveal the decimal places you require

 

...............

 

Hope this helps

 

Howard L'

takashi
Influencer
  • Best Answer
  • February 17, 2015
Hi,

 

 

Probably both HF and Population values don't have decimal places.

 

The / operator returns integer when both operands are integer.

 

e.g. "1 / 2" returns "0", it doesn't return "0.5".

 

 

Even though the data type is shown as "64 bit real" in Data Inspector, it will be interpreted as integer when the expression is evaluated, if it doesn't have decimal places.

 

 

To avoid the "integer division trap", try adding decimal places to at least one operand of the / operator.

 

e.g.

 

Rate = 1000.0 * HF / Population

 

Rate = @double(HF) / Population * 1000

 

Rate = (HF + 0.0) / Population * 1000

 

and so on.

 

 

It's the spec of the / operator in FME 2014 or earlier.

 

But be aware that the spec has been changed in FME 2015.

 

In FME 2015, "1 / 2" returns "0.5".

 

 

Takashi

Forum|alt.badge.img
  • Author
  • February 17, 2015
Thanks for the response.

 

Used Rate = (HF + 0.0) / Population * 1000 as a work around.

 

 

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings