1

I am trying to get a script to run to batch resample some TIFF files. I've used an almost identical script to resample GRID files with no issues. When I try to run it with a group of TIFF files the code stops with the first file with "RESTART: Shell" but no errors. Here is the code:

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Input data source
env.workspace = r'C:\ArcGIS\GR 8573\tpw_tif_in'
arcpy.env.overwriteOutput = True

# Set output folder
OutputFolder = r'C:\ArcGIS\GR 8573\tpw_resamp_out'

# Loop through a list of files in the workspace
RSfiles = arcpy.ListRasters("*", "TIF")

for filename in RSfiles:
    print("Processing: " + filename)
    inRSfiles = arcpy.env.workspace + "/" + filename

    # This next line reduces a file name of the format "comp20180702.120000" to "807022" where the
    # first digit is the year (assuming all years 2018, 2019, or 2020), the 2nd & 3rd digits are the month
    # the 4th and 5th digits are the day, and the 6th digit the hour (assuming 00, 06, 12, 18 are the only choices)

    newname = filename[7:12] + filename[14]

    TempLayerFile = "resamp"
    
    outRaster = OutputFolder + "/" + newname

    # Process: Resample
    arcpy.Resample_management(inRSfiles, "resamp", "1 1", "BILINEAR")

    # Process: Copy Raster
    arcpy.CopyRaster_management(TempLayerFile, outRaster, format="TIFF")

print "***DONE!!!"
print arcpy.GetMessages()

When I step through the process the I think the restart happens at arcpy.CopyRaster_management(TempLayerFile, outRaster, format="TIFF").

When I searched for help I couldn't find any solutions I thought were applicable. It's especially confusing because with just a few minor changes to make it applicable to GRID files it works great.

Edit: changing the line outRaster = OutputFolder + "/" + newname to outRaster = OutputFolder + "/" + newname +".tif" solved my issue.

3
  • 1
    Try outRaster = OutputFolder + "/" + newname +".tif"
    – FelixIP
    Commented Jul 3, 2021 at 21:58
  • That did it! Thanks!
    – Chris
    Commented Jul 4, 2021 at 2:49
  • Please self-answer it to reduce number of posts with no solutions.
    – FelixIP
    Commented Jul 4, 2021 at 4:48

1 Answer 1

1

The suggestion by FelixIP solved my issue. Changing the line outRaster = OutputFolder + "/" + newname to outRaster = OutputFolder + "/" + newname + ".tif" did the trick!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.