I've written a script to run through a point layer, using the SearchCursor in the data access module and then read the XY values. Within the with
statement, I then use GetCellValue
to get the elevation values and print them.
What I'd like to do is go one step further and write the value to a field in the row. Is there a way to do this? I can use CalculateField
, but that'll be slow as it'll have to use a query to limit itself to the current row. I can also possibly use a list to write the values to and then run through the list and update the fields using the UpdateCursor
, but I think that'll be slow too.
Is there a way to do this inside the with
statement?
import arcpy
##arcpy.AddField_management('C:\Data\Surveyed.shp', 'Z', 'DOUBLE')
with arcpy.da.SearchCursor('C:\Data\Surveyed.shp', ['SHAPE@XY']) as cursor:
for row in cursor:
result = arcpy.GetCellValue_management('Database Connections\DC_SDEEBG_gisp.sde\SDEEBG.GIS.SRTM_DEM_NSWVICTAS_1SEC', str((row[0])[0]) + " " + str((row[0])[1]), "1")
CellValue = float(result.getOutput(0))
print CellValue