AnsweredAssumed Answered

How to fix ascii to raster error

Question asked by gerard_summers_UCC on Oct 10, 2019
Latest reply on Oct 14, 2019 by Hornbydd

I am trying to create a raster from an ascii text file in python through the arcpy tool ASCIIToRaster_conversion(). I have the ascii text formatted as so:

 

NCOL 39
NROWS 54
XLLCORNER 2760.091202
YLLCORNER -1253.840905
CELLSIZE 2.0
NODATA_VALUE -99999
5.789899100000000232e+01 2.760091202000000067e+03 -1.253840905000000021e+03
6.423454300000000217e+01 2.762091202000000067e+03 -1.253840905000000021e+03

 

I have created the raster file through make x y event layer and the details all match up bar the nodata value, which is left blank. 

 

The code used to create the ascii is:

 

xmin = np.min(myArray[:,1])
ymin = np.min(myArray[:,2])

cell_size = "2"

col = np.max(myArray[:,1]) - xmin
row = np.max(myArray[:,2]) - np.min(myArray[:,2])

 

header = "NCOL " + str(col) + "\n".format(myArray.shape[1])
header += "NROWS " + str(row) + "\n".format(myArray.shape[0])
header += "XLLCORNER " + str(xmin)+ "\n"
header += "YLLCORNER " + str(ymin)+ "\n"
header += "CELLSIZE " + str(cell_size) + "\n"
header += "NODATA_VALUE -99999"

 

np.savetxt("myGrid.asc", myArray, delimiter = " ",header = header, comments="")

 

The code used to open the ascii text and put it through the raster converter is:

 

Workspace= "D:/Documents/PhD/GIS/Odhran"

arcpy.ASCIIToRaster_conversion("mygrid.asc", Workspace, "INTEGER")

 

The associated error message is:

 

Traceback (most recent call last):
File "C:\Python27\ArcGIS10.6\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "D:\Documents\Csv_to_raster_sub.py", line 12, in <module>
Workspace, "INTEGER")
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\conversion.py", line 2461, in ASCIIToRaster
raise e
ExecuteError: ERROR 010158: Unable to open file MYGRID.ASC.
ERROR 010067: Error in executing grid expression.
Failed to execute (ASCIIToRaster).

Outcomes