Extract values from PCA on raster

446 views Asked by At
pcaRasters
$call
rasterPCA(img = predictors)

$model
Call:
princomp(cor = spca, covmat = covMat[[1]])

Standard deviations:
      Comp.1       Comp.2       Comp.3       Comp.4       Comp.5       Comp.6       Comp.7       Comp.8       Comp.9 
498.96308248 356.19955279 166.82560362  79.75533403  28.30786958  18.01329729  11.05097697   5.90091966   4.85153037 
     Comp.10      Comp.11      Comp.12      Comp.13      Comp.14      Comp.15      Comp.16      Comp.17      Comp.18 
  3.96912826   2.92429575   2.32486057   1.74476578   1.37242353   0.99700591   0.69100295   0.52470761   0.38599513 
     Comp.19      Comp.20      Comp.21      Comp.22      Comp.23 
  0.30199746   0.12861497   0.05112695   0.01751713   0.00000000 

 23  variables and  1034761 observations.

$map
class       : RasterBrick 
dimensions  : 959, 1079, 1034761, 23  (nrow, ncol, ncell, nlayers)
resolution  : 0.008333334, 0.008333334  (x, y)
extent      : 24.99168, 33.98334, -23.00833, -15.01666  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +no_defs 
data source : in memory
names       :           PC1,           PC2,           PC3,           PC4,           PC5,           PC6,           PC7,           PC8,           PC9,          PC10,          PC11,          PC12,          PC13,          PC14,          PC15, ... 
min values  : -1.525414e+03, -8.294717e+02, -1.597420e+03, -2.924969e+02, -4.018654e+02, -9.054122e+01, -4.005998e+01, -1.802074e+01, -2.699063e+01, -2.808965e+01, -1.337488e+01, -1.268085e+01, -1.224565e+01, -1.060565e+01, -4.378304e+00, ... 
max values  :  1.589643e+03,  1.964028e+03,  3.989713e+02,  3.699300e+02,  1.310118e+02,  7.833018e+01,  6.450310e+01,  2.629923e+01,  3.463626e+01,  2.732504e+01,  1.044373e+01,  1.601244e+01,  3.073991e+01,  5.426831e+00,  7.680870e+00, ... 
1

There are 1 answers

1
maRtin On
#sample data

data(rlogo)
ggRGB(rlogo, 1,2,3)
pcaRasters <- rasterPCA(rlogo)

Access the values:

 getValues(pcaRasters$map)
                  PC1           PC2         PC3
   [1,] -118.27810276  -4.054375764  0.726071167
   [2,] -118.27810276  -4.054375764  0.726071167
   [3,] -118.27810276  -4.054375764  0.726071167

Plot rasters:

plot(pcaRasters$map)

PCA Plots

Save to disk:

writeRaster(pcaRasters$map, "filename.tif")