Using the df.spatial.to_featureclass() causes the feature class to lose field name formatting

1272
6
Jump to solution
01-11-2021 09:37 AM
EricSamson1
New Contributor II

I have created a script tool that cleans up the input feature class using pandas, through utilizing the spatial dataframe functionality. I created it months ago, and it seemed to work fine then. Coming back to it now, however, I have noticed that when saving the output feature class using the .spatial.to_featureclass() function, the feature class field names go from capital letters to lower case letters, and adds underscores to certain fields not previously containing spaces.

Examples (original => output):

SimplifiedEXAMPLEStatus => simplified_example_status

GlobalID => global_id

VIdeo_Complete => v_ideo_complete

VideoRecord => video_record

Obviously, this creates a lot of problems when trying to work with the data further. It seems like the function doesn't like when random capital letters are thrown into a field name. I tried to recreate the problem in an ArcGIS notebook and experienced the same output problem, but before running the .spatial.to_featureclass() function, I examined the dataframe and found that the fields were in proper form. So the problem seems to be occurring during the export function. I couldn't find any details online about this problem so wanted to post here to see if others have experienced this.

 

0 Kudos
1 Solution

Accepted Solutions
MikeSlattery
Occasional Contributor

Looks like the GeoAccessor to_featureclass() call has a 'sanitize_columns' param that default to true.   Elsewhere it looks like the sanitize routine clobbers camelcase to create snake case.   Hopefully setting that param to False will work and be trouble free.

https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAcces...

View solution in original post

6 Replies
MikeSlattery
Occasional Contributor

Looks like the GeoAccessor to_featureclass() call has a 'sanitize_columns' param that default to true.   Elsewhere it looks like the sanitize routine clobbers camelcase to create snake case.   Hopefully setting that param to False will work and be trouble free.

https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAcces...

JohnHuillery1
Occasional Contributor

This must have been introduced in version 1.9.  Not sure why they thought modifying column names automatically was a good idea.

EricSamson1
New Contributor II

I agree, it doesn't make a lot of sense. If someone wanted their column names changed...wouldn't they just do that themselves? I can't see any positive for it

JimmyKnowles
Occasional Contributor II

Thanks for the solution on this, setting 'sanitize_columns' to 'False' worked for me.

Certainly doesn't make sense to me since it first modifies the dataframe and not just the feature class that is being written to. Took me a little while to figure out what was changing the case of my field names.

EricSamson1
New Contributor II

Wow, completely missed this. Mondays. Thanks Mike, really appreciate it.

0 Kudos
MichaelKnowles
New Contributor

Today was the first time I tried the .spatial.to_featureclass feature with the same results you had.  I tried the sanitze_columns=False option but get the same results, i.e., lower case columns with underscores inserted occasionally. 

Based on the code below am I missing something -- no errors returned? Or something else to try?

df_fc.spatial.to_featureclass(out_fc, overwrite=True, sanitize_columns=False)

0 Kudos