Tools that honor the Snap Raster environment will adjust the extent of output rasters so that they match the cell alignment of the specified snap raster.
A snap raster is typically used when inputs to tools:
- Have different cell alignments
- Have different cell resolutions
- Have different coordinate systems
- Are features
- Specifying a snap raster does not change the values in the output extent control immediately; however, the extent is adjusted during execution.
- The lower left corner of the extent is snapped to a cell corner of the snap raster, and the upper right corner is adjusted using the output cell size. As a result, when the output cell size is the same as the snap raster cell size, the cells in the output raster are aligned with the cells of the snap raster.
- In general, the snap raster is applied to tools that output a raster. The extent is not snapped when the output is a feature class, table, or file.
- A snap raster can be used with the default output extent. You do not need to specify an extent explicitly in the environment to use a snap raster.
- It is recommended that you use the same cell size for the snap and output rasters. However, it is possible to have the snap raster cell size differ from the output raster cell size. In that case, only the left and bottom boundaries will align with the snap raster cells, and the upper right corner of the output extent may not coincide with a cell corner of the snap raster.
- Since the extent can be snapped to a larger extent, the output raster may contain an additional row and column of NoData cells.
- The size (the number of rows or columns) of a snap raster is not important. Only its origin and cell size are used to adjust the output extent.
- The extent of the snap raster does not need to overlap with the output extent. A small raster located outside of your analysis area can be used for snapping.
- The Snap Raster environment is independent of the Extent environment.
Snap Raster—Sets a raster that is used to define the cell alignment of an output raster.
arcpy.env.snapRaster = raster
The raster to be used as the snap raster.
This example demonstrates how to set the Snap Raster environment before executing an ArcGIS Spatial Analyst extension tool.
# Set workspace and extent environments
arcpy.env.workspace = "C:/workspace"
arcpy.env.extent = "C:/data/studyArea"
# Set Snap Raster environment
arcpy.env.snapRaster = "C:/data/my_snapraster"
# Set local variables
InZones = "C:/data/parcels.shp"
InZoneField = "Parcel_ID"
InValueRaster = "C:/data/Slope"
# Check out ArcGIS Spatial Analyst extension license
# Process: Calculate the mean slope of each parcel area.
out = arcpy.sa.ZonalStatistics(InZones, InZoneField, InValueRaster, "MEAN",