how rename feature attribute with python
how rename feature attribute with python
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
ERROR:
Python Exception <IndentationError>: expected an indented block (<string>, line 10)
Error executing string `import<space>fme<lf>import<space>fmeobjects<lf>#<space>Template<space>Function<space>interface:<lf>#<space>When<space>using<space>this<space>function<comma><space>make<space>sure<space>its<space>name<space>is<space>set<space>as<space>the<space>value<space>of<lf>#<space>the<space><apos>Class<space>or<space>Function<space>to<space>Process<space>Features<apos><space>transformer<space>parameter<space><lf>def<space>processFeature<openparen>feature<closeparen>:<lf><space><space><space><space>a=feature.getAttributeNullMissingAndType<openparen><apos>BZ<apos><closeparen><lf><space><space><space><space>if<space>a<openbracket>1<closebracket>==true:<lf><space><space><space><space>feature.performFunction<openparen><apos><at>RenameAttributes<openparen><apos>KD<apos><comma><apos>BZ<apos><closeparen><apos><closeparen><lf>#<space><space><space><space><space><space><space><space>v<space>=<space>feature.getAttribute<openparen><apos>BZ<apos><closeparen><lf>#<space><space><space><space><space><space><space><space>feature.setAttribute<openparen><apos><u5907><u6ce8><apos><comma><space>v<closeparen><lf>#<space><space><space><space><space><space><space><space>feature.removeAttribute<openparen><apos>BZ<apos><closeparen><lf><space><space><space><space><space><space><space>#<space>feature.setAttribute<openparen><apos><u5907><u6ce8><apos><comma>feature.getAttribute<openparen>feature.getAttribute<openparen><apos>BZ<apos><closeparen><closeparen><closeparen><space><lf><space><space><space><lf><lf>'
Factory proxy not initialized
PythonCaller (PythonFactory): PythonFactory failed to process feature
A fatal error has occurred. Check the logfile above for details
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
why I Can't execute successfully
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
firstly check if you have set the Class or Function to Process Features parameter appropriately.
firstly check if you have set the Class or Function to Process Features parameter appropriately.
First time use PythonCaller, can you provide some detailed operations?thanks
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
Then, correct indentations.
Then, correct indentations.
https://docs.safe.com/fme/html/FME_FactFunc/index.html function usage depend performFunction ?
Then, correct indentations.
No, the @RenameAttributes function is an FME function (not Python), and the document you link describes FME functions.
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
There are excellent tutorials on Python and FME basics, I'd recommend you to start learning from here.
https://knowledge.safe.com/articles/706/python-and-fme-basics.html
https://knowledge.safe.com/articles/60319/pythoncaller-transformer.html
Hi @charry, there are at least two ways.
1. Create new attribute, remove old attribute.
def renameExample(feature):
v = feature.getAttribute('oldName')
feature.setAttribute('newName', v)
feature.removeAttribute('oldName')
2. Rename attribute using the FME function @RenameAttributes
def renameExample2(feature):
feature.performFunction('@RenameAttributes(newName,oldName)')
See here to learn more about FME Functions: FME Factory and Function Documentation
Alternatively you can use the AttributeManager transformer or the AttributeRenamer transformer, if you just need to rename attributes.
Of course it's good to learn Python, but it would take time.