1

I am trying to reproject a raster and change its resolution with the function projectRaster() in R.

I looked up at the R documentation website (https://www.rdocumentation.org/packages/raster/versions/2.5-8/topics/projectRaster) and found the following code for it:

projectRaster(from, to, res, crs, method="bilinear",  alignOnly=FALSE, over=FALSE, filename="", ...) 

I tried to replicate it using the following code:

newproj <- "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m"

projectRaster(lradin, 94.65157575, crs = newproj, +datum=WGS84, method="bilinear", filename="lradin_1", overwrite = TRUE)

Here, lradin is the raster object, 94.65157575 is the resolution that I am changing to (in meters).

My original raster (lradin) is in WGS1984 coordinate system with a resolution of 0.1° x 0.1° and I need to change it in Asia North Albers Equal Area Conic projection with a resolution of 94.65157575 meters.

When I run the code I get the following error:

Error in projectRaster(r, a, 94.65157575, crs = newproj, method = 
"bilinear",  : 
 output projection is NA

I am not understanding what the error is. I feel I have written the code according to the documentation website. Could anyone suggest something ?

  • 1
    What about the ", +datum=WGS84" in your code? I think that shouldn't be there. Maybe you delete this and give it a try. – blabbath Aug 17 '17 at 9:47
  • If you're trying to get the same resolution and CRS than another raster just simply use projectRaster(lradin, rasterWithDesiredResolution) – aldo_tapia Aug 17 '17 at 10:49
  • @poelling - Nope.. II deleted the +datum=WGS84 in second lne but it didnt work. – Sahadeep Aug 17 '17 at 12:42
  • @aldo_tapia - I have a raster which I have converted in the albers equal area conic projection in ArcMAP. I will give it a try. – Sahadeep Aug 17 '17 at 12:43
  • Also changing the +lon_0=-96 to +lon_0=96 may help if the data is in Asia. – mkennedy Aug 17 '17 at 20:10
1

In that case, this is important to specify what are the options of your function by declaring them clearly. You need to say that your resolution is the resolution. The order of parameters is not taken into account. Only the first argument is known to be the raster. And remove the datum which is already in your CRS:

lradin_aea <- projectRaster(lradin, res = 94.65157575, crs = newproj, method="bilinear", filename="lradin_1", overwrite = TRUE)

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.