Here is a program that worked well six months ago doing the same thing but refuses to do so now and returns the error messages. Any advice would be appreciated.
import arcpy, os, glob, shutil, fnmatch
from arcpy import env
from arcpy.sa import *
import time
start_time = time.time()
arcpy.CheckOutExtension("Spatial")
env.overwriteOutput = True
# Set environment
arcpy.env.workspace = "G:/GIS Data/FAO GAEZ/low irrigation"
arcpy.env.scratchWorkspace="G:/GIS Data/scratch"
# Set local variables
# folder containing only input rasters and nothing else
inws = "G:/GIS Data/FAO GAEZ/low irrigation"
outws="G:/GIS Data/FAO GAEZ/rasters/World/low_irrigation"
rasters=[]
for root, dirs, files in os.walk(inws):
for subdir in dirs:
print subdir
directory=outws+"/"+subdir
print directory
outRaster=directory+"/"+"data"
print outRaster
asciiname=root+"/"+subdir+"/data.asc"
print asciiname
if not os.path.exists(directory):
os.makedirs(directory)
arcpy.ASCIIToRaster_conversion(asciiname,outRaster)
print "Done"Here are the results. I should note that the program is creating the directory successfully. Line 37 refers to the arcpy.ASCIIToRaster...command.
chickpea_105_low
G:/GIS Data/FAO GAEZ/rasters/World/low_irrigation/chickpea_105_low
G:/GIS Data/FAO GAEZ/rasters/World/low_irrigation/chickpea_105_low/data
G:/GIS Data/FAO GAEZ/low irrigation/chickpea_105_low/data.asc
Traceback (most recent call last):
File "C:\Users\achanda\Dropbox\Research\India Canals\python\lowirrigationpixels.py", line 37, in <module>
arcpy.ASCIIToRaster_conversion(asciiname,outRaster)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\conversion.py", line 2461, in ASCIIToRaster
raise e
ExecuteError: ERROR 010328: Syntax error at or near symbol SPACE.
ERROR 010267: Syntax error in parsing grid expression.
Failed to execute (ASCIIToRaster).
Solved! Go to Solution.
Can you try saving to a directory that contains no spaces, just to rule that out?
Can you try saving to a directory that contains no spaces, just to rule that out?
line numbers and formatting /blogs/dan_patterson/2016/08/14/script-formatting
for future reference
And I would recommend saving to *.tif raster format, in a folder. tifs behave better than the old esri grid format since they have fewer restrictions on how they are named
Thanks for your replies. It was definitely the long directory name with spaces. I really need to address that.
Dan, thanks for directing me to those instructions as well.