I have a 500m sinusoidal raster that I converted it into an approximately equivalent 500m WGS84 using the
raster package in R by using the following script:
library (raster) library(maptools) #Load the tif file TIF <- raster("~/TIF.tif") plot(TIF) # Define the SRS of the original tif SRS <- "+proj=sinu +lan_0=0 +x_0=0 +y_0=0 +R=631007.181 +units=m +no_defs" #Define the Lat/Long SRS of the output Tif in WGS84 llcrs <- "+proj=longlat +ellps=WGS84 +datum=WGS84" #Load original tif data df <- as.data.frame(TIF, xy=TRUE) #Define Transform rll <- projectRaster(TIF,crs = llcrs) #ras_sinu <- raster(nrow=391, ncol=695, ext=extent(-9031818, 4773511, -870816, 4954666), crs=incrs) #rs <- rasterImage(w, ras_sinu) plot(rll) WGS84 <- raster("~/WGS84.tif") plot(WGS84)
Next I checked whether the number of rows and columns match or not?
summary(values(TIF)) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 0.0 25.0 50.0 50.5 75.0 100.0 230368 summary(values(WGS84)) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 0.0 26.0 51.0 50.5 76.0 100.0 454803 table(is.na(match(values(TIF),values(WGS84)))) FALSE 271745 ncell(TIF) 271745 ncell(WGS84) 496125 ncell(TIF) - ncell(WGS84) -224380 sum(is.na(TIF)) - sum(is.na(WGS84)) -224435 res(TIF) 463.3127 463.3127 res(WGS84) 0.00577 0.00417
I was checking answers to similar questions and it was mentioned after reprojections, the number of pixels change, hence that is why I am seeing a difference between the two rasters. This I guess means that the resolution of both the rasters is different as well. Is there a way in R to resolve this issue in R (i.e. the reprojected raster in WGS84 has a resolution approximate to 500m)?