Select to view content in your preferred language

Copy Features removing majority of field name

666
4
Jump to solution
04-19-2024 10:20 AM
CodyPatterson
MVP Regular Contributor

Hey All,

I'm sure I'm doing something very obvious that I'm missing, when using arcpy and the CopyFeatures tool, I'm running into an issue where it removes everything in a field name after an underscore. Here are some screenshots:

Before:

CodyPatterson_0-1713546981127.png

After:

CodyPatterson_1-1713547145905.png

I saw in the Copy Features geoprocessing tool I can enable "Maintain fully qualified field names" but I see no way to do this in Python, is there a way?

arcpy.management.CopyFeatures(NID_Layer, output_fc)

Thanks in advance!

Cody

0 Kudos
1 Solution

Accepted Solutions
CodyPatterson
MVP Regular Contributor

Hey @AlfredBaldenweck 

I was able to find a way around it, I had to use the append tool along with a new source on the actual output of structure_name that I wanted to use, I've attached a screenshot of what I did. I converted the actual geoprocessing tool to Python using the drop down next to run and then input my variables and everything worked! (This was after the Copy Features, as structure is cut down)

CodyPatterson_0-1713783672939.png

Cody

View solution in original post

4 Replies
AlfredBaldenweck
MVP Regular Contributor

If the output is a Shapefile, they can only have field names 10 characters long, max. Anything longer gets cut off.

Use a geopackage or mobile geodatabase instead if you need to easily share the data and maintain the field names.

CodyPatterson
MVP Regular Contributor

Hey @AlfredBaldenweck 

Oddly enough, it immediately converts the feature layer into a shapefile after this copy occurs, the main reason for this is to eventually stack the information into a feature class, but since the field names are different, it doesn't allow that to happen. Would you know of a way to to map this structure_ field to structure_name when using the append tool? Any type of change I've made has just placed "Null"

field_mappings = arcpy.FieldMappings()

field_map_ipid = arcpy.FieldMap()
field_map_clli = arcpy.FieldMap()

field_ipid = arcpy.Field()
field_ipid.name = "ipid"
field_clli = arcpy.Field()
field_clli.name = "structure_"

field_map_ipid.addInputField(output_fc, "ipid")
field_map_clli.addInputField(output_fc, "structure_")

field_mappings.addFieldMap(field_map_ipid)
field_mappings.addFieldMap(field_map_clli)

This is my attempt so far

0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @AlfredBaldenweck 

I was able to find a way around it, I had to use the append tool along with a new source on the actual output of structure_name that I wanted to use, I've attached a screenshot of what I did. I converted the actual geoprocessing tool to Python using the drop down next to run and then input my variables and everything worked! (This was after the Copy Features, as structure is cut down)

CodyPatterson_0-1713783672939.png

Cody

AlfredBaldenweck
MVP Regular Contributor

Nice work!

0 Kudos