I’m running 2 Python scripts. The first it is to apply Zonal Histogram to several rasters. The second it is for saving the Zonal Histograms to a text file.
My problem is when the first script creates the Zonal Histogram a suffix is added to the VALUE row (see image) and the second script doesn’t work because for every raster a different suffix is added (suffix added correspond to the feature zone data value)
Any idea on how avoid this suffix and only have the label VALUE for each raster?
Script 1:
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = r"C:Base_de_datosPrueba_zonalcuencas"
rasters = arcpy.ListRasters("*")
# Set local variables
zoneField = "VALUE"
inValueRaster = "C:Base_de_datosPrueba_zonalusos_tolten.tif"
outTable = r"C:\Base_de_datos\Prueba_zonal\Tablas\"
# Overwrite
arcpy.env.overwriteOutput = True
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ZonalHistogram
for raster in rasters:
ZonalHistogram(raster, zoneField, inValueRaster, outTable + str(raster))
print raster + " listo"
Script 2:
import arcpy
from arcpy import env
# Set environment settings
env.workspace = r"C:Base_de_datosPrueba_zonalTablas"
= arcpy.ListTables("*")
outfile = open(r"C:\Base_de_datos\Prueba_zonal\zonal.txt", "w")
# SearchCursor value and count - export to txt
for tabla in tablas:
rows = arcpy.SearchCursor(tabla,"","","LABEL;VALUE","")
for row in rows:
val = row.getValue("LABEL")
count = row.getValue("VALUE")
print val, count
outfile.write(str(tabla) + "," + str(val) + "," + str(count) + "n")
outfile.close()