0

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.

jbchurchill
4,49924 silver badges41 bronze badges
asked Aug 9, 2017 at 11:11
5
  • for starters the syntax does not look right on the UpdateCursor(fc, fields). The variable mast should be separated from the list of fields by a comma. Commented Aug 9, 2017 at 13:12
  • @jbchurchill Thats correct, well spottet, but I think that was only a copying error as the original code include the coma. I updated the post to reflect that. Commented Aug 9, 2017 at 13:23
  • 1
    Your field list appears to be using 2 fields from different tables as they have table names before the field name.. That is not how the cursor works, you can only process fields from the single featureclass, in your case mast. Commented Aug 9, 2017 at 13:39
  • @Hornbydd Thank you, that was what I was wondering about. Do you have any idea how I could approach this problem? I'm not very skilled in python. Commented Aug 9, 2017 at 13:55
  • If you have a field that matches in both tables you can run your update cursor within a search cursor so that when it finds a match, it updates the values in the other table. Commented Aug 9, 2017 at 14:36

2 Answers 2

1

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)
answered Aug 9, 2017 at 22:34
1

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)
answered Aug 9, 2017 at 15:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.