0

I'd like to read from the attribute table of an intermediate raster generated by arcpy.sa.Combine:

combined = arcpy.sa.Combine(['raster1', 'raster2'])
arcpy.BuildRasterAttributeTable_management(combined)
data = [row for row in arcpy.da.SearchCursor(combined, ["VALUE", "COUNT"])]

The above code raises: RuntimeError: 'in_table' is not a table or a featureclass

Is there a way to access the RAT without saving the raster?

asked Sep 28, 2018 at 16:05
1
  • Try to create raster layer from it. Commented Sep 28, 2018 at 19:38

1 Answer 1

2

Try setting arcpy.env.workspace = 'in_memory', or the cursor will not know where to find the raster.

It could also be that combined is a raster object which the cursor cannot read. Try "saving" it to in_memory workspace:

combined.save(r"in_memory\outcombine2")
data = [row for row in arcpy.da.SearchCursor(r"in_memory\outcombine2", ["VALUE", "COUNT"])]
answered Sep 28, 2018 at 16:27
1
  • The second solution worked for me: I had to call .save() on the raster and then I could use SearchCursor on it like any other table. This is odd, because you can print the variable containing the output of your raster tool (in your example, you could use arcpy.AddMessage(f"Output raster={combined}") and it too will be a path to a raster. But you can't read its contents as a table. In my case I was using arcpy.sa.ExtractByAttributes, so a lot of raster tools probably do this. Commented Mar 8, 2024 at 12:59

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.