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
....??

1 Answer 1

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

1
  • Thanks very much, this works perfectly! and thanks for the pointer regarding UTM zones, I will give this some thought
    – user205185
    May 7, 2022 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.