0

Sort of new to Python. In Arcmap you can calculate a field on a joined table to just move the attributes from one column to another with just an = sign. Since my layer has feature linked anno on 7 different layers the calculation has to be done in an edit session. I tried this and it ran over three hours and not sure if it was going to finish. This won't work since I have to do this on about 30 fields.

I am trying to do this in arcpy. I was using arcpy.CalculateField_management. I don't think that works based on the error I received. The error is invalid property. I think this means that it wants to make a calculation not just move attributes.

Here is my sample code:

import arcpy
from arcpy import env

anno_conn = "\\\\any database"
env.workspace = anno_conn

#Variables
Table_A = "data_1"
Table_B = "data_r3"
Layer_A = Table_A + "_lyr"
Layer_B = Table_B + "_lyr"

try:
    #join tables
    arcpy.MakeFeatureLayer_management(Table_A, Layer_A)
    arcpy.MakeFeatureLayer_management(Table_B, Layer_B)

    arcpy.AddJoin_management(Layer_A, "visi_link", Layer_B, "prior_visi")

    # Using an edit session - feature linked layer can't be edited outside an edit session      
    # inside try edits will be saved if successful, will roll back if an exception is thrown
    with arcpy.da.Editor(env.workspace) as edit:
        arcpy.CalculateField_management(Layer_A, Table_A + ".link_id", "!" + Table_B + ".link_id!", "PYTHON")

except Exception, err:
    traceback.print_exc()

It seems to work up until the Calc field line. I've searched for answers to this for a day.

Any help is greatly appreciated.

  • You might want to use 'copy as python snippet' under geoprocessing>results after running calculate field from the toolbox. That way you'll know you are getting the syntax correct. Also, for concatenating strings and variables, you should investigate .format(). – Paul Jan 22 '14 at 16:24
  • I've voted to re-open because the asker has deleted the Duplicate Question that this one is pointing to. – PolyGeo Jan 23 '14 at 23:43
1

There are a couple of ways to accomplish this. If I am understanding what you are attempting to do correctly, you want to populate fields in the second table with values from the first.

The tact you are attempting is very ArcGIS centric and will definitely work. However, the more programmatic way to attempt this, one designed to run much faster in Python, is to use the update cursor from the arcpy data access module.

Also, although you likely just changed it when pasting into this editor, remember to play very close attention to your indentation. Your block of code between try and except, if not indented, will throw an error.

Finally, I did try and refactor your code a bit, but was not sure what the source and target field names are. Looking at your code above, they look almost identical. It may just be a simple step of including the source layer name in front of the dot notation. However, without a sample dataset to test against, it is hard to ascertain.

  • Let's see if I can explain a little better. Table_A is an older copied version of Table_B. We can't just replace Table_A since it has 7 levels of feature_linked annotation for an online product. The feature_link is the object_id. Replacing would require all of the anno to be checked. So, most of the fields in Table_A need to be updated with fields from Table_B. Both tables have the same field names. – Mike Hirschmann Jan 23 '14 at 12:57
  • Table_A fields: Objectid, visi_link, link_id, road1. Table_B: Objectid, visi_link, link_id, road1, prior_visi. Objectid must not change. Join table by visi_link - prior_visi. – Mike Hirschmann Jan 23 '14 at 14:56
  • @MikeHirschmann I think your Question will benefit from describing the steps to create a simple dataset e.g. point feature class with one point, label it, convert it to annotation, etc. Also, you will find it much easier to use the edit button below your Question to revise it to address questions raised in Comments instead of trying to cram detailed information into reply Comments. – PolyGeo Jan 23 '14 at 23:48
  • @PolyGeo I will certainly edit next time. I am new to this site and will read the best practices. This is wonderful resource. knu2xs I am trying the update curs0r method. So foar not much luck. It doesn't seem to like the fact that the table is joined. – Mike Hirschmann Jan 24 '14 at 14:51

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.