I have a land use land cover (lulc) raster in WGS84 coordinate system shown below

class       : RasterLayer 
dimensions  : 59575, 57541, 3428005075  (nrow, ncol, ncell)
resolution  : 0.000509, 0.000509  (x, y)
extent      : 68.12366, 97.41203, 6.754034, 37.07771  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source :<address path> 
names       : lulc raster 
values      : 1, 19  (min, max)

I have another raster in MODIS sinusoidal projection below which I will refer to as the foundation raster

class       : RasterLayer 
dimensions  : 7276, 8330, 60609080  (nrow, ncol, ncell)
resolution  : 463.3127, 463.3127  (x, y)
extent      : 6508617, 10368012, 751956.5, 4123020  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs 

data source : names : foundation raster values : 2, 3 (min, max)

I have to do analysis with both rasters and cannot change the projection of the foundation raster. So I reprojected the lulc raster as below

lulc_projected<-projectRaster(lulc raster, res=res(foundation raster),crs=crs(foundation raster), method='ngb') #categorical classes; hence ngb.

The resulting raster lulc_projected is completed without errors and aligns perfectly with the foundation raster when viewed in QGIS and Arc as below.

 class       : RasterLayer 
 dimensions  : 7258, 10179, 73879182  (nrow, ncol, ncell)
 resolution  : 463.3127, 463.3127  (x, y)
 extent      : 6055308, 10771368, 744727.8, 4107452  (xmin, xmax, ymin, ymax)
 coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : lulc projected 
values      : 1, 19  (min, max)

However, the nrows and ncols differ not allowing me to continue with analysis such as mask() in R. More confusing is that the resolution matches. I know I can change the extent by using extent(lulc_projected)<-extent(foundation raster).

As a solution I resampled the lulc_projected raster as below

lulc_projected_resampled<-resample(lulc_projected,foundation_raster, method='ngb')

After this the rasters match perfectly i.e. extent, resolution, coordinate system and nrows and ncols. But when I view both the lulc_projected_resampled and foundation raster, there is a shift by about 40 km. Refer to this post for a visual example of this shift and comments (with no solution).

So, firstly, why is projectRaster() not giving a raster with the same number of rows and columns? The product at this stage i.e. lulc_projected aligns perfectly with the foundation raster, however I cannot proceed with more analysis in R, such as stack() and mask() because the nrows and ncols do not match.

Secondly, is this not the workflow? If not, what is the workflow to project a raster to match another?

  • 1
    Use the foundation raster as the target, so everything matches. lulc_projected <-projectRaster(lulc_raster, foundation_raster) (but also investigate other ways of comparing, this is very brute force and a complete remodelling of the lulc data).
    – mdsumner
    Aug 15, 2018 at 2:32
  • @mdsumner How is providing the target raster different from just specifying the crs() and res() part of the syntax with it? And what is brute force? What you are suggesting or what I have done?
    – tg110
    Aug 15, 2018 at 2:35
  • 2
    The extent is different (crs and res don't define an extent, that is derived from the source data if you don't provide it). (The other, projectRaster is remodeling the data (a bit brute force), it's not relevant to your question, it's just general advice to perhaps consider other workflows)
    – mdsumner
    Aug 15, 2018 at 4:52
  • @mdsumner did as you suggested i.e. projectRaster(lulc_raster, foundation_raster), same results as above i.e. nrows and ncols still don't match, but res and crs match.
    – tg110
    Aug 15, 2018 at 13:32
  • 2
    @mdsumner- Sorry! I tried it again, this time clearing my workspace and it worked! On specifying the foundation raster as the to raster, instead of using the crs() and res(), the resulting lulc projected has the correct nrows, ncols, extent, res and crs. Thank you!
    – tg110
    Aug 18, 2018 at 15:37

1 Answer 1


If you re-project an image it is ofter also rotated. Rotation is making the envelope of the image larger as you can see from this image.

enter image description here

In this case it is not possible to keep both the pixel size and number or rows and columns at the same time. Maintaining the resolution is of course impossible also if re-projection is also changing the units for example from degrees into meters.

  • So basically I cannot reproject the lulc raster to match the foundation raster maintaining resolution, crs, nrows, ncols, extent etc, to continue analysis in R?
    – tg110
    Aug 15, 2018 at 13:58
  • Well, if your analysis can't just use overlapping pixels where they can be found I guess that you must re-project into desired crs and clip the image to make the nrows and ncols to match.
    – user30184
    Aug 15, 2018 at 14:33

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.