Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanscharf/0d7d499c8e5ac47e8fa96d92afba3899 to your computer and use it in GitHub Desktop.
Save ryanscharf/0d7d499c8e5ac47e8fa96d92afba3899 to your computer and use it in GitHub Desktop.
Landsat imagery test
username = '',
password = ''
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
bbox_ls <- clipping_bbox(-82.758605,27.631232,-82.732227,27.654636)
sres <- lsSearch(startDate = as.Date("01-01-2020", "%d-%m-%Y"),
endDate = as.Date("31-01-2020", "%d-%m-%Y"),
#pathrow = list(c(200, 31), c(200, 30)),
browseAvaliable = "Y",
region = st_as_sfc(bbox_ls),
AppRoot = wdir,
username = '',
password = '',
product = 'LSR_LANDSAT_8_C1')
lsPreview(sres, 1)
lsDownload(sres,
username = '',
password = '',
AppRoot = wdir,
untar = T)
wdir.ls8 <- file.path(wdir,"Landsat8")
files.ls8 <- list.files(wdir.ls8,
pattern = "\\.TIF$",
full.names = TRUE,
recursive = TRUE)[c(6,5,4)]
files.ls8.rgb <- stack(files.ls8)
qrange <- c(0.001, 0.999)
img.ls8.rgb <- varRGB(files.ls8.rgb[[1]],
files.ls8.rgb[[2]],
files.ls8.rgb[[3]],
qrange)
plotRGB(img.ls8.rgb)
bbox_sp <- as_Spatial(st_as_sfc(bbox_ls))
bbox_sp <- spTransform(bbox_sp, crs(img.ls8.rgb))
img.ls8.rgb_c <- crop(img.ls8.rgb,
extent(bbox_sp))
img.ls8.rgb_m <- mask(img.ls8.rgb,
bbox_sp)
test <- varRGB(img.ls8.rgb_c$red,
img.ls8.rgb_c$green,
img.ls8.rgb_c$blue
)
test <- stack(test)
#RGB <- cbind(getValues(test$red), getValues(test$green), getValues(test$blue))
plotRGB(test)
plotRGB(test, stretch = 'lin')
tmap_mode("view")
genPlotGIS(list(test)#,
#region = st_as_sfc(bbox_ls)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment