<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Export values in a raster table to .txt or .csv file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-values-in-a-raster-table-to-txt-or-csv-file/m-p/552616#M43149</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm batch-processing some watershed stuff and wish to automatically export the values in a raster table to anything useful outside of GIS, such as a .txt, .csv or .xls file. I cannot locate this command. It was once upon a time quite easy with Arc/INFO but those days have passed. Also, the ability to append to the output file (rather than write 100s of different files) would be very nice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Feb 2012 18:55:52 GMT</pubDate>
    <dc:creator>RyanUtz</dc:creator>
    <dc:date>2012-02-13T18:55:52Z</dc:date>
    <item>
      <title>Export values in a raster table to .txt or .csv file</title>
      <link>https://community.esri.com/t5/python-questions/export-values-in-a-raster-table-to-txt-or-csv-file/m-p/552616#M43149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm batch-processing some watershed stuff and wish to automatically export the values in a raster table to anything useful outside of GIS, such as a .txt, .csv or .xls file. I cannot locate this command. It was once upon a time quite easy with Arc/INFO but those days have passed. Also, the ability to append to the output file (rather than write 100s of different files) would be very nice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ryan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2012 18:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-values-in-a-raster-table-to-txt-or-csv-file/m-p/552616#M43149</guid>
      <dc:creator>RyanUtz</dc:creator>
      <dc:date>2012-02-13T18:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Export values in a raster table to .txt or .csv file</title>
      <link>https://community.esri.com/t5/python-questions/export-values-in-a-raster-table-to-txt-or-csv-file/m-p/552617#M43150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;1. The CopyRows tool will export a raster attribute table to any "ESRI-approved" table format (.dbf, .mdb., .gdb, SDE, INFO, etc.) Unfortunatly, tab and comma delimited text format tables are not in that list! You would need to write your own thing to do that via Python (pretty easy to do), or download someone elses toolbox/code... Maybe a toolbox/python code such as &lt;/SPAN&gt;&lt;A href="http://arcscripts.esri.com/details.asp?dbid=13692" rel="nofollow noopener noreferrer" target="_blank"&gt;http://arcscripts.esri.com/details.asp?dbid=13692&lt;/A&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Curious that you can do a right click and "Export As" in ArcMap/ArcCatalog and export to a txt format (tab delimited BTW). However, there doesn't seem to be a tool in ArcToolbox that can accomplish this amazing feat...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Do you mean append to the table? Again, if you use one of the ESRI-appropved table formats, the Append tool works just great. There doesn't appear to be a way to do this "out of the box" however if you are using a txt fomat table though!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A good resource for basic file reading/writting in Python: &lt;/SPAN&gt;&lt;A href="http://docs.python.org/tutorial/inputoutput.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/tutorial/inputoutput.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;A good resource for more "precise" csv file writting: &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/csv.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/library/csv.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's some basic code I wrote to build a quick and dirty comma delimited text file:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy 
outputTxtFile = r"C:\csny490\myfile.txt" #output comma delimited text file
myGrid = r"C:\csny490\mm_from_space\wa06_mean4bin" #input raster file
fieldList = arcpy.ListFields(myGrid) #make a list of the fields
f = open(outputTxtFile, 'w') #open the text file for writting
f.write(",".join(['"'+ field.name + '"' for field in fieldList]) + "\n") #write the header (field names) using list comprehension 
searchRows = arcpy.SearchCursor(myGrid) #open a search cursor
for searchRow in searchRows: #loop through the rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(",".join([str(searchRow.getValue(field.name)) for field in fieldList]) + "\n") #write out the field values of each row using list comprehension 
del searchRow, searchRows #delete the cursor objects
f.close() #close the text file&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:53:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-values-in-a-raster-table-to-txt-or-csv-file/m-p/552617#M43150</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T23:53:35Z</dc:date>
    </item>
  </channel>
</rss>

