library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin#origin(target) <- c(-119, 32.9583) # Commented for further 'experiments' >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif'))``` library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif'))``` library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) #origin(target) <- c(-119, 32.9583) # Commented for further 'experiments' >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif'))``` The new imageIn gray "test raster", raster comparisonin yellow "original raster".
[![In grey target, in color source][1]][1]
[![raster][2]][2]The new image, raster comparison.
In gray "test raster", in yellow "original raster".
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif')) [1]: https://i.sstatic.net/jVvWY.png [2]: https://i.sstatic.net/nT6kk.png [3]: https://i.sstatic.net/7hRTb.png``` The new image, raster comparison.
[![In grey target, in color source][1]][1]
[![raster][2]][2]
In gray "test raster", in yellow "original raster".
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif')) [1]: https://i.sstatic.net/jVvWY.png [2]: https://i.sstatic.net/nT6kk.png [3]: https://i.sstatic.net/7hRTb.png In gray "test raster", in yellow "original raster".
The new image, raster comparison.
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif'))```
The new image, raster comparison.
[![In grey target, in color source][1]][1]
[![raster][2]][2]
In gray "test raster", in yellow "original raster".
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif')) [1]: https://i.sstatic.net/jVvWY.png [2]: https://i.sstatic.net/nT6kk.png [3]: https://i.sstatic.net/7hRTb.png In gray "test raster", in yellow "original raster".
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif')) The new image, raster comparison.
[![In grey target, in color source][1]][1]
[![raster][2]][2]
In gray "test raster", in yellow "original raster".
library(raster) library(sp) library(rgdal) library(ggplot2) library(itertools) path = '~/path' spath = '~/path1' source <- raster(file.path(path,'file.tif')) >source Summary of origin raster: class : RasterLayer dimensions : 467, 805, 375935 (nrow, ncol, ncell) resolution : 0.04166667, 0.04166667 (x, y) extent : -119, -85.45833, 13.54167, 33 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : ~/path/file.tif names : raster_name >summary(source) raster_name Min. 5.516960 1st Qu. 9.151464 Median 10.334464 3rd Qu. 12.149574 Max. 17.560150 NA's 0.000000 # How the raster should be target <- raster(nrow=2335, ncol=4025, extent(source), crs(source)) origin(target) <- c(-119, 32.9583) >target class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 > summary(target) layer Min. NA 1st Qu. NA Median NA 3rd Qu. NA Max. NA NA's NA # Project source raster to target raster by bilinear dest <- projectRaster(source, target, method='bilinear', tolerance=0.0001) >dest class : RasterLayer dimensions : 2335, 4025, 9398375 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -119, -85.45833, 13.54163, 32.99997 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 source : memory names : raster_name values : 5.517167, 17.58864 (min, max) > summary(dest) raster_name Min. 5.517167e+00 1st Qu. 9.154074e+00 Median 1.034819e+01 3rd Qu. 1.217350e+01 Max. 1.758864e+01 NA's 5.232403e+06 # Write new raster file to a path writeRaster(flip(dest, direction='y'), file.path(spath, 'target.tif')) [1]: https://i.sstatic.net/jVvWY.png [2]: https://i.sstatic.net/nT6kk.png [3]: https://i.sstatic.net/7hRTb.png