29

I have a layer with coord. ref. : NA.

How can I assign coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 to coord. ref. : NA?

class       : RasterLayer 
dimensions  : 127, 146, 18542  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : -122.39, -120.93, 36.72, 37.99  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : C:\2012Tif\2012ASC5min_ppt_spas1306_0001_20121222_0005_UTC.asc.tif 
names       : X2012ASC5min_ppt_spas1306_0001_20121222_0005_UTC.asc 
values      : 0, 0.0782172  (min, max)


class       : RasterLayer 
dimensions  : 180, 240, 43200  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : -123.305, -120.905, 36.705, 38.505  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +to wgs84=0,0,0 
data source : C:\Users\nahmlee\Documents\1998Test.tif 
names       : X1998Test 
values      : 0, 0.07884484  (min, max)

1 Answer 1

42

Use crs function. If r is your raster:

crs(r) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 

Of course, you need to be sure it is the correct projection for your raster.

4
  • 19
    The result is the same, but this version is easier adaptable to other reference systems: crs(r) <- CRS('+init=EPSG:4326') if you know the EPSG number.
    – Julian
    Commented Nov 20, 2017 at 14:49
  • 2
    This should be CRS("+init=epsg:28992") for rgdal.
    – mace
    Commented Mar 5, 2019 at 14:00
  • The correct and full syntax shouldt be 'proj4string(r) <- CRS("+init=epsg:5678")'
    – David
    Commented Jan 6, 2021 at 16:15
  • 6
    Note that PROJ4 is on its way out. The PROJ6 way would be raster::crs(r) <- "EPSG:4326"
    – Mikko
    Commented May 27, 2021 at 15:01

Your Answer

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

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