Extract by Attributes (Spatial Analyst)

License Level:BasicStandardAdvanced

Summary

Extracts the cells of a raster based on a logical query.

Illustration

Extract by Attributes illustration
OutRas = Select(InRas1, "Value >= 2")

Usage

Syntax

ExtractByAttributes (in_raster, where_clause)
ParameterExplanationData Type
in_raster

The input raster from which cells will be extracted.

Raster Layer
where_clause

A logical expression that selects a subset of raster cells.

The expression follows the general form of an SQL expression.

Consult the documentation for more information on the SQL reference for query expressions used in ArcGIS and specifying a query in Python.

SQL Expression

Return Value

NameExplanationData Type
out_raster

The output raster containing the cell values extracted from the input raster.

Raster

Code Sample

ExtractByAttributes example 1 (Python window)

This example extracts cells from a raster based on a logical query, where elevation is greater than 1,000 meters.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
attExtract = ExtractByAttributes("elevation", "VALUE > 1000") 
attExtract.save("c:/sapyexamples/output/attextract")
ExtractByAttributes example 2 (stand-alone script)

This example extracts cells from a raster based on a logical query, where elevation is greater than 1,000 meters.

# Name: ExtractByAttributes_Ex_02.py
# Description: Extracts the cells of a raster based on a logical query. 
# 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
inRaster = "elevation"
inSQLClause = "VALUE > 1000"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute ExtractByAttributes
attExtract = ExtractByAttributes(inRaster, inSQLClause) 

# Save the output 
attExtract.save("c:/sapyexamples/output/attextract02")

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
11/8/2012