Hi @jlgvii
While it is definitely possible to set values based on conditions using a PythonCaller, a better method within FME would be to use conditional values within an AttributeManager or AttributeCreator. No Python required.
I would recommend taking a look at this article on conditional values if this is something you want to try:
https://knowledge.safe.com/articles/34109/determining-attribute-values-by-testing-with-condi.html
I entirely agree with @debbiatsafe, it's much easier doing this with regular transformers and a conditional value, especially if you have little or no prior experience with Python.
However, for reference, this is what the above might look like in Python:
import fme
def quadrant(feature):
NorthAzimuth = int(feature.getAttribute('NorthAzimu'))
if NorthAzimuth >= 0 and NorthAzimuth < 90:
quad = 'N' + str(NorthAzimuth) + 'E'
elif NorthAzimuth >= 90 and NorthAzimuth < 180:
quad = 'N' + str(180 - NorthAzimuth) + 'E'
elif ... # other criteria follows the same pattern
feature.setAttribute('Quadrant', quad)
This will output the attribute 'Quadrant' with the result based on the input attribute 'NorthAzimu'.
Hi @jlgvii
While it is definitely possible to set values based on conditions using a PythonCaller, a better method within FME would be to use conditional values within an AttributeManager or AttributeCreator. No Python required.
I would recommend taking a look at this article on conditional values if this is something you want to try:
https://knowledge.safe.com/articles/34109/determining-attribute-values-by-testing-with-condi.html
Thanks this worked perfectly and will help greatly in other work as well. Thanks so much.
I entirely agree with @debbiatsafe, it's much easier doing this with regular transformers and a conditional value, especially if you have little or no prior experience with Python.
However, for reference, this is what the above might look like in Python:
import fme
def quadrant(feature):
NorthAzimuth = int(feature.getAttribute('NorthAzimu'))
if NorthAzimuth >= 0 and NorthAzimuth < 90:
quad = 'N' + str(NorthAzimuth) + 'E'
elif NorthAzimuth >= 90 and NorthAzimuth < 180:
quad = 'N' + str(180 - NorthAzimuth) + 'E'
elif ... # other criteria follows the same pattern
feature.setAttribute('Quadrant', quad)
This will output the attribute 'Quadrant' with the result based on the input attribute 'NorthAzimu'.
I appreciate the response. As I had tried to get this to work for a decent amount of time. But conditional values did get me the results I was looking for.