PCA using raster datasets in R

后端 未结 6 1646
别那么骄傲
别那么骄傲 2021-01-18 10:48

I have several large rasters that I want to process in a PCA (to produce summary rasters). I have seen several examples whereby people seem to be simply calling prcomp or pr

6条回答
  •  臣服心动
    2021-01-18 11:12

    The above method is not working simply because prcomp does not know how to deal with a raster object. It only knows how to deal with vectors, and coercing to vector does not work, hence the error.

    What you need to do is read each of your files into a vector, and put each of the rasters in a column of a matrix. Each row will then be a time series of values at a single spatial location, and each column will be all the pixels at a certain time step. Note that the exact spatial coordinates are not needed in this approach. This matrix serves as the input of prcomp.

    Reading the files can be done using readGDAL, and using as.data.frame to cast the spatial data to data.frame.

提交回复
热议问题