<?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 Re: Convert raster to txt in XYZ format in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212823#M16394</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can determine the x,y,z dimensions using Raster, as described &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000wt000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can iterate over the dimensions and get the cell values, as described &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000m8000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can write to a file like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f = 'D:\\temp\\test.txt'
with open(f, 'w') as fObj:
&amp;nbsp; fObj.write('x, y, z\n')
&amp;nbsp; for i in range(10):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fObj.write('%f, %f, %f\n % (i, i, i))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, your overall code might be something like (have not tested):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outTxt = 'D:\\temp\\test.txt'
inRasFP = 'D:\\temp\\raster.img'
inRas = arcpy.Raster(inRasFP)
extent = inRas.extent
with open(outTxt, 'w') as fObj:
&amp;nbsp; fObj.write('x, y, z\n') # only if you want a header in the text file
&amp;nbsp; for x in range(extent.XMin, extent.XMax):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for y in range(extent.YMin, extent.YMax):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fObj.write('%i, %i, %f\n % (x, y, arcpy.GetCellValue_management(inRasFP, "%i %i" % (x, y))))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:27:32 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-11T10:27:32Z</dc:date>
    <item>
      <title>Convert raster to txt in XYZ format</title>
      <link>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212822#M16393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello friends,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to convert a raster to a txt file but XYZ format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;*&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ASCII TO RASTER tool does not help because it does in another format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Know if there are processes supported by python can do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Gualberto&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 20:29:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212822#M16393</guid>
      <dc:creator>GualbertoHernandez</dc:creator>
      <dc:date>2013-08-08T20:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert raster to txt in XYZ format</title>
      <link>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212823#M16394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can determine the x,y,z dimensions using Raster, as described &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000wt000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can iterate over the dimensions and get the cell values, as described &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000m8000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can write to a file like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f = 'D:\\temp\\test.txt'
with open(f, 'w') as fObj:
&amp;nbsp; fObj.write('x, y, z\n')
&amp;nbsp; for i in range(10):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fObj.write('%f, %f, %f\n % (i, i, i))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, your overall code might be something like (have not tested):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outTxt = 'D:\\temp\\test.txt'
inRasFP = 'D:\\temp\\raster.img'
inRas = arcpy.Raster(inRasFP)
extent = inRas.extent
with open(outTxt, 'w') as fObj:
&amp;nbsp; fObj.write('x, y, z\n') # only if you want a header in the text file
&amp;nbsp; for x in range(extent.XMin, extent.XMax):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for y in range(extent.YMin, extent.YMax):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fObj.write('%i, %i, %f\n % (x, y, arcpy.GetCellValue_management(inRasFP, "%i %i" % (x, y))))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:27:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212823#M16394</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T10:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert raster to txt in XYZ format</title>
      <link>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212824#M16395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Sample/009z0000002v000000/"&gt;Sample&lt;/A&gt;&lt;SPAN&gt; tool.&amp;nbsp; See also this &lt;/SPAN&gt;&lt;A href="http://gis.stackexchange.com/questions/20783/how-to-get-x-y-coordinates-and-cell-value-of-each-pixel-in-a-raster-using-python/22249#22249"&gt;answer&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 01:20:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-raster-to-txt-in-xyz-format/m-p/212824#M16395</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2013-08-09T01:20:32Z</dc:date>
    </item>
  </channel>
</rss>

