Principal Components (Spatial Analyst)

Summary

Performs Principal Component Analysis (PCA) on a set of raster bands and generates a single multiband raster as output.

Learn more about how Principal Components works

Usage

Syntax

PrincipalComponents (in_raster_bands, {number_components}, {out_data_file})
ParameterExplanationData Type
in_raster_bands
[in_raster_band,...]

The input raster bands.

Raster Layer
number_components
(Optional)

Number of principal components.

The number must be greater than zero and less than or equal to the total number of input raster bands.

The default is the total number of rasters in the input.

Long
out_data_file
(Optional)

Output ASCII data file storing principal component parameters.

The extension for the output file can be .txt or .asc.

File

Return Value

NameExplanationData Type
out_multiband_raster

The output multiband raster dataset.

If the output is an ESRI GRID raster, the name must have less than 10 characters.

Raster

Code Sample

PrincipalComponents example 1 (Python window)

This example performs Principal Component Analysis (PCA) on an input multiband raster and generates a multiband raster output.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outPrincipalComp = PrincipalComponents(["redlands"], 4,"pcdata.txt")
outPrincipalComp.save("C:/sapyexamples/output/outpc01")
PrincipalComponents example 2 (stand-alone script)

This example performs Principal Component Analysis (PCA) on an input multiband raster and generates a multiband raster output.

# Name: PrincipalComponents_Ex_02.py
# Description: Performs principal components analysis on a set of raster bands.
# 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
inRasterBand1 = "redlands/redlandsc1"
inRasterBand2 = "redlands/redlandsc3"
numberComponents = 2
outDataFile = "C:/sapyexamples/output/pcdatafile.txt"

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

# Execute PrincipalComponents
outPrincipalComp = PrincipalComponents([inRasterBand1, inRasterBand2], 2,
                                       outDataFile)

# Save the output 
outPrincipalComp.save("C:/sapyexamples/output/outpc01")

Environments

Related Topics

Licensing Information

ArcView: Requires Spatial Analyst
ArcEditor: Requires Spatial Analyst
ArcInfo: Requires Spatial Analyst

6/29/2011