<?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: Ascii to Raster Conversion help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743295#M57458</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just add the path to the name of the ascii file for each member of your list as you go through a loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got it to work like this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for asc in ascList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]asc = path+"\\"+asc[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.ASCIIToRaster_conversion(asc, asc[:-4]+".img" , "FLOAT")[/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Oct 2012 23:49:02 GMT</pubDate>
    <dc:creator>WhitneyKirkendall</dc:creator>
    <dc:date>2012-10-11T23:49:02Z</dc:date>
    <item>
      <title>Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743284#M57447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hope someone can help - I've written this script several times in the past but unfortunately my laptop is being serviced and I forgot to backup my python scripts directory - ~DOH &lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, this should be really simple - I'm looping through some ascii files in a directory and converting them to a raster.&amp;nbsp; However, Python returns the error - Failed to execute (ASCIIToRaster).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the ascii file is there as I have manually converted in toolbox and its fine.&amp;nbsp; I've posted the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "C:/Data/asc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputraster = raster.rstrip("dtm.asc")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datatype = "FLOAT"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Get a list of ascii files&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rasterList = arcpy.ListRasters()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for raster in rasterList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ASCIIToRaster_conversion(raster,outputraster,datatype)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 17:16:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743284#M57447</guid>
      <dc:creator>ClaireParsons</dc:creator>
      <dc:date>2011-10-24T17:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743285#M57448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hope someone can help - I've written this script several times in the past but unfortunately my laptop is being serviced and I forgot to backup my python scripts directory - ~DOH &lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Anyway, this should be really simple - I'm looping through some ascii files in a directory and converting them to a raster.&amp;nbsp; However, Python returns the error - Failed to execute (ASCIIToRaster).&lt;BR /&gt;I know the ascii file is there as I have manually converted in toolbox and its fine.&amp;nbsp; I've posted the code below.&lt;BR /&gt;&lt;BR /&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;&lt;BR /&gt;# Local variables:&lt;BR /&gt;env.workspace = "C:/Data/asc"&lt;BR /&gt;outputraster = raster.rstrip("dtm.asc")&lt;BR /&gt;datatype = "FLOAT"&lt;BR /&gt;&lt;BR /&gt;#Get a list of ascii files&lt;BR /&gt;rasterList = arcpy.ListRasters()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for raster in rasterList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ASCIIToRaster_conversion(raster,outputraster,datatype)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The issu is outputraster = raster.rstrip("dtm.asc"). It does not create "dtm". Try use &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputraster = raster.split(".")[0] instead&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 17:46:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743285#M57448</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-10-24T17:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743286#M57449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;dtm is in the file name so have used rstrip("dtm.asc") to strip dtm and asc from the filename so it doesn't exceed 13 characters - so not sure this is the answer as its the input file it can't find!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;***Extra note - just ran your suggestion and same issue - for some reason it is saying the input file doesn't exist which is bizarre when it has got the name from the rasterlist which has just cycled through that folder!!!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000865: Input ASCII raster file: sx0051dtm.asc does not exist&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 17:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743286#M57449</guid>
      <dc:creator>ClaireParsons</dc:creator>
      <dc:date>2011-10-24T17:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743287#M57450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;env.workspace = "C:/Data/asc"&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;shouldn't this read env.workspace = r"C:/Data/asc" ??&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 18:10:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743287#M57450</guid>
      <dc:creator>ScottBlankenbeckler</dc:creator>
      <dc:date>2011-10-24T18:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743288#M57451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;dtm is in the file name so have used rstrip("dtm.asc") to strip dtm and asc from the filename so it doesn't exceed 13 characters - so not sure this is the answer as its the input file it can't find!&lt;BR /&gt;&lt;BR /&gt;***Extra note - just ran your suggestion and same issue - for some reason it is saying the input file doesn't exist which is bizarre when it has got the name from the rasterlist which has just cycled through that folder!!!&amp;nbsp; &lt;BR /&gt;ERROR 000865: Input ASCII raster file: sx0051dtm.asc does not exist&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hard code the input and output path to see if it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 18:28:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743288#M57451</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-10-24T18:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743289#M57452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;shouldn't this read env.workspace = r"C:/Data/asc" ??&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = r"C:\Data\asc"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 18:51:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743289#M57452</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-10-24T18:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743290#M57453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok if you hard code the paths and run the script on a single file it works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I'm wondering whether its ListRasters or the For loop - can't remeber having this problem before!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EXTRA NOTE***** - Is there any other way I can get a list or loop through files in a folder?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 18:59:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743290#M57453</guid>
      <dc:creator>ClaireParsons</dc:creator>
      <dc:date>2011-10-24T18:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743291#M57454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Ok if you hard code the paths and run the script on a single file it works.&lt;BR /&gt;So, I'm wondering whether its ListRasters or the For loop - can't remeber having this problem before!!&lt;BR /&gt;&lt;BR /&gt;EXTRA NOTE***** - Is there any other way I can get a list or loop through files in a folder?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "C:/Data/asc"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for file in arcpy.ListFiles("*.asc"):&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2011 19:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743291#M57454</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-10-24T19:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743292#M57455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi thanks for your reply but this still isn't working.&amp;nbsp; I've changed the script a little bit so it prints the file names before commencing the conversion(or not!!), to ascertain that its creating the list, which incidentally it is.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
import os

env.workspace = "C:\\Data\\asc"
listFiles = arcpy.ListFiles("*.asc")
for file in listFiles:
&amp;nbsp;&amp;nbsp;&amp;nbsp; outfile = file[:6]
&amp;nbsp;&amp;nbsp;&amp;nbsp; infile = file
&amp;nbsp;&amp;nbsp;&amp;nbsp; dtype = "Float"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print file
&amp;nbsp;&amp;nbsp;&amp;nbsp; print outfile
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ASCIIToRaster_conversion(infile, outfile, dtype)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm desperate for some advice on this as I have some files to convert for a client tomorrow &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Claire&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:38:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743292#M57455</guid>
      <dc:creator>ClaireParsons</dc:creator>
      <dc:date>2021-12-12T07:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743293#M57456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;maybe you can try the glob module instead of listrasters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import glob,os
import arcpy

path = r'C:\Data\asc'
arcpy.env.workspace = path 
os.chdir(path)

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make a list of asc files in the workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; listAsc = glob.glob('*.asc')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for currentFile in listAsc:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Find the current file name and path
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = currentFile[:-4]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textFilePath = path + '/' + currentFile&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a raster from the current file
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ASCIIToRaster_conversion(textFilePath,name + '.tif','FLOAT')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(arcpy.GetMessages() + "\n")&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Get error messages
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages(2)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:38:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743293#M57456</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-12T07:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743294#M57457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I too am trying to batch convert 137 asc files to raster using the python script - I can make the function work for individual files:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.ASCIIToRaster_conversion("c:/data/elevation.asc", "c:/output/elevation", "INTEGER")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But cannot get it to batch work. I tried to follow the thread below (although I couldnt see if it was actually successful?) but to no avail. This is my first day of Python so could just be my ignorance. Any help greatfully received.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Dec 2011 15:34:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743294#M57457</guid>
      <dc:creator>JustinDix</dc:creator>
      <dc:date>2011-12-07T15:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Ascii to Raster Conversion help</title>
      <link>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743295#M57458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just add the path to the name of the ascii file for each member of your list as you go through a loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got it to work like this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for asc in ascList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]asc = path+"\\"+asc[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.ASCIIToRaster_conversion(asc, asc[:-4]+".img" , "FLOAT")[/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2012 23:49:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ascii-to-raster-conversion-help/m-p/743295#M57458</guid>
      <dc:creator>WhitneyKirkendall</dc:creator>
      <dc:date>2012-10-11T23:49:02Z</dc:date>
    </item>
  </channel>
</rss>

