I don't know what I'm doing wrong. I always get the error 000865 when using arcpy.ASCIIToRaster_conversion. I'm new and do not have much Python experience right now – so sorry for that.
>>> import arcpy
import os
from arcpy import env
env.workspace = r"D:\Julia_T\projekt\erste_schritte\dritter_tag_python\testdaten"
#folder to list
ascFileList = arcpy.ListFiles("*.asc")
for ascFile in ascFileList:
# geoprocessing steps
ascFileName = os.path.splitext(ascFile)[0]
# define the output file
rastFile = ascFileName + "_output.img"
# run the tool
arcpy.ASCIIToRaster_conversion(ascFile,rastFile, "INTEGER")
Runtime error Traceback (most recent call last): File "", line 15, in File "c:\programme\arcgis\desktop10.2\arcpy\arcpy\conversion.py", line 2193, in ASCIIToRaster raise e ExecuteError: ERROR 000865: Eingabe-ASCII-Raster-Datei: 2001002_cloud_free.asc ist nicht vorhanden.
Do I have to use the CatalogPath? I'm working with ArcMap 10.2.1. Thanks
2 Answers 2
The ASCIIToRaster tool is not interpreting the file names correctly, despite you setting the workspace environment. You need to include the full path, so in your case your line should be:
arcpy.ASCIIToRaster_conversion(env.workspace + "\\" + ascFile, env.workspace + "\\" + rastFile, "INTEGER")
Also as @Erica says you should get into the habit of placing print
statements in your code to see the actual value of the variables.
Check whether the raster exists by using a print
statement, e.g.
for ascFile in ascFileList:
print ascFile
If that prints a list of .asc files, try rebooting.
If that doesn't work, check that the ASCII file will convert properly by testing just one (in a separate temporary script).
import arcpy
arcpy.ASCIIToRaster_conversion(r"c:\temp2001002円_cloud_free.asc",r"c:\temp\output.img", "INTEGER")
And use the full file path as Hornbydd describes:
for ascFile in ascFileList:
# define the input file path
ascFilePath = env.workspace + "\\" + ascFile
# define the output file
ascFileName = os.path.splitext(ascFile)[0]
rastFilePath = env.workspace + "\\" + ascFileName + "_output.img"
# run the tool
arcpy.ASCIIToRaster_conversion(ascFile,rastFile, "INTEGER")
-
So I print every step, did restarted the system, but I still get the same ERROR while running the tool. I really don't know what to do.Nora– Nora2014年07月24日 08:03:51 +00:00Commented Jul 24, 2014 at 8:03
-
'print ascFileList #works for ascFile in ascFileList: # geoprocessing steps ascFileName = os.path.splitext (ascFile)[0] print ascFileName #works rastFile = ascFileName + "_output.img" print rastFile #works #run the tool arcpy.ASCIIToRaster_conversion (ascFile, rastFile, "INTEGER") #ERROR 000865'Nora– Nora2014年07月24日 08:11:23 +00:00Commented Jul 24, 2014 at 8:11
-
@Nora Try (in a new script, perhaps) running the tool on just one raster with explicit declaration, e.g.:
arcpy.ASCIIToRaster_conversion(r"c:\temp2001002円_cloud_free.asc",r"c:\temp\output.img", "INTEGER")
Erica– Erica2014年07月24日 11:05:35 +00:00Commented Jul 24, 2014 at 11:05 -
it works with just one: ASCII inASCII = r"D:\Julia_T2000067円_cloud_free.asc" outRaster = r"D:\Julia_T\output" rasterType = "INTEGER" arcpy.ASCIIToRaster_conversion(inASCII,outRaster,rasterType)Nora– Nora2014年07月24日 12:40:13 +00:00Commented Jul 24, 2014 at 12:40
-
Good, so the raster files are not the problem. Try using the full path as Hornbydd proposes in his answer.Erica– Erica2014年07月24日 12:43:32 +00:00Commented Jul 24, 2014 at 12:43
Explore related questions
See similar questions with these tags.
for
loop need to be indented -- is it correct in your script? (Often pasting code into Questions loses spaces.)