I have joined two tables. The first table includes the current z values, while the new table includes new z values. I first tried to snap, but this didn't update the Z values, only X and Y. How can I update the z values of the joined table? I tried some python scripting, but Im not very good at it.
import arcpy
mast = "VoltTotal.GDB\Export_Output"
with arcpy.da.UpdateCursor(mast['test_endre_geom.SHAPE@Z','feat3d.POINT_Z']) as cursor:
for row in cursor:
row[0] = row[1]
cursor.updateRow(row)
Currently I'm getting an error displaying: RuntimeError: A column was specified that does not exist.
2 Answers 2
Use cursors and make use of dictionaries to avoid nested loops.
import arcpy
mast = "VoltTotal.GDB\Export_Output"
shapeFile = "PathToMy\test_endre_geom.shp"
di = {}
with arcpy.da.SearchCursor(mast, ['M_FIELD', 'POINT_Z']) as cursor:
for m, z in cursor:
di [m] = z
with arcpy.da.UpdateCursor(shapeFile, ['M_FIELD', 'SHAPE@Z']) as cursor:
for m, z in cursor:
z = di [m]
row = (m, z)
cursor.updateRow (row)
To elaborate on my comment, I'm providing a potential solution. I'm assuming mast is the table and test_endre_geom.shp is the shapefile. The field 'M_FIELD' is a field that matches in both layers.
import arcpy
mast = "VoltTotal.GDB\Export_Output"
shapeFile = "PathToMy\test_endre_geom.shp"
with arcpy.da.SearchCursor(mast,['M_FIELD', 'POINT_Z']) as outsidecursor:
for row in outsidecursor:
matchValue = row[0]
tableValue = row[1]
with arcpy.da.UpdateCursor(shapeFile,['M_FIELD', 'SHAPE@Z']) as cursor:
for row in cursor:
if row[0] == matchValue:
row[1] = tableValue
cursor.updateRow(row)
UpdateCursor(fc, fields)
. The variablemast
should be separated from the list of fields by a comma.mast
.