1

I'm trying to limit the number of fields when I perform a merge to two. Below is the script I have created to do so. However, the merged feature class carries over all fields, despite my use of a fieldmappings object.

di is a dictionary with a shape type ("polyline", "polygon", etc) as its key, and a python list of feature classes as its value. Any ideas?

relevant code:

fms = FieldMappings()
jnFm = FieldMap()
sourceFm = FieldMap()
jnFm.addInputField(fc, jobField)
sourceFm.addInputField(outFcFullPath, "FC_SOURCE")
fms.addFieldMap (jnFm)
fms.addFieldMap (sourceFm)

print "\nMerging"
for shapeType in di:
    featureClasses = di[shapeType]
    mergeFC = os.path.join (outGDB, "All_" + shapeType)
    Merge_management (featureClasses, mergeFC, fms)
    print "Created: All_" + shapeType
1

I have figured out that for each feature class I'm merging, I need to add the fields to the field map objects.

Functioning code:

fms = FieldMappings()
jnFm = FieldMap()
sourceFm = FieldMap()
jnFm.addInputField(fc, jobField)
jnFm.addInputField(outFcFullPath, jobField) #New code
sourceFm.addInputField(fc, "FC_SOURCE") #New code
sourceFm.addInputField(outFcFullPath, "FC_SOURCE")
fms.addFieldMap (jnFm)
fms.addFieldMap (sourceFm)

print "\nMerging"
for shapeType in di:
    featureClasses = di[shapeType]
    mergeFC = os.path.join (outGDB, "All_" + shapeType)
    Merge_management (featureClasses, mergeFC, fms)
    print "Created: All_" + shapeType

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.