# 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")
os.rename(os.path.join(inDir,InAsciiFile), os.path.join(inDir,InAsciiFilename))
looks like i forgot a bracket at the end, sorry!os.rename(os.path.join(inDir,InAsciiFile), os.path.join(inDir,InAsciiFilename))
Traceback (most recent call last): File "C:\Users\rumana\Desktop\My EFDC\Data\AVHRR\BatchAscii2Raster5.py", line 23, in <module> gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFilename), os.path.join(OutRaster,InAsciiFilename.rsplit(".")[0][:11]), "FLOAT") ExecuteError: ERROR 000875: Output raster: C:/Users/rumana/Desktop/My EFDC/Data/AVHRR/SST_Feb11/RasterUp_Feb11\SST2011_037's workspace is an invalid output workspace. ERROR 000581: Invalid parameters. Failed to execute (ASCIIToRaster).
# Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() import arcpy # Set local variables InAsciiFile = None inDir = r'J:/BIOCLIM_Data/a1b_scenario/csiro_mk3_0_sres_a1b_2020s_bio_30s_no_tile_asc' OutRaster = 'J:/BIOCLIM_Data/a1b_scenario/csiro_mk3_0_sres_a1b_2020s_bio_30s_no_tile_asc/Raster format' 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: full_path = os.path.join(inDir, filename) inASCII = '%s.asc' % (full_path,) outRaster = '%s.img' % (full_path,) # Process: ASCIIToRaster_conversion gp.ASCIIToRaster_conversion(os.path.join(inDir,InAsciiFile), OutRaster, "FLOAT") except: pass
import os,arcpy, glob # Path to ascii files filepath = r"E:\test\ascdirectory" # Path where to put rasters outFolder = r"E:\test\ascdirectory\rasters" ascList = glob.glob(filepath + "/*.asc") print ascList for ascFile in ascList: outRaster = outFolder + "/" + os.path.split(ascFile)[1][:-3] + "tif" print outRaster arcpy.ASCIIToRaster_conversion(ascFile, outRaster, "FLOAT")
Hi, I tried out your script and it worked perfectly for a tif, but I requiere a GRID-raster, what do you recomend I should do?
just set the path to not end with ".tif"
Esri grids need to be named < 14 characters and need to start with a letter and no funny characters
# remove file extension and path
grid_name = os.path.splitext(os.path.basename(ascFile))[0][:13]
# clean up funky characters
grid_name = arcpy.ValidateTableName(grid_name, outFolder)
# set output Esri grid path
outRaster = outFolder + "/" + grid_name
# Import system modules import arcgisscripting, os # Create the Geoprocessor object gp = arcgisscripting.create() import arcpy import os import glob # Path to ascii files filepath = r"J:/BIOCLIM_Data/a1b_scenario/csiro_mk3_0_sres_a1b_2020s_bio_30s_no_tile_asc/new folder" # Path where to put rasters outFolder = r"J:/BIOCLIM_Data/a1b_scenario/csiro_mk3_0_sres_a1b_2020s_bio_30s_no_tile_asc/new folder" ascList = glob.glob(filepath + "/*.asc") print ascList for ascFile in ascList: outRaster = outFolder + "/" + os.path.split(ascFile)[1][:-3] + "tif" print outRaster arcpy.ASCIIToRaster_conversion(ascFile, outRaster, "FLOAT")