1

Am trying to clip multiple rasters but getting a runtime error, what could be the problem with my code

import arcpy, os

arcpy.env.workspace = r"E:\Geos4s\GeoS4S Module Geospatial Support for Arid Ecosystem Management\prec_30s_esri\converted"
arcpy.env.overwriteOutput = True

# Clip region
poly = r"E:\Kenya GIS Resources\Kenya New Districts1\Kenya_CountyID.shp"
out_folder =  r"E:\Geos4s\GeoS4S Module Geospatial Support for Arid Ecosystem Management\prec_30s_esri\clipped"
rasters = arcpy.ListRasters()
for raster in rasters:
    out_raster =(out_folder,raster)
    arcpy.Clip_management(raster,'#',out_raster,poly,'#','ClippingGeometry')
    print 'Clipped: %s' %raster
print arcpy.GetMessages()
  • What is the precise error message, including line number, that you receive when you run the code that you have presented? – PolyGeo Mar 28 at 12:08
4

You just need to replace:

out_raster =(out_folder,raster)

With:

out_raster = os.path.join(out_folder,raster)

Or out_raster will be a tuple: ('C:\\folder', 'raster.tif'), instead of a path: 'C:\\folder\\raster.tif'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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