Search code examples
rraster

Projecting raster between lat/lon and laea


I am having trouble projecting a North America DEM from laea to lat/lon format. I know lat/lon isn't always the best for raster work but I'm working with the dismo package and everything from that and worldclim comes in lat/lon format, and it's too much data to deal with spTransform and projectRaster on my machine - so I'm stuck going the other way.

Here's the DEM I'm using. I've named the raster object mydem.

Its projection info is: +proj=laea +lat_0=-100 +lon_0=6370997 +x_0=45 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0

The worldclim data (raster object biocl.complete) projection info is: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

When I try to use...

 mydem.lonlat <- projectRaster(mydem,
                          crs = proj4string(biocl.complete))

... my computer dedicates 100% CPU power to RSession and the memory allotment quickly skyrockets, requires compressed memory, and then I have to kill the process. I'm confused because the actual DEM layer is only 43 MB but something is happening in the background I don't understand.

Does anyone know a good approach to deal with this?

I've explored the following reference but I'm not getting an error, my computer just seems to be sh*tting the bed here. Projection Question

Alignment issues (followup to Hijmans' solution): DEM Bioclim

Final edit: R does not read in the projection information for the above DEM correctly, so reprojecting naturally causes a major issue. See this discussion for a detailed solution to the projection issue.


Solution

  • What you want to do is:

    mydem.lonlat <- projectRaster(mydem, biocl.complete, filename='mydemlonlat.tif')
    

    That is, provide an 'example' raster object as a template, such that you not only get the CRS desired, but also the extent and resolution. Also note that I added a filename argument such that the results are saved, and you do not have to do this repeatedly.

    The above may or may not solve the memory problem. To solve that, try to set the maximum memory used with rasterOptions.

    rasterOptions(chunksize=1e+06, maxmemory=1e+07) 
    

    And or with:

    rasterOptions(todisk=TRUE) 
    

    Check

    rasterOptions()