0

This thread Reprojecting raster from lat/lon to UTM in R? was of no help to me.

I have the following raster which I first need to create in lat/long in order to crop it to rworldmap. However, I then need to work in UTM. How do I convert the raster to UTM? The above thread just assigns the UTM projection from the start, which I know how to do. I just don't know how to convert back.

# Make raster layer of study area
ras = raster(ext=extent(-70, -55, -60, -38), res=c(0.01,0.01)) 
#give all ponints a "1"
ras[] <- 1
#project the grid to lat/long
projection(ras) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

load land

library(rworldmap) worldMap <- getMap(resolution = "high") projection(worldMap) <- CRS(proj4string(ras))

#crop and mask raster by land r2 <- crop(ras, worldMap) r3 <- mask(r2, worldMap, inverse = T) plot(r3)

#convert raster back to UTM ....??

Vince
  • 20,017
  • 15
  • 45
  • 64

1 Answers1

1

Use projectRaster function with crs argument. You can also use terra since it's faster and projection takes a lot of time. But with raster library:

r3utm <- projectRaster(from = r3, crs = "+init=epsg:32720")

plot(r3utm)

enter image description here

I know this is an example, but UTM zones are for 3º longitude extent (you can create custom TM projections if your data falls between two zones). For this case, the raster is too wide for UTM projections (15º longitude extent). Think about it

aldo_tapia
  • 13,560
  • 5
  • 30
  • 56
  • Thanks very much, this works perfectly! and thanks for the pointer regarding UTM zones, I will give this some thought – user205185 May 07 '22 at 11:03