I need to know whether it is possible to calculate a new field for a raster table based on a value from a joined table. Ideally I'd like to be able to accomplish this task without having to add table and raster layer to the table of contents within ArcMap. Please help!

The following section of my script runs successfully until it gets the line which creates the update cursor:

    #ArcMap v. 10.2.1
    # Add 3 fields to each of the new product rasters
    #Perform a spatial join connecting the variable rates table to the product raster

if sPotash and sPotash != "#":
    arcpy.AddField_management("pt_tst","LB_P_AC", "DOUBLE","","", "","")
    arcpy.AddField_management("pt_tst","LB_P_SQM", "DOUBLE","","", "","")
    arcpy.AddField_management("pt_tst","P_P_SQM", "DOUBLE","","", "","")




    #arcpy.JoinField_management("pt_tst_lyr", "VALUE", "Potash_Rates.dbf","ZONE","Potash")

    potashrstr = pt_tst_lyr

    cursor = arcpy.UpdateCursor("pt_tst_lyr")

    fields = ["Potash","LB_P_SQM"] #the Potash field is a field belonging to the Variable_Rates table

    with arcpy.da.UpdateCursor("pt_tst_lyr",fields) as cursor:
        for row in cursor:
            row[1] = row[0]/4046.86

when you join a table, the names of the fields to be used in ArcGIS becomes a concatenation of the name of the table and the name of the field. So you should try with

fields = ["Potash_Rates.Potash","pt_tst.LB_P_SQM"]

also there is a small typo in your raster name, but probably not in your original one

cursor = arcpy.UpdateCursor("pt_tst_lyr") should be removed

""C:\Users\Desktop\CurrentWork\pm\Output_1192015\pt_tst" is "C:\Users\Desktop\CurrentWork\pm\Output_1192015\pt_tst"

EDIT : you could also try with the field calculator

arcpy.CalculateField_management("pt_tst_lyr", "pt_tst.LB_P_SQM", "[Potash_Rates.Potash]/4046.86")

EDIT : I didn't realize immediately that you were working with a grid, so the syntax is a bit different

arcpy.CalculateField_management("pt_tst_lyr", "pt_tst.vat:LB_P_SQM", "[Potash_Rates.Potash]/4046.86")
  • The script now works up until when it specifies the update cursor. Gives me the following error message: 'Type Error: Cannot update join table'
    – c_mck
    Jan 19 '15 at 18:01
  • you should only update the raster table, and I inverted the order. Updated now.
    – radouxju
    Jan 19 '15 at 19:34
  • also, I suggest that you use MakeTableView instead of MakeRasterLayer
    – radouxju
    Jan 19 '15 at 19:50
  • I tried that and im still getting an error. Would it be easier to create a dictionary of values representing the table of values i am trying to pull from?
    – c_mck
    Jan 19 '15 at 21:24
  • this is indeed one solution. but I think that the problem comes from the name of your table. You should first try with the join in arcmap and see exactly how your table is called. Then you can use the arcpy.CalculateField tool, which is easier to use than the cursor in your case.
    – radouxju
    Jan 19 '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.