Sample (Spatial Analyst)

License Level:BasicStandardAdvanced

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.

Learn more about how Sample works

Usage

Syntax

Sample (in_rasters, in_location_data, out_table, {resampling_type})
ParameterExplanationData 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.

The format of the table is determined by the output location and path. If no extension is specified, it will be an INFO table. If the location is in a geodatabase, the output table will be created in that particular type (for example, a file or ArcSDE geodatabase). If the name has a .dbf extension, the output will be in dBASE format.

Table
resampling_type
(Optional)

Resampling algorithm used when sampling a raster.

  • NEAREST Nearest neighbor assignment.
  • BILINEAR Bilinear interpolation.
  • CUBIC Cubic convolution.
String

Code Sample

Sample example 1 (Python window)

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")
Sample example 2 (stand-alone script)

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

# 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)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires Spatial Analyst
ArcGIS for Desktop Standard: Requires Spatial Analyst
ArcGIS for Desktop Advanced: Requires Spatial Analyst
4/10/2014