Saturday, 12 December 2015

arcmap - Error 000865 when using arcpy.ASCIIToRaster_conversion


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



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...