arcpy.da.UpdateCursor fails to update geometry

3975
12
Jump to solution
01-26-2017 05:25 AM
BledarBirbo1
Occasional Contributor

Hi.

I am having the following issue when i try to update an SDE Geodatabase featureclass geometry from arcpy

Using:

ArcGIS 10.3.1

SQL Server Geodatabase

Line featureclass with enabled: Archiving , Editor Tracking and Registered as Versioned.

The line featureclass also participates in a replica as the source layer.

The line fetureclass can be edited fine from arcmap.

The issue:

Because we do receive new updated line geometries (features) from another source i have bulid a python script that joins the 2 datasets based on an attribute key and and tries to update the geometry on the Line Featureclass.

I am using the following code tu update the geometry.

fieldNames = ['ID', 'SHAPE@','SHAPE@WKT']
edit.startEditing()
edit.startOperation()
with arcpy.da.UpdateCursor(line_layer, fieldNames) as updateCursor:
 for tmpRow in updateCursor:
    tmpRow[1] = #newgeometry that was read previusly
    updateCursor.updateRow(tmpRow)
edit.stopOperation()
edit.stopEditing(True)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The code runs without any error but the geometry is not updated. I tested the code for other attributes and they were updated correctly.

Any ideas ?

Thanks.

0 Kudos
12 Replies
VinceAngelo
Esri Esteemed Contributor

kimo wrote:

Do you need a geometry AND a wkt version? Surely one will do. You would have to be careful to get the one in the list.

This is the key point.  By specifying an update of the same column in two different forms, but only updating the first referenced input, the code is likely updating the column with the new content, then updating it again with the previous contents.

Multiple references to the same geometry column in an UPDATE or INSERT cursor really ought to raise an error.

- V

BledarBirbo1
Occasional Contributor

Leaving only the SHAPE@WKT field in the UpdateCursor and updating only that fixed it.

Thanks.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Why use SHAPE@WKT instead of SHAPE@ ?  From a performance perspective, I can't imagine returning the WKT instead of a geometry object saves much, and there are cases where the WKT doesn't exactly equal the geometry.  For example, with curves:

>>> esri_json = {  
...     "curvePaths": [[  
...         [1,5],  
...         {"c": [[7,3], [6,2]]}  
...     ]],  
...     "spatialReference": {"wkid": 0}  
... }  
...   
>>> ln = arcpy.AsShape(esri_json, True)
>>> ln.JSON
u'{"curvePaths":[[[1,5],{"c":[[7,3],[6,2]]}]],"spatialReference":{"wkid":null}}'
>>> 
>>> arcpy.FromWKT(ln.WKT).JSON
u'{"paths":[[[1,5],[0.99399503194559768,4.9030739951953093],[0.99088008165787445,4.8060121224880596],[0.99065791395499181,4.7089005336315006],[0.99332872603216815,4.6118254245067529],[0.99889014728664582,4.5148729586156593], ..., [6.7724322738783158,2.6854575752247012],[6.8328139890149053,2.7615151752781921],[6.8909032081665362,2.8393377469851719],[6.9466483715607055,2.9188562153236042],[7,3]]],"spatialReference":{"wkid":null}}'

In the example above, the true curve is approximated when dumped out in WKT, and regenerating the geometry from that WKT makes for a different geometry, although practically the same.