Like many others, I have become frustrated with the amount of time it takes to use the "Add Join" tool and "Calculate field" tool to get values from one table into another while working with Python and ArcMap in general. To increase the performance, I started playing around with dictionaries and saw that many other people have done this as well to create a dictionary to use with an update cursor. By using this method, I do not have to do the "join and calculate" method to copy records from one table into another. The dictionary method is a very efficient way to update records (since update cursors cannot work with joined tables) and performs this operation about 100x times faster.
I decided to write a couple functions that will use the dictionary and update cursor method to update tables since it is a LOT faster. I wrote one function that will create a dictionary and update one field in an attribute table based on a dictionary created from another table somewhere else on disk. This works for updating only one field (AttributeUpdate).
Next I created another function that will accept a list of fields to update in the source table, and a list of value fields from another table (join table) that will be used to update the fields in the source table. It creates a new dictionary for each join table field and updates all input fields in the source table. The only catch with this is there has to be the same amount of update fields and value fields from both tables (MultipleAttributeUpdate).
Anyways, these two functions work great and I am attaching the script that contains them to this post in case anyone is interested. Also attached is the tool help documentation I hastily put together. They have already saved me a ton of time. If anyone wants an idea of how fast the new tools work, I have a script where I add 4 fields to a table and do a temporary join of that table with another and do 4 separate field calculations on a table to copy those records with about 20,000 records (the process that used to take about 8 minutes). The process has now been reduced to only 33 seconds with these new tools I created! Quite a performance enhancement! They are attached to this email if anyone is interested.
One more note, there are two versions, one for Arc 10.0 and one for 10.1. The only difference is that the 10.1 version uses the da cursors and is faster than the 10.0 version for that reason. Enjoy!
I have re-posted this since I put some of the wrong files in the folders on the previous post.
I decided to write a couple functions that will use the dictionary and update cursor method to update tables since it is a LOT faster. I wrote one function that will create a dictionary and update one field in an attribute table based on a dictionary created from another table somewhere else on disk. This works for updating only one field (AttributeUpdate).
Next I created another function that will accept a list of fields to update in the source table, and a list of value fields from another table (join table) that will be used to update the fields in the source table. It creates a new dictionary for each join table field and updates all input fields in the source table. The only catch with this is there has to be the same amount of update fields and value fields from both tables (MultipleAttributeUpdate).
Anyways, these two functions work great and I am attaching the script that contains them to this post in case anyone is interested. Also attached is the tool help documentation I hastily put together. They have already saved me a ton of time. If anyone wants an idea of how fast the new tools work, I have a script where I add 4 fields to a table and do a temporary join of that table with another and do 4 separate field calculations on a table to copy those records with about 20,000 records (the process that used to take about 8 minutes). The process has now been reduced to only 33 seconds with these new tools I created! Quite a performance enhancement! They are attached to this email if anyone is interested.
One more note, there are two versions, one for Arc 10.0 and one for 10.1. The only difference is that the 10.1 version uses the da cursors and is faster than the 10.0 version for that reason. Enjoy!
I have re-posted this since I put some of the wrong files in the folders on the previous post.