[GIS] Projecting a MODIS SST netcdf file in R

modisrraster

I've downloaded monthly SST data (11u, nighttime) for July 2014.

https://oceancolor.gsfc.nasa.gov/cgi/l3?per=MO&prd=NSST_sst.nc&sen=A&res=4km&num=24&ctg=Standard&date=1Jul2014

The data is stored as a NetCDF (.nc) file. So, I've used the following code to import the file into R.

library(ncdf4)
library(raster)
sst<-raster(path.expand("~/Remote Sensing/SST/SST_July2014_L3_MO_4km.nc"))

Next, I checked the file.

sst 

This was the output:

class       : RasterLayer 
dimensions  : 4320, 8640, 37324800  (nrow, ncol, ncell)
resolution  : 0.04166667, 0.04166667  (x, y)
extent      : -180, 180, -90.00001, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : ~\Remote Sensing\SST\SST_25June2016_L3_8D_4km.nc 
names       : Sea.Surface.Temperature 
zvar        : sst 

Does the raster() function in ncdf4 automatically project the file? I'm confused because the MODIS SST metadata states that the projection is Equidistant Cylindrical.
Sorry if this question is very elementary, but this is my first time working with rasters or MODIS data.

EDIT

I successfully specified the projection using the code provided by @Phil

sst<-raster(path.expand("~/Remote Sensing/SST/SST_July2014_L3_MO_4km.nc"))
sst@crs <- sp::CRS("+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 +b=6371007 +units=m +no_defs")

My other data files are in latlong WGS84, so I reprojected the SST raster.

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

I then tried to crop the bathymetry raster by the extent of my polygon layer called 'polygonsp.' (code for polygonsp below)

library(sp)
vertices<-c(-131.8246,-131.8246,-127.6479,-127.6479,50.14335,54.53591,54.53591,50.14335)
vertices<-matrix(vertices,4,2)
polygon<-Polygon(vertices)
polygono<-Polygons(list(polygon),1)
polygonsp<-SpatialPolygons(list(polygono))
proj4string(polygonsp)<-CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")

sstcrop<-crop(sst,polygonsp)

However, I now get an error that says "Error in .local(x, y, …) : extents do not overlap".

This code worked for me before I added the line specifying the projection of the SST data as equidistant cylindrical. Any idea what is happening?

Best Answer

It doesn't look like there's an associated projection with the file, and the default behaviour of raster::raster() when the CRS is missing is (taken from the function documentation, ?raster):

If this argument is missing, and the x coordinates are withing [sic] -360 .. 360 and the y coordinates are within -90 .. 90, "+proj=longlat +datum=WGS84" is used.

So it looks like WGS84 has been assigned for you. To change it, simply use sp::CRS() and assign it to the @crs slot:

sst@crs <- sp::CRS("+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6371007 +b=6371007 +units=m +no_defs")

CRS definition taken from spatial reference.

And the result:

rasterVis::levelplot(sst)

enter image description here