Append - FieldMapping

2640
5
07-20-2016 11:57 AM
DaveOrlando
Occasional Contributor III

Hello,

I'm getting some odd results from my FieldMappings and am wondering if it can be explained.

Using Append, I'm combining five FCs into one existing FC using Delete Feature and Append. All FCs are in a different geographic area so there are no features overlapping.

The Target FC contains a field Asset_ID. All five sources also have Asset_ID, but I don't want to use one of them, instead I'm trying to map to eg. SomeOtherID for one of the sources The Append still seems to be trying to use the Asset_ID field for all sources.

I've noticed that if a Asset_ID value is NULL, it then reverts to the SomeOtherID. That made me think about the Merge rule, so I switched to Last, and it worked fine. so.... is the merge rule referring to the order of fields in my source tables?.. This is not what I thought the rule was for, why would it even still consider the Asset_ID when I've told it to go to another field?

It feels like it takes either the target field and looks for it in all the sources by default, or maybe it takes each of the mappings and tries to look for them in all the sources?....

if anyone has some time to test a scenario like this it would be greatly appreciated.

10.2 and 10.4

Thanks,

Dave

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

I am wondering why you have chosen to Append to an existing rather than Merge all to a new file

Merge—Help | ArcGIS for Desktop

I am wondering if this would facilitate better control over the field mapping

Using the field mapping control—Help | ArcGIS for Desktop

0 Kudos
DaveOrlando
Occasional Contributor III

Hi Dan,

I am appending into an edit version of our production schema.

Python and Toolbox both produce the same results. In a final Python script I create proper field map objects, but when I see odd results I test the pants off of Toolbox.

I have worked around the issue by delete all fields in my sources that have the same name as a target field, if I'm trying to avoid that field in the source.

This is all after the fact and looking for an explanation of field mapping 'under the hood'. I would like to report a bug, but would like some more opinions.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Dave...

I haven't had the need to control field mapping since I rarely use data from other sources, hence removing the problem you seem to be encountering.  This is why I thought starting from scratch with a merge would enable better control.  I come from a background were tabular data are constructed from inputs according to predetermined rules (data type, permitted classes etc) rather than trying to fit data into an existing structure, so my suggestion probably won't be of any use to your workflow.  Good luck

0 Kudos
andrewj_ca
Occasional Contributor II

Hey Dave,

Can you post a snippet of your code?  I have some ideas for you.  Just want to confirm what your code looks like.

Cheers

0 Kudos
DaveOrlando
Occasional Contributor III
    # Process: Delete Features (6)
    arcpy.DeleteFeatures_management(QA_WaterLines)
    # create FieldMap objects
    #
    # !! bug found: if the target field exists in the source table (ie Asset_ID), but you want to map away from it (ie SomeNewID),
    # !! it must be deleted from the source, if not it will override these mappings
    #
    # field map Jur_Flag
    fldName = arcpy.Field()
    fldName.name = 'Jur_Flag'
    fldName.aliasName = 'Jur_Flag'
    fldName.type = 'Text'
    fldName.length = 3
    fmJur = arcpy.FieldMap()
    fmJur.outputField = fldName
    fmJur.addInputField(ENG_WaterLine_tmp, 'Jur_Flag')
    fmJur.addInputField(DWK_WaterLine_tmp, 'Jur_Flag')
    fmJur.addInputField(DLC_WATR_PIPES_tmp, 'Jur_Flag')
    fmJur.addInputField(PCH_WaterLines_tmp, 'Jur_Flag')
    fmJur.addInputField(WFN_WaterLines_tmp, 'Jur_Flag')
    #
    # field map WaterLineType
    fldName = arcpy.Field()
    fldName.name = 'WaterLineType'
    fldName.aliasName = 'WaterLineType'
    fldName.type = 'Text'
    fldName.length = 20
    fmType = arcpy.FieldMap()
    fmType.outputField = fldName
    fmType.addInputField(ENG_WaterLine_tmp, 'WaterLineType')
    fmType.addInputField(DWK_WaterLine_tmp, 'WaterLineType')
    fmType.addInputField(DLC_WATR_PIPES_tmp, 'WaterLineType')
    fmType.addInputField(PCH_WaterLines_tmp, 'WaterLineType')
    fmType.addInputField(WFN_WaterLines_tmp, 'Type')
    #
    # field map Path
    fldName = arcpy.Field()
    fldName.name = 'Path'
    fldName.aliasName = 'Path'
    fldName.type = 'Text'
    fldName.length = 255
    fmPath = arcpy.FieldMap()
    fmPath.outputField = fldName
    fmPath.addInputField(DWK_WaterLine_tmp, 'Path')
    #
    # field map Asset_ID
    fldName = arcpy.Field()
    fldName.name = 'Asset_ID'
    fldName.aliasName = 'Asset_ID'
    fldName.type = 'Text'
    fldName.length = 20
    fmAsset_ID = arcpy.FieldMap()
    fmAsset_ID.outputField = fldName
    fmAsset_ID.addInputField(ENG_WaterLine_tmp, 'Asset_ID')
    fmAsset_ID.addInputField(DLC_WATR_PIPES_tmp, 'Asset_ID')
    fmAsset_ID.addInputField(PCH_WaterLines_tmp, 'Asset_ID')
    fmAsset_ID.addInputField(WFN_WaterLines_tmp, 'AssetID')
    #
    # field map RDCO_LinkID
    fldName = arcpy.Field()
    fldName.name = 'RDCO_LinkID'
    fldName.aliasName = 'RDCO_LinkID'
    fldName.type = 'Text'
    fldName.length = 50
    fmRDCO_LinkID = arcpy.FieldMap()
    fmRDCO_LinkID.outputField = fldName
    fmRDCO_LinkID.addInputField(ENG_WaterLine_tmp, 'RDCO_LinkID')
    fmRDCO_LinkID.addInputField(DLC_WATR_PIPES_tmp, 'RDCO_LinkID')
    fmRDCO_LinkID.addInputField(PCH_WaterLines_tmp, 'RDCO_LinkID')
    fmRDCO_LinkID.addInputField(WFN_WaterLines_tmp, 'RDCO_LinkID')
    # add field map to field mappings
    fms = arcpy.FieldMappings()
    fms.addFieldMap(fmJur)
    fms.addFieldMap(fmType)
    fms.addFieldMap(fmAsset_ID)
    fms.addFieldMap(fmRDCO_LinkID)
    fms.addFieldMap(fmPath)
    # Process: Append (6)
    arcpy.Append_management(Append_inputs, QA_WaterLines, "NO_TEST", fms)

so, for example, in the second field map, the last input I wanted to go away from 'WaterLineType' but had to delete that field to force it go to 'Type'

Thanks

0 Kudos