0

I'm building an ArcMap script tool that will be run on many different input table schemas for geocoding purposes. When importing from CSV to GDB table using the arcpy.conversion.TableToTable function I have several string fields that look like numbers (ID, Zip) that are getting automatically converted to long integers and dropping their leading zeros. I need to preserve these values and leading zeros as strings for joining later. There will not be any actual numeric fields in the input tables that need to be preserved as such.

Is there a way to specify that all fields from any input table will be string type in the output table?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • 2
    Check out my answer (search for "schema.ini") in the question at: https://gis.stackexchange.com/questions/45050/preparing-csv-files-for-use-in-arcgis-desktop (NB: not the accepted answer) – Son of a Beach Feb 19 '24 at 02:42
  • That seems promising thank you, I'll look into it. The concern is that this tool will be shared with different people with varying skillsets so the process needs to be completely automated if at all possible. Ideally I want them to be able to simply navigate to a directory and choose a CSV table and let the tool do all the work. – Paul DiGirolamo Feb 19 '24 at 02:52
  • 2
    I wonder if I could use arcpy to list the fields in any given input table then automate a process to write a schema.ini file using those fieldnames with type always set to text? – Paul DiGirolamo Feb 19 '24 at 02:59
  • Yes, I was about to suggest that. In theory, the tool could write the schema.ini before loading up the CSV. In fact, I used to have a tool that copied a standard schema.ini file to the location of the data that I needed to import, then edited the copied schema.ini (just to change the name of the .csv file) before doing the import. – Son of a Beach Feb 19 '24 at 02:59
  • OK great I will pursue that approach and see what I can figure out. Thanks! – Paul DiGirolamo Feb 19 '24 at 03:01
  • I manually edited a schema.ini file for my test table and that worked great, preserved the field types on import. Now I just need to figure out how to automate that process using the list function and then save that list plus some header and other text to a text file in the source directory! – Paul DiGirolamo Feb 19 '24 at 17:37
  • Good to hear. If you get stuck... just post a new question. :-) – Son of a Beach Feb 19 '24 at 20:52
  • Thanks for your help! I made alot of progress but still not quite there, new question is here: https://gis.stackexchange.com/questions/476316/schema-ini-file-not-being-honored-by-arcmap-string-fields-still-being-converted – Paul DiGirolamo Feb 19 '24 at 21:47

0 Answers0