0

I'm working with landsat-7 image data(TIF files) from which you can download from USGS earth explorer. The TIF files come in 9 images so I want to be able to change each of the resolution of the images to 10x10, and then crop the image to a specific area that I'm interested in and then re-plot each of the images. Is this possible in R? I've included some actual/pseudo-code of my attempt for one specific image. As the exact images are too large to be uploaded, I've included an area where the images can be downloaded - but rather, any image example would work for me to go by.

library(raster)
library(rgdal)
grey <- raster("image") ##loading image
gr.disaggregate <- disaggregate(gr.disaggregate, fact=3) ##turning into 10x10 from 30x30
r.pts <- rasterToPoints(gr.disaggregate, spatial=TRUE) ##This keeps running forever until R aborts. 
## if it did my thought process would be the following
geo.prj <- "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" 
r.pts <- spTransform(r.pts, CRS(geo.prj)) 
r.pts@data <- data.frame(r.pts@data, long=coordinates(r.pts)[,1],
                         lat=coordinates(r.pts)[,2])                         
ext <- extent(xmin, xmax, ymin, ymax)
r.pts2 <- crop(r.pts, ext) 
##I would then want to replot the resolution increased/cropped image. 

Update: Any sample image that I'm exactly using can be found Here. Updated annotations to accurately describe problems.

Would appreciate the assistance, thank you!

Dangerous Game
  • 103
  • 1
  • 1
  • 6
  • Can you provide a reproducible example? what are the properties of `gr.disaggregate`? what error message you are receiving? – Majid Dec 17 '19 at 23:38
  • gr.disaggregate would be a 10x10 resolution image as opposed to originally being 30x30. There is no error message, it just keeps running(R aborts and shutdowns after a while). – Dangerous Game Dec 18 '19 at 00:46
  • You do not need to convert the gr.disaggregate raster to points to be able to crop it. Just use crop( gr.disaggregate, extent) (being careful to define the extent in the same coordinate system of the raster). – lbusett Dec 18 '19 at 23:00

1 Answers1

0

To upscale or downscale (change resolution) you can use aggregate or disaggregate function within r
as an example

library(raster)

grey <- raster("image") ##loading image
#this function will give you the resolution of your raster
res(grey)

#disaggregate/downscale from 30 x 30 resolution to 10 x 10 (factor = 3)
grey_agg <- disaggregate(grey, fact=3)

##this function will give you the resolution of your raster after changing resolution
res(grey_agg)

This is based on this solution
As per the cropping, you can use crop or mask functions

#load the required shapefile (namely as shp)
grey_cropped <- crop(grey_upscaled, shp)
  • I've performed most of this as per my code above. I've edited my question to maybe give a better idea of what I'm trying to accomplish – Dangerous Game Dec 18 '19 at 00:54
  • I gathered that your problem is in `rasterToPoints` function as it takes forever to run. Have you tried running this outside the Rstudio? maybe, skip the rastertopoint function and save the raster as an ascii file, then read that as data points. – Mohamed Ismaiel Ahmed Dec 18 '19 at 22:24