ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Sample

Available with Spatial Analyst license.

  • Summary
  • Usage
  • Syntax
  • Code Sample
  • Environments
  • Licensing Information

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.

The input rasters can be two-dimensional or multidimensional. The structure of the output table changes when the input rasters are multidimensional.

Learn more about how Sample works

Usage

  • When the input location is a raster, the set of location cells consists of all cells 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, or rasters, will be given a <null> value in an output geodatabase table. For output to INFO or .dbf, since the concept of null is not supported, a value of 0 (zero) will be given.

  • If more than one multidimensional raster is provided, they must all share the same dimension names.

  • NetCDF Raster Layers are the only type of multidimensional rasters supported.

  • If the input rasters are a mixture of two-dimensional and multidimensional rasters, only the current slice of any multidimensional raster will be sampled.

  • When the input rasters are two-dimensional, the field type of the sampled values in the output table is always floating point. This is to ensure that the appropriate degree of precision is retained if the bilinear or cubic options for the resampling technique were to be selected.

  • When the location input is raster, for best results, 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.

  • Multipoint datasets are not supported as input.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Syntax

Sample (in_rasters, in_location_data, out_table, {resampling_type}, {unique_id_field}, {process_as_multidimensional})
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. By default, the output will be a geodatabase table. If the path is not in a geodatabase, the format is determined by the extension. If the extension is .dbf, it will be in dBASE format. If no extension is specified, the output will be an INFO table.

Table
resampling_type
(Optional)

Resampling algorithm used when sampling a raster.

  • NEAREST — Nearest neighbor assignment
  • BILINEAR — Bilinear interpolation
  • CUBIC — Cubic convolution
String
unique_id_field
(Optional)

A field containing a different value for every location or feature in the input location raster or point features.

Field
process_as_multidimensional
(Optional)

Determines how the input rasters are processed.

  • ALL_SLICES — Samples will be taken for all dimensions (such as time or depth) of a multidimensional dataset.
  • CURRENT_SLICE —Samples will be taken from the current slice of a multidimensional dataset. This is the default.
Boolean

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

  • Auto Commit
  • Extent
  • Current Workspace
  • Output CONFIG Keyword
  • Scratch Workspace

Licensing Information

  • ArcGIS for Desktop Basic: Requires Spatial Analyst
  • ArcGIS for Desktop Standard: Requires Spatial Analyst
  • ArcGIS for Desktop Advanced: Requires Spatial Analyst

Related Topics

  • An overview of the Extraction tools
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal