I have a few .tif rasters (ELEV and POP) projected in long/lat, but I would like the CRS and extent to be the same as a shapefile I have (STUDYAREA), for example, my study area lies mostly in UTM16 so I want that to be in the crs for all objects. Also, I would like them all to have a 1000*1000m resolution.
I first make sure that the extent is the same as the shapefile, as I've learned that working with objects with a different extent will give an error. Here is how I try to reach my goal:
create object to adapt other objects extent to (needs to be equal to extent of STUDYAREA)
studyarea <- spTransform(studyarea,CRSobj= "+proj=utm +zone=16 +datum=WGS84 +units=m + no_defs")
areaextent <- extent(studyarea)
projection <- "+proj=utm +zone=16 +datum=WGS84 +units=m +no_defs"
elev <- raster("Gtopo30/Gtopo30.TIF")
newelev <- setExtent(elev,areaextent)
elev <- projectRaster(newelev,res=1000,crs=projection)
pop <- raster("griddedpop/gpw.tif")
pop <- setExtent(elev,areaextent,keepres=FALSE)
pop <- projectRaster(pop,crs=projection)
But when using the ProjectRaster function, I run into very similar errors for both raster projections:
elev <- projectRaster(newelev,res=1000,crs=projection)
Error in projectExtent(from, projto) : cannot do this transformation
In addition: Warning message:
In rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[, :
704 projected point(s) not finite