Skip to main content
Solved

(Private Parameter) Python script does not return the right value


Hello everybody,

in my workbench the scale of an output raster type feature should depend on an attribute RADIUS, which is defined as a numeric published parameter the user can manipulate. I realized that with a private parameter which is defined through a python script as you see below. I set the default value of the RADIUS attribute to '500' so the scale should be '4000'... But the script returns the value '15000'. I also tried to return just the value of the RADIUS itself in this script to test if the RADIUS value is still setted to 500 when the python script is running and it is! And the RADIUS attribute is definitely numeric. It has the type 'Number'. What could be the problem? I don't really know what to do.

Best regards,

Felix

scale=0

if (FME_MacroValues['RADIUS'] <= 500):
    scale=4000
elif (500 < FME_MacroValues['RADIUS'] <= 1000):
    scale=8000
else:
    scale=15000

return scale

Best answer by larry

You have to cast your FME_MacroValues to a number like in:

float(FME_MacroValues['RADIUS']) <= 500

View original
Did this help you find an answer to your question?

4 replies

Forum|alt.badge.img
  • Best Answer
  • June 20, 2017

You have to cast your FME_MacroValues to a number like in:

float(FME_MacroValues['RADIUS']) <= 500


geosander
Forum|alt.badge.img+7
  • June 20, 2017

Hi @felixderglueckl,

It might sound strange, but macro values (parameters) are always returned as a string.

 

The type you specify when you set up the parameter can't always be directly translated into a Python type. It mainly serves as a way to narrow down (and check) the user input.

So for your code to work, you'd have to cast the FME_MacroValues['RADIUS'] to an integer (or float). Use int(FME_MacroValues['RADIUS']) or float(FME_MacroValues['RADIUS']) to do this and be aware that these functions will not work on a missing value (NoneType), so you might also want to check for that first, just in case.

[edit]I am too slow... but my answer is a bit more complete...[/edit]


Forum|alt.badge.img
  • June 20, 2017
geosander wrote:

Hi @felixderglueckl,

It might sound strange, but macro values (parameters) are always returned as a string.

 

The type you specify when you set up the parameter can't always be directly translated into a Python type. It mainly serves as a way to narrow down (and check) the user input.

So for your code to work, you'd have to cast the FME_MacroValues['RADIUS'] to an integer (or float). Use int(FME_MacroValues['RADIUS']) or float(FME_MacroValues['RADIUS']) to do this and be aware that these functions will not work on a missing value (NoneType), so you might also want to check for that first, just in case.

[edit]I am too slow... but my answer is a bit more complete...[/edit]

I'm faster but I up voted your answer :)

 

 


geosander
Forum|alt.badge.img+7
  • June 20, 2017
larry wrote:
I'm faster but I up voted your answer :)

 

 

Ah, a true gentleman! ;)

Reply


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