Doubled question (https://stackoverflow.com/questions/44726971/changing-a-raster-stack-projection-in-r?noredirect=1#comment76436491_44726971)

I have a NetCDF (nc) file I'm using to create a Raster stack in R. The coord. ref. is listed as "NA" when I load it in, but plots as Polar Stereographic.

When I try set its CRS, it lists that it has changed in the Raster info, but still plots incorrectly. How do I change the CRS to WGS1984 and plot it as Equirectangular?

I need to crop it using lat/long coordinates etc, so can't really leave it as stereographic projection.

Data is available here https://drive.google.com/file/d/0Bz0W7Ut_SNfjeE9ObXpySzJ5UWs/view

Code used is:

  library (raster)

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

(I can provide images of plots etc if you don't want to run the above)


You need to use the projectRaster() function to reproject the data rather than simply assigning a crs. First you should assign the dataset's native crs (assuming you know it, try checking the metadata or run gdalinfo on the on disk file) and then reproject to WGS84. Be careful to choose an appropriate resampling option. If none of the available options suit, you may be better off reprojecting using gdalwarp (in fact, this will probably be a lot faster, raster reprojection in R is pretty slow for large datasets).

Edit: having had a closer look at your data, I don't know if it can be reprojected the way you want. The 'lat' and 'long' values in the file aren't - they're just grid coords (c(1,1) etc) from top-left, so there's no proper 'from' data. Suggest you contact the dataset originators, the full metadata for your file is, I think, here - https://data.nodc.noaa.gov/cgi-bin/iso?id=gov.noaa.ncdc:C00756 and it has some contact names in it.

| improve this answer | |

Thanks for the help obrl_soil, it prompted me to solve it using CDO (Climate Data Operators), using the reprojection function.

For anyone else running into problems with NetCDF files using horrible grids, I highly recommend CDO, whereby you can change it to the grid of another .nc file using the -remapbil function. Solved here: CDO Solution

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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