Hello!
I have a script that runs as a tool in ArcGIS Pro. The script takes each record in a feature class and queries a web service based on some filled in attributes to populate the rest of the attributes. The script uses an UpdateCursor to update the input feature class and then uses an InsertCursor to output it to a new feature class. I've chosen to do it this way since there are multiple features that need to be outputted with slightly different information. For example, if one record has a field that has three different values for it (A, B, and C), I need to create 3 different polygons in the output feature class. (I'm aware that related tables could also work for this part, but that's not relevant to the issue.
The issue occurs when I try to use InsertCursor to transfer the geometry to the output feature class. Somehow, the feature class gets warped somehow? In the screenshot below, the pink polygon is the output and the underlying blue polygon is the input.
The output feature class is created with the input as a template so the schemas are essentially identical. Below is the code I use:
with arcpy.da.UpdateCursor(inputClass, ['inputAttribute1', 'inputAttribute2', 'inputAttribute3','inputAttribute4','inputAttribute5', 'SHAPE@']) as cursor: arcpy.AddMessage('Creating copies for each control event...') destCursor = arcpy.da.InsertCursor(outClass, ['outputAttribute1', 'outputAttribute2', 'outputAttribute3','outputAttribute4','outputAttribute5','SHAPE@'])
## loop through each row in the input feature class for row in cursor: ## function that retrieves data based on unique identifier from input feature class returnJSON = getAttributes(row[0]) ## the return JSON has a variable that holds an array of objects containing the information for each copy required. ## loop updates the row in the input feature class with information and then updates the for event in returnJSON['varyingAttributes']: if row[1] == event['definingAttribute']: try: row[2] = event['attribute3'] except: pass try: row[3] = event['attribute4'] except: pass try: row[4] = event['attribute5'] except: pass ## update the row with the new information try: cursor.updateRow(row) except: print('Error: ', row[0]) pass ## insert the updated row into the output feature class before updating it again with new information. destCursor.insertRow(row) del destCursor
The logic of attribute updating works well, it's just the geometry is the only thing (this description might be overkill, but I wanted to include as much info as possible).
In summary, insert cursor doesn't seem to accurately transfer geometry data.
Any guidance on this is greatly appreciated!
Solved! Go to Solution.
Due to the way your code is written, I cant see much potential for warping of the features via this.
Which mostly, just leaves coordinate systems.
Ensure your input, and output FC have matching coordinate systems.
Due to the way your code is written, I cant see much potential for warping of the features via this.
Which mostly, just leaves coordinate systems.
Ensure your input, and output FC have matching coordinate systems.
Thanks so much! I wrongly assumed that the template would include the CRS, but I see now that is not the case (as the documentation states below).