Select to view content in your preferred language

Append Events Python Field Mapping Parameters

1417
5
Jump to solution
04-22-2022 10:41 AM
Colin_Schut
Occasional Contributor

 

field_mapping = 'YEAR_ "YEAR_" true true false 2 Short 0 0 ,First,#,C:\NY_Data.gdb\AADT_Add,YEAR_,-1,-1;

 

 

I am attempting to use append events in python to append non-spatial data to a LRS event. The append events documentation lists out the parameters of the tools, but not what the parameters in the field mapping portion are since it's just one giant string. I have got it working but right now it's reliant on all the fields having the same properties for my unknown ones.

Does anyone know them all? The above is the example from the documentation.

Year_ = Target Field Name

"Year_" = Target Field Alias

true = null allowed?

true = null allowed?

false = required?

2 = Length

Short = Type

0  = Scale 

0 = Precision

First = Merge Rule

# = Delimiter? (how does this apply to the tool? )

NY_Data = Input dataset

Year_ = Input Field Name

-1 = start_position

-1 = end_position

(Also if anyone wants to critique my novice python code let me know!)

0 Kudos
1 Solution

Accepted Solutions
BJCovington
Emerging Contributor

What this part of the code refers to is the field mappings object, (https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/fieldmappings.htm) which is a collection of field maps (https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/fieldmap.htm) that create a field. 

The easiest method to script this would be to create a series of field maps, then add them to a field mappings object, then refer to the field mappings object in the script. 

This if fairly opaque, but if you conduct a regular append in ArcMap (I am assuming you are still in desktop since this is RHUG) you can follow along with the code in the field map window.

My best recommendation for any programmer - test on a copy of your data!

View solution in original post

0 Kudos
5 Replies
BJCovington
Emerging Contributor

What this part of the code refers to is the field mappings object, (https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/fieldmappings.htm) which is a collection of field maps (https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/fieldmap.htm) that create a field. 

The easiest method to script this would be to create a series of field maps, then add them to a field mappings object, then refer to the field mappings object in the script. 

This if fairly opaque, but if you conduct a regular append in ArcMap (I am assuming you are still in desktop since this is RHUG) you can follow along with the code in the field map window.

My best recommendation for any programmer - test on a copy of your data!

0 Kudos
Colin_Schut
Occasional Contributor

Yes, it's the opaqueness of the specific field maps that's the issue. I was just hoping someone knew before I spent time on adjusting database/tool parameters to narrow it down (as well as maybe have this as a reference on the web for anyone else with the same issue).

Maybe I'm missing something obvious, but I really can't think of what the -1's are. The true/true/false ones are easier to figure out. 

What I did in the script was list fields then create a formatted string list with the field properties, but right now it has those unknown values hardcoded in. 

0 Kudos
BJCovington
Emerging Contributor

The -1's come from the field map parameter that allows for a slice of data from your string field. It is the default positional argument for the start/end of the string.

BJCovington_0-1650929344986.png

 

Tags (1)
Colin_Schut
Occasional Contributor

Brilliant, thank you. 

CameronCole
Occasional Contributor

I personally don't know the properties and am a very novice coder so I get around this by running the Append Events Tool then copying the code snippet and making any adjustment necessary for the real append that I need to do. I take the tables people send me and append them into GDB temp tables tables but that allows me to get the data in the schema that I need it in and puts the data in a location where my code doesn't have to change. Then I the append events tool grabs the good data from the temp tables.  

Here is my process if this at all helps:

1. Create blank source table (table that will be appended).

2. Run append events (adjust the field mapping parameters in the tool manually)

3. Look at your results, copy as code snippet.

4. There you have the field mapping all done and proper the way the system wants it. 

0 Kudos