Skip to content

Instantly share code, notes, and snippets.

@daranzolin
Created February 17, 2022 00:36
Show Gist options
  • Save daranzolin/605e55541f2bd5696daf32218ff3e708 to your computer and use it in GitHub Desktop.
Save daranzolin/605e55541f2bd5696daf32218ff3e708 to your computer and use it in GitHub Desktop.
Display a raster's 'attribute' table w/arcpy
import pandas as pd
def display_raster_attribute_table(ras):
if ras.hasRAT:
flds = [fld.name for fld in arcpy.ListFields(ras)]
table = []
cur = arcpy.SearchCursor(ras, flds)
for row in cur:
rowList = [row.getValue(fld) for fld in flds]
table.append(rowList)
del cur
return pd.DataFrame(table, columns = flds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment