1

I am trying to append multiple feature classes to a new one. As they come from different sources, the fields are all different, so I have to map the fields of the input feature classes to the fields of the output feature class.

I've first set up a table which looks like this:enter image description here

The table contains 1 record for every field in the input feature classes which needs to be mapped to an output field. My script iterates through the table and makes a Tablerecord object for every record in the table. These are stored in a dictionary table_records with a lookup ID:

{1: <__main__.Tablerecord instance at 0x0DF5BB70>, 
 2: <__main__.Tablerecord instance at 0x0DF600D0>, ... }

Every Tablerecord has attributes id, path, field, targetfc, targetfield

Then for every output feature class mentioned, it makes a key in a dictionary output_fcs with lookup value a row of IDs: {'fence': [1, 2, 3,...]}

Then, the script should make 1 FieldMappings object for every output feature class, which contains a FieldMap object for every output field, each of which contains a reference to the associated input fields from the input feature classes.

Problem is, when I run this from PyCharm (though for Pyscripter and IDLE it's the same), it causes Python to crash ("python.exe has encountered a problem and needs to close. please tell microsoft about this problem" and all that). What is going on here, what is the fault in my script that does not just generate an error but crashes the interpreter?

Script:

for output_fc in output_fcs.keys():
    fc_list = []
    fms = arcpy.FieldMappings()
    fms.addTable(os.path.join(gdb_path, output_fc))
    id_list = output_fcs[output_fc]
    for record_id in id_list:
        record = table_records[record_id]
        if not (record.split or record.merge_field or record.merge_fc):
            i = fms.findFieldMapIndex(record.targetfield)
            if i == -1:
                fm = arcpy.FieldMap()
                fm.outputField = record.targetfield
                fm.addInputField(record.path, record.field)
                fms.addFieldMap(fm)
            else:
                fm = fms.getFieldMap(i)
                fm.addInputField(record.path, record.field)
                fms.replaceFieldMap(i, fm)

closed as off-topic by PolyGeo Aug 27 '16 at 1:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Would you be able to edit your IDE into your question, please? – PolyGeo Oct 23 '14 at 10:38
  • 1
    Where does the script crash? Could you add print messages to locate the exact line? Does it also crash if you remove the spaces in your field names in the Excel sheet? – GISGe Oct 23 '14 at 14:09
  • The excel headers are skipped so that can't be a problem. Tried it with removing spaces anyway but still crashes. Script crashes at the first time it reaches fm.outputField = record.targetfield – Menno Oct 24 '14 at 8:20
  • At the moment you are presenting a function rather than a code snippet that works up to where you are stuck. Can you refactor this into an mcve that still reproduces your problem so that we can more easily read and attempt to test it, please? – PolyGeo Aug 27 '16 at 1:55