0

I've joined a point FC (InputPointCopy) with a polyline FC (Polyline) and now I'd like to append the Polyline FC att table to an empty FC of the same geometry.

I ran across a custom function at Using field mapping with ArcPy that uses a dictionary to create a field map object (key = source field name, value = target field name), but I'm not sure how to call on it within arcpy.management.Append().

How can I go about this, even if it doesn't include using the custom function?

polyline_fc = "Polyline" # the polyline FC in the TOC
# create dictionary
mappingDict = {
 # source field name (Polyline) : target field name (Translated_FiberCable)
 "InputPointCopy.FIBER_CABLE_TYPE": "FIBER_CABLE_TYPE",
 "InputPointCopy.FIBER_CABLE_NAME": "FIBER_CABLE_NAME",
 "InputPointCopy.ROUTE": "ROUTE",
 "InputPointCopy.PLACEMENT_TYPE" : "PLACEMENT_TYPE",
 "InputPointCopy.CABLE_SEQUENTIAL_LENGTH" : "CABLE_SEQUENTIAL_LENGTH",
 "InputPointCopy.CABLE_COUNT" : "CABLE_COUNT",
 "InputPointCopy.BUFFER" : "BUFFER",
 "InputPointCopy.FIBER_QTY" : "FIBER_QTY",
 "InputPointCopy.APPROVED_IND" : "APPROVED_IND",
 "InputPointCopy.BUILD_STATUS" : "BUILD_STATUS",
 "InputPointCopy.INSTALLATION_YEAR" : "INSTALLATION_YEAR",
 "InputPointCopy.TDS_WBS_CODE" : "TDS_WBS_CODE",
 "InputPointCopy.COMMENTS" : "COMMENTS",
 "InputPointCopy.MARKET_CODE" : "MARKET_CODE"
}
# run custom script to make FM object from dictionary
def fmapForDict(polyline_fc, mappingDict):
 fieldMappings = arcpy.FieldMappings()
 for sourceField in mappingDict:
 fMap = arcpy.FieldMap()
 fMap.addInputField(polyline_fc, sourceField)
 outField = fMap.outputField
 outField.name = mappingDict[sourceField]
 fMap.outputField = outField
 fieldMappings.addFieldMap(fMap)
 return fieldMappings
fm_object = fmapForDict(polyline_fc, mappingDict)
# append selected features to "Translated_FiberCables" FC
arcpy.management.Append(polyline_fc, out_name, "NO_TEST",fm_object)
asked May 19, 2023 at 19:07
1
  • You say that "I'm not sure how to call on it within arcpy.management.Append()" and yet you have done exactly that in your script with, fm_object = fmapForDict(polyline_fc, mappingDict) and then arcpy.management.Append(polyline_fc, out_name, "NO_TEST", fm_object). Is this not working? If not, what is going wrong? (Edit/update your question with any additional information.) Commented May 30, 2023 at 2:05

1 Answer 1

1

It looks like you are using the same field names for both source and target feature classes. In this case, the Append function will take care of field mapping automatically and you can just leave out the field map parameter altogether. You may need to include "NO_TEST" for the schema_type parameter if there are other fields that are different between the two feature classes (I usually include "NO_TEST" as a matter of habit to be on the safe side, but it depends on your needs).

Because of your join, your fields may not automatically match up, due to the "InputPointCopy." being prefixed to the field names. In this case, copy the feature layer to an intermediate feature class first without the field name prefixes. Eg:

arcpy.env.qualifiedFieldNames = False
arcpy.ExportFeatures_conversion(source, source_exported)

This should result in field names without the prefix, and then you can simply use the Append function and the field mapping should happen automatically (because the source and target field names have exactly the same names. Eg:

arcpy.Append_management(source_exported, target, "NO_TEST")
answered May 30, 2023 at 1:48
3
  • Take advantage of the memory workspace so you do not need to write the intermediate data to disk. arcpy.ExportFeatures_conversion(source, "memory\\temp_fc") Commented May 31, 2023 at 7:22
  • I tried this and now all the fields from the "InputPointCopy" FC have an "_1" tagged on at the end... which still makes them different from the "Polyline" field names, therefore the append won't be pretty. Thanks for the in depth response though. Essentially I want to take attribute values from the "Point" FC and get them into the "Polyline" FC so that when I append the features from the "Polyline" FC, those attribute values transfer over in the append using the "NO_TEST" parameter. Any thoughts? Commented Jun 8, 2023 at 19:41
  • There is usually a reason for the "_1" at the end of field names. And changing field names is very easy. Figure out what the reason is first, to see if it can be prevented (most likely those fields already exist, so a "_1" is being added to avoid a naming confict - see if that can be avoided). If it cannot be avoided, then you can rename all the fields as required, to remove the "_1". If that would cause a conflict, then you may need to rename the other fields first. Commented Jun 14, 2023 at 3:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.