How to use Python dictionaries and update cursor instead of ArcGIS Joins?

11507
11
10-05-2012 09:23 AM
PeterWilson
Occasional Contributor III
I'm looking for a way to use python dictionaries instead of ArcGIS Joins. Please note that I'm new to Python and would need some assistance to understand your code if you don't mind and have the time.

I have 7.5 million parcles saved as a feature class. Within the feature class I have a field called "SG_Code". I also have two tables called WARMS (i.e. WARMS_DW760 & WARMS DW764). They each have a field called "SG_Code" & "TIT_DEED_NUM". I then have another two additional tables called RED (i.e. Redistribution) and REST (i.e. Restitution). The RED and REST tables have a two fields "SG_CODE" and "TIT_DEED_NUM".

I need to create a subset feature class of the 7.5 million parcles where I find a match using firstly the "SG_Code" between the parcles feature class and each WARMS table separately (i.e. WARMS_DW760 then WARMS_DW764). I then need to find a match using the original 7.5 million feature class and RED and REST tables using the "SG_Code". Then I need to find a match based on the match already found using the 7.5 million records between the WARMS_DW760 and WARMS_DW764 and then match the "TIT_DEED_NUM" and the "TIT_DEED_NUM" found in the RED and REST tables to see if I find additional matches using the "TIT_DEED_NUM" as not all the records have "SG_Codes" within the REST and RED tables.

In short, what I'm trying to accomplish is to identify where I find a match between the parcles and warms, then a match between the parcles and RED and REST.

I've used Add Joins so far to accomplish this, but its running forever. I've attached my model that I've built so far to better understand what I'm trying to accomplish.

Regards
0 Kudos
11 Replies
PapantzinCid
New Contributor III
Hello, I am a python novice and am having some trouble with what I assume is an easy fix. I have a feature class that I added a new field to (Geology_Class). I want to update the new field with the items from my dictionary.  The keys in the dictionary are PTYPE and I want the new field to contain the values.  I created a search cursor so that it would loop through the existing PTYPE field (there are about 60) in my feature class.  I then added the update cursor so that it would search the PTYPE and add it to the new Geology_Class field.  When I run the script I get an error "Traceback (most recent call last):
  "File "C:\Users\Users\Desktop\GeoDis.py", line 42, in <module> row[2] = dictionary(row[1]) TypeError: 'dict' object is not callable."  Upon reading other forums is looks like I am trying to call a function when in reality it's not?  Or maybe use the .updateRow?
I know there are other methods in doing something so simple but using python was requested.  Any help you can offer is greatly appreciated.  Thank you.

Using ArcGIS 10.0




# Import arcpy module
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True

dictionary = {'C':'INSERT1','Ca':'Coarse-Competent','D':'INSERT2' ,'E':'Fine-Competent','Ec':'Coarse-Competent','E-Ep':'INSERT3',
'Ep':'Coarse-Competent','gb':'Crystalline','gr':'INSERT4','grCz':'INSERT5','grCz?':'INSERT6','gr-m':'Crystalline','grMz':'Crystalline', 'grMz?':'Crystalline',
'grpC':'INSERT7','grpC?':'INSERT8', 'grPz':'INSERT9','J':'INSERT10','J?':'INSERT11','K':'Fine-Competent','K?':'Fine-Competent','KJf':'INSERT12',
'KJfm':'INSERT13','KJfs':'INSERT14','Kl':'INSERT15','Kl?':'INSERT16','Ku':'Coarse-Weak','Ku-Ep':'INSERT17',
'ls':'INSERT18','M':'Coarse-Competent','M?':'Coarse_Competent','m':'Fine-Competent','M+KJfs':'INSERT19','Mc':'Coarse-Competent',
'Mexico':'Mexico','mv':'Fine-Competent'}


Input_Geology_Feature_Class = arcpy.GetParameterAsText(0)


attributes = arcpy.SearchCursor(Input_Geology_Feature_Class,"","","PTYPE","")


arcpy.AddMessage("Adding Geology Class Field...")
arcpy.AddField_management(Input_Geology_Feature_Class, "Geology_Class","TEXT")



arcpy.AddMessage("Populating Geology Class Field, Please Wait...")
geology = arcpy.da.UpdateCursor(Input_Geology_Feature_Class,["PTYPE","Geology_Class"])

for row in geology:
    row[2] = dictionary(row[1])
    geology.updateRow(row)
del row, geology
0 Kudos
PapantzinCid
New Contributor III
I was able to figure it out.  Thank you for taking the time to read. 
The problem was my update cursor:

geology = arcpy.UpdateCursor(Input_Geology_Feature_Class,["PTYPE", "Geology_Class"])

for updateRow in geology:
    if updateRow.PTYPE in dictionary:
        updateRow.Geology_Class = dictionary[updateRow.PTYPE]
        geology.updateRow(row)
del updateRow, geology
0 Kudos