Created
January 6, 2018 04:50
-
-
Save tonjadwyer/fa505cf08cb3f8a4093b1e1450e816d9 to your computer and use it in GitHub Desktop.
Build an ArcPy FieldMappings object from source and target feature classes using field map tuples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# fm_input is a field mapping tuple | |
# fm_input = (("target1","source1"),("target2","source2"),("target3","source3")) | |
def build_field_map(target, source, fm_input): | |
field_mapps = arcpy.FieldMappings() | |
field_mapps.addTable(target) | |
for fm_item in fm_input: | |
try: | |
target_field, source_field = fm_item | |
print_msg("target field: " + target_field + " source field: " + source_field) | |
index = field_mapps.findFieldMapIndex(target_field) | |
fmap = field_mapps.getFieldMap(index) | |
fmap.removeAll() | |
fmap.addInputField(source,source_field) | |
field_mapps.replaceFieldMap(index,fmap) | |
except Exception as e: | |
if len(e.args) > 0: | |
print_msg(e.args[0]) | |
else: | |
print_msg("Error, exiting") | |
exit | |
return field_mapps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment