updateRows = arcpy.UpdateCursor(targetLayer) for updateRow in updateRows: shapeObj = updateRow.getValue(shapeFieldName) # Multipart geometries. for partObj in shapeObj: for pointObj in partObj: # Only valid points. if (pointObj != None): # Setting the values of the z cooridnates to a fixed value. pointObj.Z = 9999 updateRow.setValue(shapeFieldName, shapeObj) updateRows.updateRow(updateRow)
Solved! Go to Solution.
import arcpy targetLayer = r'C:\Project\_Forums\multipart\test.gdb\myPolylineZ_multipart' shapeFieldName = 'SHAPE' cursor = arcpy.UpdateCursor(targetLayer) for row in cursor: geom = row.getValue(shapeFieldName) geomArr = arcpy.Array() for part in geom: partArr = arcpy.Array() for pnt in part: if pnt != None: pntOut = arcpy.Point(pnt.X, pnt.Y, 9999) partArr.add(pntOut) geomArr.add(partArr) polyline = arcpy.Polyline(geomArr) row.setValue(shapeFieldName, polyline) cursor.updateRow(row) del row del cursor
Dear list
I try to set the Z values of all vertex of individual lines by a fixed value / attribute. All vertex of a single geometry are getting the same value. Somehow I tried to set the values through the geometry object I retrieve from the cursor. But the values are not written back to the geodatabase.updateRows = arcpy.UpdateCursor(targetLayer) for updateRow in updateRows: shapeObj = updateRow.getValue(shapeFieldName) # Multipart geometries. for partObj in shapeObj: for pointObj in partObj: # Only valid points. if (pointObj != None): # Setting the values of the z cooridnates to a fixed value. pointObj.Z = 9999 updateRow.setValue(shapeFieldName, shapeObj) updateRows.updateRow(updateRow)
I don't understand why the changed geometries are not written to the database. What would be the correct way to do it?
I am looking forward to any hint and ideas.
Best regards,
Yvo
import arcpy targetLayer = r'C:\Project\_Forums\multipart\test.gdb\myPolylineZ_multipart' shapeFieldName = 'SHAPE' cursor = arcpy.UpdateCursor(targetLayer) for row in cursor: geom = row.getValue(shapeFieldName) geomArr = arcpy.Array() for part in geom: partArr = arcpy.Array() for pnt in part: if pnt != None: pntOut = arcpy.Point(pnt.X, pnt.Y, 9999) partArr.add(pntOut) geomArr.add(partArr) polyline = arcpy.Polyline(geomArr) row.setValue(shapeFieldName, polyline) cursor.updateRow(row) del row del cursor