Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Batch arcpy.CopyRaster after arcpy.ASCIItoRaster

$
0
0

I’m new to arcpy and am having trouble running CopyRaster. Do I need a separate for loop for this process like I have below?

import os,arcpy, glob  


filepath = r"C:VMsharedsmall_example_valley2snowdepthtest"   

outFolder = r"C:VMsharedsmall_example_valley2snowdepthout"  


ascList = glob.glob(filepath + "/*.asc")  

print ascList  

rasterpath = r"C:VMsharedsmall_example_valley2snowdepthout"

LastOutFolder = r"C:VMsharedsmall_example_valley2snowrast"

rasterList = glob.glob(rasterpath + "/*.tif")
print rasterList


for ascFile in ascList:  

    outRaster = outFolder + "/" + os.path.split(ascFile)[1][:-3] + "tif"  
    print outRaster  

    arcpy.ASCIIToRaster_conversion(ascFile, outRaster, "FLOAT")



for rasterFile in rasterList:   

    LastOutRaster = LastOutFolder + "/" + os.path.split(rasterFile)[1][:-3] + "tif"
    arcpy.CopyRaster_management(r"C:VMsharedsmall_example_valley2snowdepthout",r"C:VMsharedsmall_example_valley2snowrast","DEFAULTS","","","NONE","NONE","16_BIT_UNSIGNED")

Edit:

After modifying the script, I get the following error:

ERROR 000876: Output raster:
C:VMsharedsmall_example_valley2snowdepthtestsnowdepthN0001.asc’s
extension is invalid for the output raster format.

import os,arcpy, glob

filepath = r"C:VMsharedsmall_example_valley2snowdepthtest"
outFolder = r"C:VMsharedsmall_example_valley2snowdepthout"
ascList = glob.glob(filepath + "/*.asc")

rasterpath = r"C:VMsharedsmall_example_valley2snowdepthout"

OutFolderTwo = r"C:VMsharedsmall_example_valley2snowrast"

rasterList = glob.glob(rasterpath + "/*.asc")
print rasterList

for ascFile in ascList:
    outRaster = os.path.join(outFolder, ascFile)
    arcpy.ASCIIToRaster_conversion(ascFile, outRaster, "FLOAT")

rasterList = glob.glob(outFolder + "/*.tif")

for rasterFile in rasterList:

    OutRasterTwo = os.path.join(OutFolderTwo, rasterFile)
    arcpy.CopyRaster_management(rasterFile, OutRasterTwo, "DEFAULTS","","","NONE","NONE","16_BIT_UNSIGNED")

Viewing all articles
Browse latest Browse all 767

Trending Articles