Select to view content in your preferred language

Writing Geometry to Records with Empty Geometry Based on Matching IDs

2147
16
Jump to solution
02-21-2020 07:38 AM
deleted-user-PUOLzzPmi8Uz
New Contributor

I have a polyline feature class with a related table attached. Is there a good way to write the feature class line geometry to the records in the related table? Goal is to create a feature class with lines with duplicate geometry, e.g. stacked. Any py code out that can accomplish this?

Thanks!

0 Kudos
16 Replies
deleted-user-NvcfpBOWaKwr
Occasional Contributor

David, With your previous code it was updating rows with Null or None Geometry to the matching rows that contained geometry. I updated your code to exclude the "None" geometry type from the dictionary so there wouldn't be an accidental overwrite to features that contained geometry.

import arcpy

inFC = r""
inFields = ['Unique_ID', 'SHAPE@']
#valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(inFC, inFields)}

valueDict = {}

for r in arcpy.da.SearchCursor(inFC, inFields):
    if r[1] == None:
        pass
    else:
        valueDict[r[0]] = r[1:]

print(valueDict)

with arcpy.da.UpdateCursor(inFC, inFields) as updateRows:

    for updateRow in updateRows:
        keyValue = updateRow[0]
        print(keyValue)

        if keyValue in valueDict:
            updateRow[1] = valueDict[keyValue][0]
            print(valueDict[keyValue][0])
            updateRows.updateRow(updateRow)
            print("Updated {}".format(keyValue))
deleted-user-PUOLzzPmi8Uz
New Contributor

David / Jeremy. Thank you both so much. This works!

0 Kudos
deleted-user-NvcfpBOWaKwr
Occasional Contributor

Jason, don't forget to give credit to David since he did all of the heavy lifting. Plus I'm sure he would like the points for a correct answer.

Have a good weekend!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Please mark a response as Correct to close out the question.  If multiple responses helped, pick the one that helped the most and mark the others helpful.

deleted-user-PUOLzzPmi8Uz
New Contributor

Yep. Special props to David for helping me this! I learned quite a bit today.

0 Kudos
DavidPike
MVP Frequent Contributor

Jeremy, nice one. Why I tried to edit the dictionary comprehension i dont know. I'm sticking to iterators!

I think that may mislead others with incorrect solutions, but thanks anyway. Theres a points system??

0 Kudos
deleted-user-NvcfpBOWaKwr
Occasional Contributor

Haha.. Can i give the points to David please? I just swooped in to fix a dictionary issue and don't deserve the correct answer points.

0 Kudos