0

I have one elevation raster and one set of data points that I would like to be in the same projected coordinate system. When I use projectRaster, the extent of the layer becomes completely different and no longer lines up with the other data points.

dat <- read.csv(file = "ebd.csv")
elev <- raster("elev30mpa2.tif")

#Turning points into spatial object
ebdpoint <- st_as_sf(dat, coords=c("longitude","latitude"))

#Set coordinate system
ebdpoint <- st_set_crs(ebdpoint, "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs")
> head(ebdpoint)
Simple feature collection with 6 features and 35 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: -78.1582 ymin: 40.4502 xmax: -76.7758 ymax: 41.96633
CRS:            +proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs

#This is the extent and CRS of the raster before projecting
> elev
class      : RasterLayer 
dimensions : 14412, 25212, 363355344  (nrow, ncol, ncell)
resolution : 0.0002777778, 0.0002777778  (x, y)
extent     : -81.00167, -73.99833, 38.99833, 43.00167  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=NAD83 +no_defs 
names      : elev30mpa2 
values     : -86, 1332  (min, max)

#Project Raster
elev <- projectRaster(elev, crs = "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs") 
class      : RasterLayer 
dimensions : 15007, 25939, 389266573  (nrow, ncol, ncell)
resolution : 23.4, 30.8  (x, y)
extent     : -20069.59, 586903, 4316447, 4778663  (xmin, xmax, ymin, ymax)
crs        : +proj=utm +zone=18 +datum=NAD83 +units=m +no_defs
names      : elev30mpa2 
values     : -86, 1332  (min, max)

I desperately need my data to be in the same projected coordinate system. I am not sure if the issue has to do with the fact that it extends across 2 UTM zones (17 and 18) or because I am shifting the elevation layer from a geographic to projected coordinate system (I need it to be projected so I can use later functions in meters).

fin
  • 33
  • 3
  • The issue is that you are assigning a projection to your point data but, not actually projecting it whereas you are, in fact, reprojecting your raster. Try using `st_transform`, rather than `st_set_crs`, on your vector data and the two should line up. You will need to use `st_set_crs` to assign the current projection to your vector point data. It is likely "+proj=longlat +datum=WGS84" before reprojecting. – Jeffrey Evans Sep 14 '20 at 23:15
  • You were correct, using st_set_crs and then st_transform fixed the issue. Thank you! – fin Sep 15 '20 at 15:10

0 Answers0