# Import system modules import arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables InAsciiFile = "C:/Data/data_2001.asc" OutRaster = "C:/Data/data_2001" gp.outputCoordinateSystem = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(InAsciiFile, OutRaster, "FLOAT")
# Import system modules import arcgisscripting, os, glob # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables gp.workspace = "C:/Data" gp.outputCoordinateSystem = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" # Process: ASCIIToRaster_conversion for x in glob.glob(os.path.join(gp.workspace, "*.asc")): gp.ASCIIToRaster_conversion(x, os.path.split(os.path.basename(x))[0], "FLOAT")
# Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables InAsciiFile = None inDir = "C:/Data" OutRaster = "C:/Data/data_2001" gp.outputCoordinateSystem = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" for InAsciiFile in os.listdir(inDir): if InAsciiFile.rsplit(".")[-1] == "asc": print InAsciiFile try: # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), OutRaster, "FLOAT") except: pass
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000859: The required parameter Output raster is empty, or is not the type of Raster Dataset. Failed to execute (ASCIIToRaster).
# Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables InAsciiFile = None inDir = r"C:\GIS\ascii" OutRaster = "C:/GIS/Exports" gp.outputCoordinateSystem = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" for InAsciiFile in os.listdir(inDir): if InAsciiFile.rsplit(".")[-1] == "asc": print InAsciiFile # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), os.path.join(OutRaster,InAsciiFile.rsplit(".")[0]), "FLOAT")
bruce.nielsen- I got the following error- I'm not sure in this code where to specify the output?ExecuteError: Failed to execute. Parameters are not valid. ERROR 000859: The required parameter Output raster is empty, or is not the type of Raster Dataset. Failed to execute (ASCIIToRaster).
Thanks again for your help.
gp.ASCIIToRaster_conversion(x, os.path.split(os.path.basename(x))[0] + ".tif", "FLOAT")This will create TIF files, which can reside anywhere.
I tested this one and it works. Make sure your file names are less than 13 characters.# Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() # Set local variables InAsciiFile = None inDir = r"C:\GIS\ascii" OutRaster = "C:/GIS/Exports" gp.outputCoordinateSystem = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" for InAsciiFile in os.listdir(inDir): if InAsciiFile.rsplit(".")[-1] == "asc": print InAsciiFile # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), os.path.join(OutRaster,InAsciiFile.rsplit(".")[0]), "FLOAT")
Hello mzcoyle,
I tried your code for batch processing of ASCII to Raster. It works but I got one problem.
How do I rename ASCII files or output Raster files, cause my ASCII files have more than 13 characters?
gp.ASCIIToRaster_conversion(os.path.join(inDir, InAsciiFile), os.path.join(OutRaster, InAsciiFile.rsplit(".")[0][:13]), "FLOAT")