Guest User

Untitled

a guest
Nov 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # loading the bands
  2. B2 <- raster("./Data/LC08_L1TP_015053_20160413_20170223_01_T1_B2.tif")
  3. B3 <- raster("./Data/LC08_L1TP_015053_20160413_20170223_01_T1_B3.tif")
  4. B4 <- raster("./Data/LC08_L1TP_015053_20160413_20170223_01_T1_B4.tif")
  5. B8 <- raster("./Data/LC08_L1TP_015053_20160413_20170223_01_T1_B8.tif")
  6.  
  7. # then I want to clip the rasters to the study site
  8. # first I have to load the raster of the Costa Rica provinces
  9. shape <- readOGR("./Data/gadm36_CRI_1.shp")
  10.  
  11. # Then add that projection to the shapefile
  12. shape.proj <- spTransform(shape, CRS(proj4string(B2)))
  13. proj4string(shape.proj)
  14.  
  15. # Combining the two provinces that I want : Heredia and Alajuela
  16. p1 <- shape.proj[shape.proj$NAME_1=='Heredia', ]
  17. p2 <- shape.proj[shape.proj$NAME_1=='Alajuela', ]
  18. p2$NAME_1 <- NULL
  19. x <- bind(p1, p2)
  20.  
  21. # Crop raster by extent of shapefile
  22. studysiteB2 <- mask(crop(B2, x), x)
  23. studysiteB3 <- mask(crop(B3, x), x)
  24. studysiteB4 <- mask(crop(B4, x), x)
  25. studysiteB8 <- mask(crop(B8, x), x)
  26.  
  27. # now stack the Bands together
  28. image <- stack(studysiteB2,studysiteB3,studysiteB4,studysiteB8)
  29.  
  30. Error in compareRaster(x) : different extent
  31.  
  32. extent(studysiteB2)
  33.  
  34. class : Extent
  35. xmin : 710385
  36. xmax : 860325
  37. ymin : 1087635
  38. ymax : 1225725
  39.  
  40. extent(studysiteB8)
  41.  
  42. class : Extent
  43. xmin : 710392.5
  44. xmax : 860332.5
  45. ymin : 1087628
  46. ymax : 1225733
Add Comment
Please, Sign In to add comment