Hi all,
Background: I'm currently working in ArcGIS Pro 2.1.0 using a toolbox with a script attached. The goal of the script is to send a pandas data frame representation of a shapefile's (possibly a geodatabase in the future) table out to a server that does some manipulation on the rows and sometimes adding new fields, then read this updated table back into ArcGIS Pro with the script in the toolbox and update the visible map.
Issue: So far I've been easily able to send the data out and read it back in, but I have trouble when updating the shapefile's current table. My initial idea was to:
- Create a new table based off the updated data from the server (using numpy array to table)
- Copy the current table of the shapefile (using table to table conversion)
- Compare the fields in the updated table to the copied current table's and add fields to table copy accordingly (add field management)
- Create a dictionary of the updated table
- Use an update cursor to update the copied current using a key to access values in the updated table's dictionary
- Since overwrite is enabled (arcpy.env.overwriteOutput = True), use table to table conversion to now update the actual current table of the shape file
At the last, actually overwriting the table, I always run into an issue. With the steps outline above, I usually run into an issue where the actual shapefile is deleted leaving just the dbf and related files, and removing the associated layer from the map. I instead tried to use an update cursor and ran into an issue with locks on files. And when trying to delete the actual dbf file and create it anew, delete management ran into this same lock file issue.
I'm struggling to find anything online that's helping with my issue and I wanted to know, am I approaching updating a table based on new data the right way?
I will attach code snippets clearly displaying which method was used to update the table. My biggest suspicion is that, at least for method two, add fields management is creating a lock file on the table and not removing it when finished adding the fields. This then interferes with the cursor creation when updating the original table later.