I am trying to create a large (spatial?) DataFrame for use in subsequent multivariate statistical analyzes (e.g. PCA) from a set of 60 raster files.
I am somewhat new to working with spatial data in R and don’t understand how spatial coordinate data is saved or not stored in data files.
I used the following code to read in raster files and created a stack from them:
library(raster)
library(sp)
library(rgdal)
library(spatial.tools)
setwd("C:/Users/...../data/")
files <- list.raster.files(path = getwd(), pattern = ".tif$", recursive =FALSE, return_rasters = FALSE, return_bbox = FALSE)
mystack <- stack(files$raster_files)
mystack
Why did R lose spike help when I imported files? When I look at raster files in ArcGIS, they definitely have projection information.
I tried to manually apply the projection this way:
#first define the projection using the proj4 syntax
projection <- "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"
#then apply the projection to the rasterStack
projectRaster(files, projection, method = bilinear, filename = "STACKprj")
, ( "mystack" ) NA , ..
STACKprj <- projection(mystack)
.
- ? !