0

I have two point layers. I trust the geometry (read: x and y coordinates) from one of them, but not the attributes data. I trust the attribute data but not the geometry from the other one (the attribute tables have different schema). The basic process (shown in a model builder screenshot below) is to spatially join the point layers, join the result to the points with good data/bad geometry and update their shape field with a script. The script produces one of those damnable "999999: Error executing function" errors.

If I manually step through every stop of the process and feed the update cursor a ready-made feature class it works fine, the points move as intended. It's just when it's set up to run in a model that the script throws the error. I have a feeling that I may be passing the parameter incorrectly, but I can't say for sure.

I've tried moving the "fc = GetParameterAsText()" line around (including in the update cursor parameters) to no avail.

I will also point that I shamelessly took the python from a post on Geonet, located here.

The Model: enter image description here The Script:

import arcpy  
from arcpy import env  

env.workspace = r"C:\Temp\TempGDB.gdb"  

#Get the feature layer from the previous step in the model   
fc = arcpy.GetParameterAsText(0) 

pnt = arcpy.Point()  

#Update the shape field with the new coordinates  
rows = arcpy.UpdateCursor(fc)  
for row in rows:  
    pnt.X = row.X_Coord  
    pnt.Y = row.Y_Coord  
    row.shape = pnt  
    rows.updateRow(row)  

del row, rows  

The Script Tool Properties

enter image description here

  • Maybe you could try having the output of the model be put into a known location with a known name, and then you can use that known location and known name as an input to your script. At the end of the model, the known name/location should be set and the script can read it in. – Branco Feb 19 '15 at 21:22
  • @Branco I could try that; it sounds like it would work. It just feels unsatisfying given my understanding of how these functions and tools are supposed to work, like more of a 'workaround' than a 'fix'. (story of my life with ESRI) – SVisovsky Feb 19 '15 at 21:36
  • Did you check out this example (gis.stackexchange.com/questions/29873/…)? I just found it, and it will probably be pretty helpful. – Branco Feb 19 '15 at 21:40
3

It lools like the problem is that pnt has no spatial reference and arc is having a spit, It's that or your field isn't being retrieved correctly, it's best to use row.getValue(field_name) rather than row.field_name as getValue is more flexible. Please ensure the fields X_Coord and Y_Coord exist in your layer (and aren't turned off) in the layer dialog.

Try this:

import arcpy  
from arcpy import env  

env.workspace = r"C:\Temp\TempGDB.gdb"  

#Get the feature layer from the previous step in the model   
fc = arcpy.GetParameterAsText(0) 
desc = arcpy.Describe(fc)
SR = desc.spatialReference # get the spatial reference from the feature class

pnt = arcpy.Point()  

#Update the shape field with the new coordinates  
rows = arcpy.UpdateCursor(fc)  
for row in rows:  
    pnt.X = row.getValue("X_Coord")
    pnt.Y = row.getValue("Y_Coord")
    pGeom = arcpy.PointGeometry(pnt)
    pGeom.spatialReference = SR # apply it to the shape
    row.shape = pGeom  
    rows.updateRow(row)  

del row, rows  

This would definitely work better as an arcpy.da cursor (ArcGIS 10.1+):

import arcpy  
from arcpy import env  

env.workspace = r"C:\Temp\TempGDB.gdb"  

#Get the feature layer from the previous step in the model   
fc = arcpy.GetParameterAsText(0) 

#Update the shape field with the new coordinates
with (arcpy.da.UpdateCursor(fc,["SHAPE@X","SHAPE@Y","X_Coord","Y_Coord"])) as rows:
    for row in rows:
        row[0]=row[2] # X = X_coord
        row[1]=row[3] # Y = Y_coord
        rows.updateRow(row)
  • Thank you! I just tried your first script. It's still throwing the 999999 error on the rows = arcpy.UpdateCursor(fc) line. I inserted a message after getting the fc variable, and it prints out the name of the feature layer going leading into the script. I'm going to try your second script now (I have 10.2.2). Just for clarification, your row[#]s are referencing the array you created in the update cursor parameters and not an array of all the fields in the table, right? – SVisovsky Feb 20 '15 at 16:32
  • Just tried the second script and that threw a new error (but at least a descriptive one!). "(arcpy.da.UpdateCursor(fc,["SHAPE@X","SHAPE@Y","X_Coord","Y_Coord"])) as rows: TypeError: cannot update join table " – SVisovsky Feb 20 '15 at 17:23
  • You need to be editing to affect joined tables. If the join is not necessary then drop (remove) it, conversely if the joined table holds the x_coord and y_coord values then start editing in ArcMap before running the script - just remember to save your edits or the update will be undone. – Michael Stimson Feb 22 '15 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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