3

I'm trying to update the locations of a point FeatureClass using a table.

I have joined the table to the featureclass, and am attempting to use Field Calculator to update the SHAPE field.

I found the following code snippet that does what I want:

def Update(shape, newX, newY):
   pnt = shape.getPart(0)
   pnt.X = newX
   pnt.Y = newY
   return pnt

Update( !SHAPE! , !NEAR_X! , !NEAR_Y! )

which ends up looking like this:

Field Calculator Example

When I try this on a test featureclass, with no joined fields (just 3 columns; shape, newX, newY) it works perfectly. However, when I try it on my real data, with the table joined, it will not work. It gives a 'Failed to execute' error, and the ever-joyful 'ERROR 999999: Error executing function.'

I have tried making a Feature Layer from the joined table, and that doesn't help either.

How do I properly refer to the field names to make this work?

EDIT: In response to @Emil Brundage - when running the query on the joined layer, I did use the tablename.fieldname structure, as per the image below.

Query showing actual field names.

I receive a syntax error: Syntax error message

2 Answers 2

3

Once a table is joined you need the name of the table where the field originated as well as the field name, separated by a period.

Update ( !test2.Shape!, !test1.NEAR_X!, !test1.NEAR_Y!)

enter image description here

1

There is nothing wrong with your syntax, even though ArcMap would like you to think so. Use similar syntax on any other field and it will work.

The issue is that the SHAPE field is read only for Field Calculator when the table has a join. A solution would be to remove any joins, and then join the NEAR_X and NEAR_Y fields using Join Field, and then use Field Calculator with the following code:

arcpy.PointGeometry( arcpy.Point( !NEAR_X!, !NEAR_Y! ) )

You could also use an UpdateCursor and SearchCursor to do what you want without the need for joins or copying fields, but that is for another question.

3
  • Thanks @Barbarossa. This is the most clearly stated explanation I've seen of the problem yet. I've in touch with Esri tech support, and we're working on exactly what you said. However, we've now run into a (like totally unrelated) issue with the Join Field tool. However, we also have not yet had luck with UpdateCursor and SearchCurson, due to the Geometric Network and Feature Linked Annotation present. Jan 31, 2019 at 14:04
  • @DarrenCope Have you tried to wrap the cursors inside of an arcpy.da.editor operation?
    – Barbarossa
    Jan 31, 2019 at 14:43
  • I'm not a python expert (which is why I was attempting to do it in field calculator) but from what I can tell in the script, yes. There's a line that reads: "edit = arcpy.da.Editor(arcpy.env.workspace)" Feb 1, 2019 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.