I have the following script and the issues I am having is that the PermitNum can have multiple Par (par field) numbers but my current script will only populate the Parel field with just one Par attribute, it doesn't transfer each parcel that corresponds with each permit number. How can I adjust my current code to transfer each parcel number?
fc_dest = "D:/Temp/Cases"
sourceFC = "D:/Temp/Casestableview"
#Use Dictionary to update fc fileds.
sourceFieldsList = ['PermitNum','Par','AppS','AppT', 'SubT','Desc', 'MainApp', 'PA', 'Status', 'AppStatus', 'DecDate',]#,'ProjectInfo', 'Contractor', 'Subdivision', 'TwnRngSec', 'LivingSpace', 'TotalSqFt', 'Value_', 'Valuation', 'Status']
# Use list comprehension to build a dictionary from a da SearchCursor
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
updateFieldsList = ['PermitNum','Par','AppS','AppT', 'SubT','Descr', 'MainApp', 'PA', 'Status', 'AppStatus', 'DecDate']
with arcpy.da.UpdateCursor(fc_dest, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value of the row being updated in a keyValue variable
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the values stored under the keyValue from the dictionary to the updated fields.
for n in range (1,len(sourceFieldsList)):
updateRow[n] = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
del valueDict
My apologies, I might have complicated things. I removed fields to make the files smaller.
I hope this makes sense and thank you so much for trying to help.
The feature class and the table only have the PermitNum field as unique identifiers. I adding fields to the feature class to match the tables fields. So I can transfer attributes from the table to the feature class.The table can have multiple permits with more than one parcel associated with that permit.
For example in the table
PermitNum | Parcle |
CR2020-0005 | 34252 |
CR2020-0005 | 34263010 |
CR2020-0005 | 34263012 |
:
The feature class only has the following the PermitNum.
PermitNum | Parcel |
CR2020-0005 | |
CR2020-0005 | |
CR2020-0005 |
And when I run the code on my first post I get the following
PermitNum | Parcel | |
CR2020-0005 | 34263010 | |
CR2020-0005 | 34263010 | |
CR2020-0005 | 34263010 |
I need to transfer the table attributes to the feature class like below.
Feature class after the code
PermitNum | Parcle |
CR2020-0005 | 34252 |
CR2020-0005 | 34263010 |
CR2020-0005 | 34263012 |
I don't think it is possible to do what your are trying since you don't really have a column with a unique value in either your feature class or table. So, once again, forget about figuring out how to solve the problem with python for now. You have to find something in or add something to the data that lets you associate each record in the table with one and only one record in the feature class. Once you have that we can discuss how to make it work using python.
When you say that I don't have a column with a unique Value, doesn't the OBJECTID in the feature class and table count as unique columns?
True - but you need a unique value that allows you to link a record in the table with a record in the feature class. In database terminology it is a foreign key. It can't be PermitNum since there are duplicates, so it has to be PermitNum plus something else.