AnsweredAssumed Answered

Clip a raster using the Clipping Geometry option using ArcPy not working

Question asked by jvw122 on Jan 20, 2017
Latest reply on Jan 20, 2017 by iamurray

I am trying to automate the process of clipping rasters of scanned maps by following the recommendation found here: How To: Clip a raster using the Clipping Geometry option. The rasters are being clipped to the envelope, but not the shape as pixels outside of the polygon are still persisting. The rasters and the feature class are in the same coordinate system.


My footprints are all stored in same feature class with a field 'RasterFile' storing the raster name (e.g. 'raster01.tif'). I have tried creating a feature layer with a query and using Select analysis to select out the footprint for a single raster (see code below). Everything processes, but the shape clip is not honored.


When I just run the Raster Clip tool manually, the clip honors the shape. Any ideas for what I may be missing?


# Paths have been generalized for example purposes

import os
import arcpy

inputFolder = r'..\RasterFolder'
footprints = r'..\GDB.gbb\ScanFootprints' # Polygon feature class

# Create a list of rasters; Output will look like: ['raster01.tif', 'raster02.tif', ...]
arcpy.env.workspace = inputFolder
processRasters = arcpy.ListRasters()

# Iterate each raster to clip
for raster in processRasters:
    inputRaster = os.path.join(inputFolder, raster)

    # Feature layer method
    arcpy.MakeFeatureLayer_management(footprints, "footprint", "RasterFile = '" + raster + "'")
    arcpy.Clip_management(inputRaster, '#', outputRaster, "footprint", '#', 'ClippingGeometry')

    # Select Analysis method
    arcpy.Select_analysis(footprints, footprints + '_temp', "RasterFile = '" + raster + "'")
    arcpy.Clip_management(inputRaster, '#', outputRaster, footprints + '_temp', '#', 'ClippingGeometry')