Sample (Spatial Analyst)
Summary
Creates a table that shows the values of cells from a raster, or set of rasters, for defined locations. The locations are defined by raster cells or by a set of points.
Usage
-
When the input location is a raster, the set of location cells consists of all cell that have a value of zero or greater. Cells that have NoData values are not included in the location set. A location raster can be easily created using the extraction tools.
-
Locations that sample NoData cells in the input raster(s) will be given a NULL Value. For shapefiles, NULL is not supported and a value of 0 (zero) will be given.
-
The values of the cells will remain integers for the rasters in input rasters that are integer, even if the Bilinear or Cubic options are selected for the resampling technique.
-
The cell size and registration of the input rasters and the location raster should be the same.
-
The output from the tool is a table.
Syntax
Parameter | Explanation | Data Type |
in_rasters [in_raster,...] |
The list of rasters whose values will be sampled based on the input location data. | Raster Layer |
in_location_data |
Data identifying positions at which you want a sample taken. This can be a raster or a point feature dataset. | Raster Layer | Feature Layer |
out_table |
Output table holding the sampled cell values. | Table |
resampling_type (Optional) |
Resampling algorithm used when sampling a raster.
| String |
Code Sample
Extract the cell values from multiple rasters to a table based on input locations.
import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" Sample(["elevation", "costraster"], "observers.shp", "c:/sapyexamples/output/samptable","NEAREST")
Extract the cell values from multiple rasters to a table based on input locations.
# Name: Sample_Ex_02.py # Description: Creates a table that shows the values of cells from # a raster, or set of rasters, for defined locations. # The locations are defined by raster cells or by a set # of points. # Requirements: Spatial Analyst Extension # Author: ESRI # Import system modules import arcpy from arcpy import env from arcpy.sa import * # Set environment settings env.workspace = "C:/sapyexamples/data" # Set local variables inRasters = ["elevation", "costraster"] locations = "observers.shp" outTable = "c:/sapyexamples/output/samptable02" sampMethod = "NEAREST" # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Execute Sample Sample(inRasters, locations, outTable, sampMethod)