ianleinwand

exporting a raster attribute table to a csv or dbf

Discussion created by ianleinwand on Apr 30, 2012
Latest reply on May 1, 2012 by philmorefield
I need to batch export information from 400 raster attribute tables...

I can get it to write a text file delimited by , but it write all of the records on the same line... how do I get it to recognize the fields as column and
format the text file so I can import it into access as a table.

here is the code

outfile = open(eco_pa + ".txt", "w")

        rows = arcpy.SearchCursor(eco_pa, "OCCUR = 1", "", "COUNT;ECO_ID;SPECIES;OCCUR", "")
        for row in rows:
            SPECIES = row.getValue("SPECIES")
            ECO_ID = row.getValue("ECO_ID")    
            OCCUR = row.getValue("OCCUR")
            COUNT = row.getValue("COUNT")
            
            print SPECIES, ECO_ID, OCCUR, COUNT
            outfile.write(str(SPECIES) + "," + str(ECO_ID) + "," + str(OCCUR) + "," + str(COUNT)

        outfile.close()

Outcomes