0

Looking to the tutorial in http://bleutner.github.io/RStoolbox/rstbx-docu/rasterPCA.html, in which they show how to do a Principal Component Analysis on raster data, I was wandering whether is it possible to convert the ggRGB plot in a raster file.

Do you have any suggestion?

closed as off-topic by Andre Silva, ArMoraer, whyzar, Kersten, MerseyViking Jan 11 '17 at 17:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – Andre Silva, ArMoraer, whyzar, Kersten, MerseyViking
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Slot map inside PCA result is a RasterBrick:

library(RStoolbox)
library(ggplot2)
library(reshape2)

data(rlogo)

set.seed(25)

rpc <- rasterPCA(rlogo)

class(rpc$map)

[1] "RasterBrick"
attr(,"package")
[1] "raster"

You can save this slot as a raster with raster package:

library(raster)

writeRaster(rpc$map, "rpc.tif")

You can set bylayer = FALSE if you want a multi-layer raster as output, default is TRUE.

Also, read function description:

Principal Component Analysis for Rasters

Description
Calculates R-mode PCA for RasterBricks or RasterStacks and returns a RasterBrick with multiple layers of PCA scores.

Not the answer you're looking for? Browse other questions tagged or ask your own question.