Snap Raster (Environment setting)
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 where 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 different 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 might not coincide with a cell corner of the snap raster.
- Since it is permitted that the extent be snapped to a larger extent, the output raster may contain an additional row and/or column of NoData cells.
- The size (the number of rows or columns) of a snap raster is not important. Only the origin and the cell size of it are used to adjust the output extent.
- The extent of the snap raster does not need to be overlapped with the output extent. A small raster located outside of your analysis area could be used for snapping.
- The Snap Raster environment is independant of the Output 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 a Spatial Analyst tool.
import arcpy # Set general 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 arcpy.CheckOutExtension("Spatial") # Process: Calculate the mean slope of each parcel area. out = arcpy.sa.ZonalStatistics(InZones, InZoneField, InValueRaster, "MEAN","DATA") out.save("mean_ParSlp")