-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReproject_Rasters.R
More file actions
33 lines (27 loc) · 1006 Bytes
/
Reproject_Rasters.R
File metadata and controls
33 lines (27 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Creating a new branch on github
#made an edit on branch createGitHubBranch-onlocal from local
#made an edit on github
require(terra)
require(rgdal)
rasterdir<- "S:\\GCMC\\tmp\\PRISM_Daily"
files<-list.files(path = rasterdir ,pattern = "*.tif$",all.files = TRUE,full.names = TRUE,recursive = TRUE,include.dirs = FALSE)
head(files)
testrast<-rast(files[1])
plot(testrast)
crs(testrast,proj=TRUE)
terra::nlyr(testrast)
clippinggeometry<- "S:\\GCMC\\Data\\Massachusetts\\statewide_viewer_fgdb\\MassGIS_Vector_GISDATA.gdb"
clippinglayer<- "OUTLINE_POLY"
clippingpoly<-vect(readOGR(dsn=clippinggeometry,layer=clippinglayer) )
crs(clippingpoly,proj=TRUE)
for(r in files){
raster<-rast(r)
raster<-terra::project(x=raster,crs(clippingpoly))
crs(raster,proj = TRUE)==crs(clippingpoly,proj = TRUE)
print(paste("trying to write raster: ", r,sep = ""))
writeRaster(
x = raster,
filename = r,
names = names(raster),overwrite=TRUE)
print(paste("Finished writing raster: ",r,sep=""))
}