I received 3 .mat files that each contain several daily maps. I need to take them and get them into ArcMap (10.2 if that matters) as a .tif with spatial information. I have already used the R.matlab package to read the .mat files and successfully did it for one day, however I do not want to have to write hundreds of lines of code to repeat it for the remaining days. Here is my successful code:
library(R.matlab)
library(raster)
library(sp)
library(rgdal)
setwd("C:/Users/Heidi Church/Documents/Thesis/FSLE")
FSLE2006mat <- readMat("FSLEheidi2006.mat")
FSLE2007mat <- readMat("FSLEheidi2007.mat")
FSLE2008mat <- readMat("FSLEheidi2008.mat")
#Test on single day in 2006
x <- raster(FSLE2006mat$F2006812, xmn=152, xmx=155.5, ymn=47.5, ymx=50.5, crs="+proj=longlat +datum=WGS84")
plot(x, xlab="Latitude", ylab="Longitude", xlim=c(152,155.5), ylim=c(47.5,50.5), main="Submesoscale Fronts: August 12, 2006")
writeRaster(x, filename="FSLE_20060812.tif", format="GTiff", overwrite=TRUE)
I had tried doing both a for loop and lapply, however kept getting this error:
Error in .local(x, ...) : unused arguments (xmn = 152, xmx = 155.5, ymn = 47.5, ymx = 50.5, crs = "+proj=longlat +datum=WGS84")
Here are examples of each that I tried:
for (i in FSLE2006mat[1:16])
{
FSLE2006[i] <- raster(x=FSLE2006mat[i], xmn=152, xmx=155.5, ymn=47.5, ymx=50.5, crs="+proj=longlat +datum=WGS84")
}
FSLE2006 <- lapply(FSLE2006mat, (raster(x, xmn=152, xmx=155.5, ymn=47.5, ymx=50.5, crs="+proj=longlat +datum=WGS84")))
FSLE2006 <- lapply(FSLE2006mat, raster)
FSLE2006 <- lapply(FSLE2006mat[1:16], raster)
I am wondering how I can loop through all of the elements in the .mat list for each year, make them a raster with the spatial info noted, and write it to a .tif file to import into ArcGIS. I should also note that 1:16 is to only use the first 16 of 18 elements, as the last 2 are not needed.
str(FSLE2006mat$F2006812)