TransWikia.com

Cannot assign output field name to FieldMap

Geographic Information Systems Asked by mwolfe on December 26, 2020

In attempting to map input fields to output fields, I am finding that I cannot correctly assign the output field name. Running the script produces no errors, but for a given FieldMap object, the outputField property is assigned the name of the input field. I have mapped fields many times (though never with these specific tables) and never before encountered this problem.

Here is the code:

field_map = arcpy.FieldMappings()  
field_map.addTable(in_select)  
fm = arcpy.FieldMap()  
fm.addInputField(in_select, "CHANGE_STA")  
REPORT_STATUS = fm.outputField  
fm.outputField = REPORT_STATUS  
REPORT_STATUS.name = "REPORT_STATUS"  
REPORT_STATUS.type = "TEXT"  
field_map.addFieldMap(fm)

When I then call fm.outputField.name, it returns the input field name 'CHANGE_STA' (and the append I run with this field map shows that it has not mapped the fields correctly)

Any ideas? What incredibly obvious thing am I missing? (Input table is a dbf table. Is this a problem with the table type?)

One Answer

It seems that the solution is straightforward, if not obvious. By swapping the code lines so that fm.outputField is defined after defining the field name attribute:

field_map = arcpy.FieldMappings()  
field_map.addTable(in_select)  
fm = arcpy.FieldMap()  
fm.addInputField(in_select, "CHANGE_STA")  
REPORT_STATUS = fm.outputField  
REPORT_STATUS.name = "REPORT_STATUS"  
REPORT_STATUS.type = "TEXT"
fm.outputField = REPORT_STATUS  
field_map.addFieldMap(fm)

The code functions as intended. Why, I am unsure, since I have used the code in the first iteration many times without problem.

Answered by mwolfe on December 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP