1

I have downloaded US soil raster data by state from https://gdg.sc.egov.usda.gov/GDGOrder.aspx at 10m resolution.

I am now trying to add a modified raster attribute table to tif that was exported from the geodatabase using arcpy, but have been unable to do so. The existing tif has an attribute table with an ID that matches the IDs in the modified attribute table.

I have tried to (1) make the raster a layer (not sure this is the right approach), (2) add a table using AddJoin_management, and (3) export the results. Obviously, I am missing something.

import arcpy
from arcpy import env
env.workspace = "C:/Data"
inFeatures = "InRaster.tif" ## This is tif raster exported from geodatabase
layerName = "raster_layer"
rat = "rat.dbf" ## attribute table for joining
arcpy.MakeRaster_management(inFeatures,layerName) ## This doesn't work, with or without extension.
tmp = arcpy.AddJoin_management(layerName,"Value",rat,"ID") # This works, but is a result and I am not sure how to export it.
asked Apr 14, 2016 at 18:04

2 Answers 2

1

There is a much simpler solution to writing code and that is to use the Join Field tool. This is like @FelixIP approach in that it adds a field to the input table and passes over the values. So no need for an export step. This tool can pass over multiple fields and works at all license levels.

answered Apr 15, 2016 at 10:05
1
  • For downstream analyses, I do need to export the values from the attribute table as a raster Commented Apr 15, 2016 at 15:38
0

It seems that you'd like to create new raster from yours with a column added to it's table.

I also don't know how to export raster layer to a new raster. This is why I suggest to create new field in original raster and populate it by matching values from table:

import arcpy
from arcpy import env
env.workspace = "D:/scratch"
inFeatures = "InRaster.tif"
layerName = "raster_layer"
rat = "mouse.dbf"
# create dictionary from table
aDict={}
with arcpy.da.SearchCursor(rat,("ID","random")) as cursor:
 for row in cursor:aDict[row[0]]=row[1]
# create field in raster table
arcpy.MakeRasterLayer_management(inFeatures, layerName)
try:arcpy.AddField_management(layerName, "fldFloat","FLOAT")
except:pass
# and transfer matching records from rat table
with arcpy.da.UpdateCursor(layerName,("Value","fldFloat")) as cursor:
 for row in cursor:
 aKey=row[0]
 if aKey in aDict:
 print 'Transferring value %s for key %s' %(aDict[aKey],aKey)
 cursor.updateRow((aKey,aDict[aKey]))
answered Apr 15, 2016 at 3:18

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.