Principal Components (Spatial Analyst)
Summary
Performs Principal Component Analysis (PCA) on a set of raster bands and generates a single multiband raster as output.
Usage
-
The value specified for the number of principal components determines the number of principal component bands in the output multiband raster. The number must not be larger than the total number of raster bands in the input.
-
If the input is a layer created from a multiband raster with more than three bands, the operation will consider all the bands associated with the source dataset, not just the three bands that were loaded (symbolized) by the layer. If you want to process a subset of the bands in the source dataset, you can use the Make Raster Layer tool to create an input layer containing the desired bands.
-
The raster bands must have a common intersection. If there is none, an error occurs and no output is created.
-
With the output data file name specified, the correlation and covariance matrices, as well as the eigenvalues and eigenvectors, will be stored in an ASCII file.
Syntax
Parameter | Explanation | Data 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
Name | Explanation | Data 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
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")
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")