├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── R ├── RGISTools-package.R ├── RGISToolsOpts.R ├── data.R ├── defineAppRoot.R ├── genAskForYN.R ├── genCheckMD5.R ├── genCompositions.R ├── genFilterDF.R ├── genFilterStack.R ├── genGetDates.R ├── genMapViewSession.R ├── genMissionGetDates.R ├── genMosaicGdalUtils.R ├── genMosaicList.R ├── genPlotGIS.R ├── genSaveTSRData.R ├── genSmoothingCovIMA.R ├── genSmoothingIMA.R ├── jsonManage.R ├── ls7DownloadUSGS.R ├── ls7FolderToVar.R ├── ls7LoadMetadata.R ├── ls7Search.R ├── ls8DownloadUSGS.R ├── ls8FolderToVar.R ├── ls8LoadMetadata.R ├── ls8Search.R ├── lsCloudMask.R ├── lsDownSearch.R ├── lsDownload.R ├── lsEElogin.R ├── lsEarthExplorerdownload.R ├── lsEspaConnection.R ├── lsEspaDownloadOrders.R ├── lsEspaGetOrderImages.R ├── lsEspaGetOrders.R ├── lsEspaOrderImages.R ├── lsEspaUpdateOrders.R ├── lsGetPathRow.R ├── lsMosaic.R ├── lsPreview.R ├── lsQuery.R ├── lsRemoveMetadata.R ├── lsSearch.R ├── lsStartSession.R ├── lsUpdateEEDataSets.R ├── modCloudMask.R ├── modDownSearch.R ├── modDownload.R ├── modExtractHDF.R ├── modFolderToVar.R ├── modGetPathRow.R ├── modMosaic.R ├── modPreview.R ├── modSearch.R ├── senCloudMask.R ├── senDownSearch.R ├── senDownload.R ├── senFolderToVar.R ├── senGetPathRow.R ├── senMosaic.R ├── senPreview.R ├── senSearch.R ├── senSearchQuery.R ├── sysdata.rda ├── transform_multiple_proj.R ├── varEVI.R ├── varMSAVI2.R ├── varNBR.R ├── varNBR2.R ├── varNDMI.R ├── varNDVI.R ├── varNDWI.R ├── varRGB.R └── varSAVI.R ├── README.md ├── RGISTools.Rproj ├── data ├── ex.dem.navarre.rda ├── ex.navarre.rda └── ex.ndvi.navarre.rda ├── inst ├── CITATION ├── EE_data │ └── EE_DataSets.rds ├── ExNavarreVar │ ├── ExNavarreVar_MODIS_b01_1.tif │ ├── ExNavarreVar_MODIS_b02_1.tif │ ├── ExNavarreVar_MODIS_b03_1.tif │ ├── ExNavarreVar_MODIS_b04_1.tif │ ├── ExNavarreVar_MODIS_b05_1.tif │ ├── ExNavarreVar_MODIS_b06_1.tif │ └── ExNavarreVar_MODIS_b07_1.tif └── REFERENCES.bib └── man ├── RGISTools-package.Rd ├── ex.dem.navarre.Rd ├── ex.navarre.Rd ├── ex.ndvi.navarre.Rd ├── genCompositions.Rd ├── genFilterStack.Rd ├── genGetDates.Rd ├── genMosaicList.Rd ├── genPlotGIS.Rd ├── genSaveTSRData.Rd ├── genSmoothingCovIMA.Rd ├── genSmoothingIMA.Rd ├── getRGISToolsOpt.Rd ├── ls7FolderToVar.Rd ├── ls7LoadMetadata.Rd ├── ls7Search.Rd ├── ls8FolderToVar.Rd ├── ls8LoadMetadata.Rd ├── ls8Search.Rd ├── lsCloudMask.Rd ├── lsDownSearch.Rd ├── lsDownload.Rd ├── lsEspaDownloadOrders.Rd ├── lsEspaGetOrderImages.Rd ├── lsEspaOrderImages.Rd ├── lsEspaUpdateOrders.Rd ├── lsGetDates.Rd ├── lsGetPathRow.Rd ├── lsMosaic.Rd ├── lsPreview.Rd ├── lsRemoveMetadata.Rd ├── lsSearch.Rd ├── lsUpdateEEDataSets.Rd ├── modCloudMask.Rd ├── modDownSearch.Rd ├── modDownload.Rd ├── modExtractHDF.Rd ├── modFolderToVar.Rd ├── modGetDates.Rd ├── modGetPathRow.Rd ├── modMosaic.Rd ├── modPreview.Rd ├── modSearch.Rd ├── senCloudMask.Rd ├── senDownSearch.Rd ├── senDownload.Rd ├── senFolderToVar.Rd ├── senGetDates.Rd ├── senGetOrbit.Rd ├── senGetTile.Rd ├── senMosaic.Rd ├── senPreview.Rd ├── senSearch.Rd ├── setRGISToolsOpt.Rd ├── showRGISToolsOpt.Rd ├── varEVI.Rd ├── varMSAVI2.Rd ├── varNBR.Rd ├── varNBR2.Rd ├── varNDMI.Rd ├── varNDVI.Rd ├── varNDWI.Rd ├── varRGB.Rd └── varSAVI.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.md$ 5 | ^doc$ 6 | ^Meta$ 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | Meta 3 | # History files 4 | .Rhistory 5 | .Rapp.history 6 | 7 | # Session Data files 8 | .RData 9 | 10 | # Example code in package build process 11 | *-Ex.R 12 | 13 | # Output files from R CMD build 14 | /*.tar.gz 15 | 16 | # Output files from R CMD check 17 | /*.Rcheck/ 18 | 19 | # RStudio files 20 | .Rproj.user/ 21 | 22 | # produced vignettes 23 | vignettes/*.html 24 | vignettes/*.pdf 25 | 26 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 27 | .httr-oauth 28 | 29 | # knitr and R markdown default cache directories 30 | /*_cache/ 31 | /cache/ 32 | 33 | # Temporary files created by R markdown 34 | *.utf8.md 35 | *.knit.md 36 | 37 | # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html 38 | rsconnect/ 39 | 40 | # Project file and manual 41 | RGISTools.Rproj 42 | RGISTools.pdf -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Type: Package 2 | Package: RGISTools 3 | Title: Handling Multiplatform Satellite Images 4 | Version: 1.0.2 5 | Author: U Pérez - Goya [aut, cre] , 6 | M Montesino - SanMartin [aut] , 7 | A F Militino [aut] , 8 | M D Ugarte [aut] 9 | Maintainer: U Perez - Goya 10 | Description: Downloading, customizing, and processing time series of satellite images for a region of interest. 'RGISTools' functions allow a unified access to multispectral images from Landsat, MODIS and Sentinel repositories. 'RGISTools' also offers capabilities for customizing satellite images, such as tile mosaicking, image cropping and new variables computation. Finally, 'RGISTools' covers the processing, including cloud masking, compositing and gap-filling/smoothing time series of images (Militino et al., 2018 and Militino et al., 2019 ). 11 | URL: https://github.com/spatialstatisticsupna/RGISTools#RGISTools 12 | BugReports: https://github.com/spatialstatisticsupna/RGISTools/issues 13 | Depends: R (>= 3.5.0), raster, sf, tmap 14 | Imports: Rdpack, XML, xml2, utils, fields, urltools, rjson, rvest, tools, methods, curl, httr, mapview, sp, stars 15 | Suggests: rgdal 16 | RdMacros: Rdpack 17 | License: GPL-3 18 | Encoding: UTF-8 19 | LazyData: true 20 | RoxygenNote: 7.1.0 21 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | export(genCompositions,genSmoothingCovIMA,genFilterStack, 2 | genGetDates,senGetDates,lsGetDates,modGetDates, 3 | genMosaicList,genPlotGIS, genSaveTSRData,genSmoothingIMA,ls7FolderToVar, 4 | ls7LoadMetadata,ls7Search,ls8FolderToVar,lsMosaic, 5 | ls8LoadMetadata,lsRemoveMetadata,ls8Search,lsGetPathRow,lsPreview,modGetPathRow, 6 | lsDownload,lsDownSearch,modExtractHDF,modFolderToVar,modDownload, 7 | modGetPathRow,modMosaic,modPreview,modDownSearch,modSearch,setRGISToolsOpt, 8 | getRGISToolsOpt,showRGISToolsOpt,senDownload,senDownSearch,senGetTile,senGetOrbit, 9 | senFolderToVar,senSearch,senMosaic,senPreview,varEVI,varMSAVI2,varNBR, 10 | varNBR2,varNDMI,varNDVI,varNDWI,varRGB,varSAVI,lsCloudMask,senCloudMask,modCloudMask, 11 | lsEspaOrderImages,lsEspaGetOrderImages,lsEspaUpdateOrders,lsEspaDownloadOrders,lsSearch, 12 | lsUpdateEEDataSets) 13 | import("raster","curl", "rjson","rvest", "urltools","tools", 14 | "fields","sf","tmap","stars") 15 | importFrom("stats", "na.omit") 16 | importFrom("mapview","viewRGB") 17 | importFrom("methods", "formalArgs","as", "is") 18 | importFrom("httr","POST","authenticate","content_type","content") 19 | importFrom("sp","layout.scale.bar","layout.north.arrow" 20 | ,"spplot") 21 | importFrom("XML","xmlNativeTreeParse","xmlSApply", 22 | "xmlValue","xmlRoot") 23 | importFrom("xml2","read_xml","xml_attr", 24 | "read_html") 25 | importFrom("utils", "URLencode", "data", "download.file", 26 | "read.csv","untar") 27 | importFrom("Rdpack","reprompt") 28 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' A Digital Elevation Model (DEM) of the region of Navarre (Spain) 2 | #' 3 | #' Geographically projected \code{RasterStack} with the digital elevation model 4 | #'(DEM) of the region of Navarre (Spain). The DEM was obtained from the 5 | #' \href{http://centrodedescargas.cnig.es/CentroDescargas/locale?request_locale=en#}{National Center for Geographic Information} 6 | #' of Spain. The DEM is used as a covariable in the Image Mean Anomaly (IMA) 7 | #' algorithm (\code{\link{genSmoothingCovIMA}}). 8 | #' 9 | #' @format The \code{RasterStack} contains 6 layers with the same DEM, one for 10 | #' every image in the time series of the \code{\link{genSmoothingCovIMA}} example. 11 | #' The \code{RasterStack} coordinates are in the Sinusoidal projection: 12 | #' 13 | #' \describe{ 14 | #' \item{name}{layer names contain the capturing date of the corresponding image in the format "\code{YYYYJJJ}"}. 15 | #' \item{size}{113 rows by 105 columns and 6 layers}. 16 | #' } 17 | #' @name ex.dem.navarre 18 | #' @docType data 19 | #' @keywords data 20 | NULL 21 | 22 | #' A time series of NDVI of Navarre (Spain) 23 | #' 24 | #' Geographically projected \code{RasterBrick} object of the normalized 25 | #' difference vegetation index (NDVI) of Navarre. 26 | #' 27 | #' @format The \code{RasterBrick} contains 6 images, from the 2nd to the 4th of 28 | #' August in 2017 and 2018. The \code{RasterBrick} coordinates are in the 29 | #' Sinusoidal projection: 30 | #' 31 | #' \describe{ 32 | #' \item{name}{layer names contain the date of the image in the format "\code{YYYYJJJ}"}. 33 | #' \item{size}{each layer contains 113 rows and 105 columns}. 34 | #' } 35 | #' @name ex.ndvi.navarre 36 | #' @docType data 37 | #' @keywords data 38 | NULL 39 | 40 | #' A polygon with the border of Navarre (Spain) 41 | #' 42 | #' Spatial feature (\code{sf}) representing the border of Navarre with 43 | #' coordinates in the longitude/latitude format. 44 | #' @name ex.navarre 45 | #' @docType data 46 | #' @keywords data 47 | NULL 48 | 49 | 50 | #' @docType package 51 | #' @bibliography system.file("REFERENCES.bib", package = "RGISTools") -------------------------------------------------------------------------------- /R/defineAppRoot.R: -------------------------------------------------------------------------------- 1 | defineAppRoot<-function(...){ 2 | arg<-list(...) 3 | if(!"AppRoot"%in%names(arg)){ 4 | AppRoot=getRGISToolsOpt("AppRoot") 5 | if(is.null(AppRoot)) 6 | AppRoot=getwd() 7 | }else{ 8 | AppRoot=arg$AppRoot 9 | } 10 | return(AppRoot) 11 | } 12 | as.Date<-function(x,...){ 13 | if(is.numeric(x)){ 14 | return(base::as.Date("1970-01-01")+x) 15 | }else{ 16 | return(base::as.Date(x,...)) 17 | } 18 | } 19 | pathWinLx<-function(str){ 20 | res<-c() 21 | for(str1 in str){ 22 | if(substr(str1,1,2)=="\\"){ 23 | res<-c(res,paste0("\\",gsub("\\","/",substr(str1,3,nchar(str1)),fixed = TRUE))) 24 | }else{ 25 | res<-c(res,gsub("\\","/",str1,fixed = TRUE)) 26 | } 27 | } 28 | return(res) 29 | } 30 | -------------------------------------------------------------------------------- /R/genAskForYN.R: -------------------------------------------------------------------------------- 1 | genAskForYN<-function(question,cont=0,n.attempts=5,omit.question=FALSE){ 2 | str = tolower(readline(question)) 3 | if(omit.question){return(TRUE)} 4 | if(cont=arg$startDate)) 40 | } 41 | if("endDate"%in%names(arg)){ 42 | dates<-genGetDates(names(r)) 43 | r<-raster::subset(r,which(dates<=arg$endDate)) 44 | } 45 | return(r) 46 | } 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /R/genGetDates.R: -------------------------------------------------------------------------------- 1 | #' Return the capturing date from the name of a raster layer 2 | #' 3 | #' \code{genGetDates} extracts the date of one or several images when the name 4 | #' of the layer includes the date in the "\code{YYYYJJJ}" format. 5 | #' 6 | #' The function reads a date from a \code{character} class object in year-julian 7 | #' ("\code{YYYYJJJ}") format and returns a \code{Date} class object. 8 | #' 9 | #' @param str \code{character} containing the date as "\code{YYYYJJJ}", 10 | #' where \code{Y} and \code{J} are year and julian day digits. 11 | #' @param ... arguments for nested functions: 12 | #' \itemize{ 13 | #' \item \code{format} the format of the date being returned. 14 | #' } 15 | #' 16 | #' @return a \code{Date} class object with the date of the image or \code{character} class, 17 | #' if \code{format} argument is used. 18 | #' 19 | #' @examples 20 | #' img <- matrix(1:16, ncol = 4, byrow = TRUE) 21 | #' r <- raster(img) 22 | #' names(r) <- c("RandomImage_2018034") 23 | #' 24 | #' spplot(r) 25 | #' genGetDates(names(r), format = "%Y%j") 26 | #' 27 | genGetDates<-function(str, ...){ 28 | arg<-list(...) 29 | if("date.format"%in%names(arg)){ 30 | return(format(as.Date(gsub(".*\\s*(\\d{7}).*", "\\1", str),"%Y%j"),format=arg$date.format)) 31 | }else{ 32 | return(as.Date(gsub(".*\\s*(\\d{7}).*", "\\1", str),"%Y%j")) 33 | } 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /R/genMapViewSession.R: -------------------------------------------------------------------------------- 1 | genMapViewSession<-function(r,lpos,lname,add.Layer,...){ 2 | sessionmap<-getRGISToolsOpt("GMapView") 3 | if(is.null(sessionmap)|(!add.Layer)){ 4 | sessionmap<-viewRGB(subset(r,lpos), 5 | layer.name =lname,...) 6 | # %>% leafem::addLogo(file.path(system.file("logo", package = "RGISTools"),"RGISTools_logo.gif"), 7 | # url = "", 8 | # width=180, 9 | # height = 70, 10 | # offset.x=10, 11 | # offset.y=10, 12 | # position = c("topright"), 13 | # src=c("local")) 14 | setRGISToolsOpt("GMapView",sessionmap) 15 | return(sessionmap) 16 | }else{ 17 | sessionmap<-viewRGB(subset(r,lpos),layer.name =lname,...)+sessionmap 18 | setRGISToolsOpt("GMapView",sessionmap) 19 | return(sessionmap) 20 | } 21 | } -------------------------------------------------------------------------------- /R/genMosaicGdalUtils.R: -------------------------------------------------------------------------------- 1 | genMosaicGdalUtils<-function(typechunks,temp="temp.vrt",nodata,out.name){ 2 | newchunks<-NULL 3 | 4 | tryCatch({ 5 | if(is.null(nodata)){ 6 | gdal_utils(util = "buildvrt", 7 | source =typechunks, 8 | destination = temp 9 | ) 10 | }else{ 11 | gdal_utils(util = "buildvrt", 12 | source = typechunks, 13 | destination = temp, 14 | options=c("-srcnodata",nodata,"-vrtnodata",nodata) 15 | ) 16 | } 17 | }, warning = function(warning_condition) { 18 | if(grepl("gdalbuildvrt does not support heterogeneous projection",warning_condition)){ 19 | tryCatch({ 20 | #reproject the images 21 | diffproj=TRUE 22 | suppressWarnings(file.remove(temp)) 23 | proj<-paste0("EPSG:",gdal_crs(typechunks[1])$crs[[1]]) 24 | newchunks<-c(typechunks[1]) 25 | for(ni in 2:length(typechunks)){ 26 | destemp<-gsub(".TIF","_proj.TIF",typechunks[ni],fixed = TRUE) 27 | destemp<-gsub(".jp2","_warp.tif",typechunks[ni],fixed = TRUE) 28 | gdal_utils(util = "warp", 29 | source =typechunks[ni], 30 | destination = destemp, 31 | options=c("-t_srs",proj) 32 | ) 33 | newchunks<-c(newchunks,destemp) 34 | } 35 | if(is.null(nodata)){ 36 | gdal_utils(util = "buildvrt", 37 | source =newchunks, 38 | destination = temp 39 | ) 40 | }else{ 41 | gdal_utils(util = "buildvrt", 42 | source =newchunks, 43 | destination = temp, 44 | options=c("-srcnodata",nodata,"-vrtnodata",nodata) 45 | ) 46 | } 47 | },warning = function(war){ 48 | if(grepl("Read error at scanline",warning_condition)){ 49 | warning(paste0("Error reading an image, check the following input images:\n",paste(paste0(1:length(typechunks),". ",typechunks), collapse = '\n'))) 50 | return(FALSE) 51 | } 52 | }) 53 | } 54 | 55 | }) 56 | gdal_utils(util = "translate", 57 | source =temp, 58 | destination = out.name, 59 | options=c(paste0("of GTiff")) 60 | ) 61 | if(file.exists(temp))file.remove(temp) 62 | if(!is.null(newchunks))file.remove(file.remove(newchunks[-1],showWarnings = FALSE)) 63 | return(TRUE) 64 | } 65 | 66 | -------------------------------------------------------------------------------- /R/genMosaicList.R: -------------------------------------------------------------------------------- 1 | #' Mosaic a list of raster images 2 | #' 3 | #' \code{genMosaicList} makes a single mosaic from a list of raster images. 4 | #' 5 | #' This is a helper function used by other functions in this package. It combines 6 | #' a list of \code{raster} images with different geolocations. If images overlap, 7 | #' the function applies \code{fun} to calculate the new values for the 8 | #' overlapping pixels. If not specified, \code{fun = max}. 9 | #' 10 | #' @param imageList \code{list} of \code{RasterLayers}. 11 | #' @param fun the function being applied to pixels that overlap. 12 | #' @param verbose logical argument. If \code{TRUE}, the function prints the 13 | #' running steps and warnings. 14 | #' 15 | #' @return a \code{raster} with the mosaicked images. 16 | #' 17 | #' @examples 18 | #' # create simulated rasters 19 | #' img <- matrix(1:16, ncol = 4, byrow = TRUE) 20 | #' r1 <- raster(img) 21 | #' r2 <- r1 22 | #' r3 <- r1 23 | #' extent(r2) <- extent(1, 2, 1, 2) 24 | #' extent(r3) <- extent(1, 2, 0, 1) 25 | #' imageList <- list(r1, r2, r3) 26 | #' # mosaic simulated rasters 27 | #' mr <- genMosaicList(imageList) 28 | #' spplot(mr) 29 | genMosaicList <-function(imageList, fun="max",verbose=TRUE){ 30 | if(length(imageList)>1){ 31 | names(imageList) <- NULL 32 | imageList$fun<-fun 33 | imageList$tolerance<-0.000005 34 | imageList$na.rm <- TRUE 35 | mosaic <- do.call(mosaic, imageList) 36 | return(mosaic) 37 | }else{ 38 | if(verbose){ 39 | warning("There is only one raster image in imgList. No need to merge.") 40 | } 41 | return(imageList[[1]]) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /R/jsonManage.R: -------------------------------------------------------------------------------- 1 | toEspaJSON<-function(json_list,is.array=c("products","inputs")){ 2 | nam<-names(json_list) 3 | resjson<-'{' 4 | for(n in 1:length(nam)){ 5 | resjson<-paste0(resjson,'"',nam[n],'":') 6 | nlist<-json_list[[n]] 7 | if(class(nlist)=='list'){ 8 | resjson<-paste0(resjson,toEspaJSON(nlist)) 9 | }else if(length(nlist)>1|nam[n]%in%is.array){ 10 | resjson<-paste0(resjson,'[') 11 | for(x in nlist){ 12 | if(is.na(x)){ 13 | resjson<-paste0(resjson,'null,') 14 | }else{ 15 | resjson<-paste0(resjson,'"',x,'",') 16 | } 17 | } 18 | resjson<-paste0(resjson,']') 19 | }else if(length(nlist)==1){ 20 | if(is.na(nlist)){ 21 | resjson<-paste0(resjson,'null') 22 | }else{ 23 | resjson<-paste0(resjson,'"',nlist,'"') 24 | } 25 | } 26 | resjson<-paste0(resjson,",") 27 | } 28 | resjson<-paste0(resjson,'}') 29 | resjson<-gsub(",]","]",resjson) 30 | resjson<-gsub(",}","}",resjson) 31 | return(resjson) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /R/ls7DownloadUSGS.R: -------------------------------------------------------------------------------- 1 | .ls7DownloadUSGS<-function(sceneID, 2 | rfolder, 3 | usgs.handler, 4 | overwrite=FALSE, 5 | ...){ 6 | arg<-list(...) 7 | if("verbose"%in%names(arg)){ 8 | verbose=arg$verbose 9 | }else{verbose=F} 10 | url<-paste0(getRGISToolsOpt("USGS.url"),"download/12267/",sceneID,"/STANDARD/EE/") 11 | pth<-paste0(rfolder,"/",sceneID,".tar.gz") 12 | if(overwrite){ 13 | file.remove(pth,showWarnings=FALSE) 14 | } 15 | message(paste0("Downloading file in: ",pth)) 16 | if(verbose){message(paste0("download url: ",url))} 17 | curl_download(url, destfile=pth,handle = usgs.handler) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /R/ls8DownloadUSGS.R: -------------------------------------------------------------------------------- 1 | .ls8DownloadUSGS<-function(sceneID, 2 | rfolder, 3 | usgs.handler, 4 | overwrite=FALSE, 5 | ...){ 6 | arg<-list(...) 7 | if("verbose"%in%names(arg)){ 8 | verbose=arg$verbose 9 | }else{verbose=F} 10 | url<-paste0(getRGISToolsOpt("USGS.url"),"download/12864/",sceneID,"/STANDARD/EE/") 11 | pth<-paste0(rfolder,"/",sceneID,".tar.gz") 12 | if(overwrite){ 13 | file.remove(pth,showWarnings=FALSE) 14 | } 15 | message(paste0("Downloading file in: ",pth)) 16 | if(verbose){message(paste0("download url: ",url))} 17 | curl_download(url, destfile=pth,handle = usgs.handler) 18 | } 19 | -------------------------------------------------------------------------------- /R/lsEElogin.R: -------------------------------------------------------------------------------- 1 | loginEEAPI<-function(username,password,verbose=FALSE){ 2 | jsonquery<-list("username"=username, 3 | "password"=password, 4 | "authType"="EROS", 5 | "catalogId"="EE") 6 | post.res <- POST(url = paste0(getRGISToolsOpt("LS.EE.API"), "login"), 7 | body = paste0('jsonRequest=',toJSON(jsonquery)), 8 | content_type("application/x-www-form-urlencoded; charset=UTF-8")) 9 | res <- content(post.res) 10 | if(res$error!=""){ 11 | stop(res$error) 12 | } 13 | if(verbose)message('Logged in to EE API.') 14 | setRGISToolsOpt("LS.EE.KEY",res$data) 15 | } 16 | 17 | 18 | logoutEEAPI<-function(verbose=FALSE){ 19 | jsonquery<-list("apikey"=getRGISToolsOpt("LS.EE.KEY")) 20 | if(!is.null(jsonquery$apikey)){ 21 | post.res <- POST(url = paste0(getRGISToolsOpt("LS.EE.API"), "logout"), 22 | body = URLencode(paste0('jsonRequest=',toJSON(jsonquery))), 23 | content_type("application/x-www-form-urlencoded; charset=UTF-8")) 24 | res <- content(post.res) 25 | if(res$error!=""){ 26 | if(verbose)message('Logged out from EE API.') 27 | setRGISToolsOpt("LS.EE.KEY",NULL) 28 | }else{ 29 | stop(res$error) 30 | } 31 | }else{ 32 | if(verbose)message('You are not logged in EE API.') 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /R/lsEarthExplorerdownload.R: -------------------------------------------------------------------------------- 1 | lsEarthExplorerdownload<-function(searchres,username,password,cookies.file,untar,raw.rm,downDir,AppRoot,downPath,verbose,overwrite,...){ 2 | #start usgs session 3 | arg<-list(...) 4 | handler<-startUSGSsession(username,password,cookies.file,verbose) 5 | if(verbose) 6 | message("USGS session started, downloading images...") 7 | for(scene in searchres$sceneID){ 8 | if(!file.exists(paste0(downPath,"/",scene,".tar.gz"))){ 9 | if(grepl("LC8",searchres[1,]$sceneID)){ 10 | .ls8DownloadUSGS(scene,downPath,handler,verbose=verbose,overwrite=overwrite) 11 | }else if(grepl("LE7",searchres[1,]$sceneID)){ 12 | .ls7DownloadUSGS(scene,downPath,handler,verbose=verbose,overwrite=overwrite) 13 | } 14 | }else{ 15 | message(paste0(scene," file already exists! Not downloading.")) 16 | } 17 | #Unzip in downDir when available 18 | untarDir<-file.path(AppRoot,downDir,"untar",scene) 19 | if((untar&!file.exists(untarDir))|(untar&overwrite)){ 20 | message(paste0("Untar ",scene," file.")) 21 | if(overwrite){ 22 | file.remove(untarDir,showWarnings=FALSE,recursive=TRUE) 23 | } 24 | dir.create(untarDir,recursive=TRUE,showWarnings=FALSE) 25 | 26 | if("bFilter"%in%names(arg)){ 27 | flist<-untar(downPath,list=TRUE) 28 | flist<-flist[Reduce("|", lapply(paste0(arg$bFilter,"\\.TIF$"),grepl,flist))] 29 | untar(tarfile=downPath, 30 | files=flist, 31 | exdir = untarDir) 32 | }else{ 33 | untar(paste0(downPath,"/",scene,".tar.gz"),exdir=untarDir) 34 | } 35 | 36 | 37 | 38 | #Flag is true, so remove compressed files 39 | if(raw.rm){ 40 | file.remove(paste0(downPath,"/",scene,".tar.gz")) 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /R/lsEspaConnection.R: -------------------------------------------------------------------------------- 1 | lsEspaCreateConnection<-function(username,password){ 2 | c.handle = new_handle() 3 | handle_setopt(c.handle, 4 | referer=getRGISToolsOpt("LS.ESPA.API"), 5 | useragent = getRGISToolsOpt("USERAGENT"), 6 | followlocation = TRUE, 7 | autoreferer = TRUE, 8 | username=username, 9 | password=password) 10 | return(c.handle) 11 | } -------------------------------------------------------------------------------- /R/lsEspaGetOrderImages.R: -------------------------------------------------------------------------------- 1 | #' Gets a first response from ESPA regarding a recent request 2 | #' 3 | #' \code{lsEspaGetOrderImages} obtains the identification number and the status 4 | #' of the request from the EROS Centre Science Processing Architecture (ESPA). 5 | #' 6 | #' This function is part of a group of functions used to pre-process Landsat 7 | #' level-1 images. The pre-processing is carried out by ESPA on demand. 8 | #' \code{lsEspaGetOrderImages} takes the identification (ID) number of a 9 | #' request carried out by \code{\link{lsEspaOrderImages}}. This ID is used to 10 | #' follow up the processing status with \code{\link{lsEspaUpdateOrders}}. All the 11 | #' status messages and their interpretation can be found in the ESPA's API 12 | #' \href{https://www.usgs.gov/media/files/eros-science-processing-architecture-demand-interface-user-guide}{User Guide}. 13 | #' 14 | #' @param username USGS's `EarthExplorer' username. 15 | #' @param password USGS's `EarthExplorer' password. 16 | #' @param c.handle a curl handler created with the package `\code{curl}' to 17 | #' stablish a connection with a preset password and username. This argument 18 | #' is mandatory if \code{username} and \code{password} are not defined. 19 | #' @param order.list a list of orders from \code{\link{lsEspaOrderImages}} 20 | #' @param verbose logical argument. If \code{TRUE}, the function prints the 21 | #' running steps and warnings. 22 | #' 23 | #' @examples 24 | #' \dontrun{ 25 | #' wdir <- file.path(tempdir(),"Path_for_downloading_folder") 26 | #' # search Landsat 7 level-2 27 | #' sres <- ls7Search(startDate = as.Date("01-01-2017", "%d-%m-%Y"), 28 | #' endDate = as.Date("07-01-2017", "%d-%m-%Y"), 29 | #' lonlat = c(-1.64323, 42.81687), 30 | #' AppRoot = wdir) 31 | #' # request to ESPA the pre-pocessing of level-2 images to 32 | #' # get the surface reflectance 33 | #' order <- lsEspaOrderImages(search.res = sres, 34 | #' username = "username", 35 | #' password = "password", 36 | #' product = 'sr', 37 | #' verbose = FALSE) 38 | #' # get an ID for our request 39 | #' lsEspaGetOrderImages(username = "username", 40 | #' password = "password") 41 | #' } 42 | lsEspaGetOrderImages<-function(username=NULL,password=NULL,c.handle=NULL,order.list=NULL,verbose=TRUE){ 43 | if(is.null(c.handle)){ 44 | if(is.null(username)|is.null(username)){ 45 | stop("c.handle or username and password are null.") 46 | }else{ 47 | stopifnot(class(username)=="character") 48 | stopifnot(class(password)=="character") 49 | c.handle<-lsEspaCreateConnection(username,password) 50 | } 51 | } 52 | if(is.null(order.list)) 53 | order.list<-lsEspaGetOrders(c.handle=c.handle) 54 | img.list<-list() 55 | for(ol in order.list){ 56 | r <- curl_fetch_memory(paste0(getRGISToolsOpt("LS.ESPA.API"),getRGISToolsOpt("LS.ESPA.API.v"),"/order/",ol), c.handle) 57 | json_data<-fromJSON(rawToChar(r$content)) 58 | if(json_data$note==getRGISToolsOpt("LS.ESPA.Request")){ 59 | all.response<-unlist(json_data,recursive=TRUE) 60 | img.list[[ol]]<-list(OrderedImages=unname(all.response[grepl("inputs",names(all.response))]), 61 | Status=json_data$status) 62 | }else{ 63 | if(verbose)message(paste0(ol," is not an RGISTools request, not adding for downloading...")) 64 | } 65 | } 66 | return(img.list) 67 | } -------------------------------------------------------------------------------- /R/lsEspaGetOrders.R: -------------------------------------------------------------------------------- 1 | lsEspaGetOrders<-function(username=NULL,password=NULL,c.handle=NULL){ 2 | if(is.null(c.handle)){ 3 | if(is.null(username)|is.null(username)){ 4 | stop("c.handle or username and password are null.") 5 | }else{ 6 | stopifnot(class(username)=="character") 7 | stopifnot(class(password)=="character") 8 | c.handle<-lsEspaCreateConnection(username,password) 9 | } 10 | } 11 | r <- curl_fetch_memory(paste0(getRGISToolsOpt("LS.ESPA.API"),getRGISToolsOpt("LS.ESPA.API.v"),"/list-orders"), c.handle) 12 | order.list<-fromJSON(rawToChar(r$content)) 13 | return(order.list) 14 | } -------------------------------------------------------------------------------- /R/lsEspaUpdateOrders.R: -------------------------------------------------------------------------------- 1 | #' Updates the status of a request made to ESPA 2 | #' 3 | #' \code{lsEspaUpdateOrders} checks the current status of a request made to EROS 4 | #' Centre Science Processing Architecture (ESPA) to pre-process Landsat level-1 5 | #' images 6 | #' 7 | #' This function is part of a group of functions used to pre-process Landsat 8 | #' level 1 images. The pre-processing is carried out by ESPA on demand. 9 | #' \code{lsEspaUpdateOrders} uses the ID numbers gathered by 10 | #' \code{\link{lsEspaGetOrderImages}} regarding previous order requests 11 | #' to check the processing status. The function has to be run repeatedly 12 | #' until the status message states “complete”. All the status messages and their 13 | #' interpretation can be found in the ESPA's API 14 | #' \href{https://www.usgs.gov/media/files/eros-science-processing-architecture-demand-interface-user-guide}{User Guide}. 15 | #' 16 | #' @param orders a list of the requested orders as returned by 17 | #' \code{\link{lsEspaGetOrderImages}}. 18 | #' @param username USGS's `EarthExplorer' username. 19 | #' @param password USGS's `EarthExplorer' password. 20 | #' @param c.handle a curl handler created with the package `\code{curl}' to 21 | #' stablish a connection with a preset password and username. This argument 22 | #' is mandatory if \code{username} and \code{password} are not defined. 23 | #' @param verbose logical argument. If \code{TRUE}, the function prints the 24 | #' running steps and warnings. 25 | #' @return this function returns a \code{dataframe} with the updated order information from ESPA. 26 | #' @examples 27 | #' \dontrun{ 28 | #' src <- file.path(tempdir(),"Path_for_downloading_folder") 29 | #' # search Landsat 7 level-1 30 | #' search.res <- ls7Search(startDate = as.Date("01-01-2017", "%d-%m-%Y"), 31 | #' endDate = as.Date("15-01-2017", "%d-%m-%Y"), 32 | #' lonlat = c(-1.64323, 42.81687), 33 | #' AppRoot = src) 34 | #' # request to ESPA the prepocessing of level-1 images to get the surface reflectance 35 | #' orders <- lsEspaOrderImages(search.res = search.res, 36 | #' username = "username", 37 | #' password = "password", 38 | #' product = 'sr', 39 | #' verbose = FALSE) 40 | #' # get an ID for our request 41 | #' orders <- lsEspaGetOrderImages(username = "username", 42 | #' password = "password") 43 | #' # follow up the status of the request 44 | #' orders <- lsEspaUpdateOrders(orders = orders, 45 | #' username = "username", 46 | #' password = "password") 47 | #' } 48 | lsEspaUpdateOrders<-function(orders,username=NULL,password=NULL,c.handle=NULL,verbose=FALSE){ 49 | if(is.null(c.handle)){ 50 | if(is.null(username)|is.null(username)){ 51 | stop("c.handle or username and password are null.") 52 | }else{ 53 | stopifnot(class(username)=="character") 54 | stopifnot(class(password)=="character") 55 | c.handle<-lsEspaCreateConnection(username,password) 56 | } 57 | } 58 | new.orders<-lsEspaGetOrders(c.handle=c.handle) 59 | new.orders<-new.orders[!new.orders%in%names(orders)] 60 | if(length(new.orders)>0){ 61 | new.images<-lsEspaGetOrderImages(order.list=new.orders,c.handle=c.handle,verbose=verbose) 62 | orders<-append(orders,new.images) 63 | } 64 | for(order in 1:length(orders)){ 65 | if(orders[[order]]$Status%in%c("ordered")){ 66 | r <- curl_fetch_memory(paste0(getRGISToolsOpt("LS.ESPA.API"),getRGISToolsOpt("LS.ESPA.API.v"),"/order/",names(orders)[order]), 67 | c.handle) 68 | json_data<-fromJSON(rawToChar(r$content)) 69 | if(json_data$note==getRGISToolsOpt("LS.ESPA.Request")){ 70 | all.response<-unlist(json_data,recursive=TRUE) 71 | orders[[order]]<-list(OrderedImages=unname(all.response[grepl("inputs",names(all.response))]), 72 | Status=json_data$status) 73 | } 74 | } 75 | } 76 | return(orders) 77 | } -------------------------------------------------------------------------------- /R/lsGetPathRow.R: -------------------------------------------------------------------------------- 1 | #' Return the pathrow of a tile of Landsat-7 or Landsat-8 images 2 | #' 3 | #' \code{lsGetPathRow} reads the official name of a Landsat-7 or Landsa-8 image 4 | #' and returns the tile’s path and row number, in "PPPRRR" format (Landsat 5 | #' naming convention). 6 | #' 7 | #' @param str the full path(s) or official name(s) of the Landsat-7 or Landsa-8 8 | #' images from which the tile’s path and row numbers are retrieved. 9 | #' 10 | #' @return a string with the path and row in "\code{PPPRRR}" format. 11 | #' 12 | #' @examples 13 | #' # example of getting date from Landsat-8 image name 14 | #' str <- c("LE72000302011066ASN00", 15 | #' "LE72000302011066ASN00") 16 | #' pr <- lsGetPathRow(str) 17 | #' print(pr) 18 | #' 19 | lsGetPathRow<-function(str){ 20 | str<-basename(str) 21 | return(substr(str,4,9)) 22 | } 23 | -------------------------------------------------------------------------------- /R/lsQuery.R: -------------------------------------------------------------------------------- 1 | lsSearchQuery<-function(datasetName,startDate,endDate,sf.obj,...){ 2 | args<-list(...) 3 | lsquery<-NULL 4 | #temporal filter 5 | lsquery$datasetName<- datasetName#'LANDSAT_8_C1' 6 | lsquery$temporalFilter<-list("startDate"=format(startDate,"%d-%m-%Y"), 7 | "endDate"=format(endDate,"%d-%m-%Y")) 8 | #spatial filter 9 | lsquery$spatialFilter<-list("filterType"='mbr', 10 | "lowerLeft"=list("latitude"=st_bbox(sf.obj)[["ymin"]], 11 | "longitude"=st_bbox(sf.obj)[["xmin"]]), 12 | "upperRight"=list("latitude"=st_bbox(sf.obj)[["ymax"]], 13 | "longitude"=st_bbox(sf.obj)[["xmax"]])) 14 | if("cloudCover"%in%names(args)){ 15 | if(length(args$cloudCover)==2&&class(args$cloudCover)=="numeric"){ 16 | lsquery$minCloudCover<-min(args$cloudCover) 17 | lsquery$maxCloudCover<-max(args$cloudCover) 18 | if("includeUnknownCloudCover"%in%names(args)){ 19 | lsquery$includeUnknownCloudCover<-args$includeUnknownCloudCover 20 | }else{ 21 | lsquery$includeUnknownCloudCover<-"true" 22 | } 23 | }else{stop("cloudCover must be a numeric argument")} 24 | } 25 | 26 | 27 | #additional criteria 28 | lsquery$maxResults<-50000 29 | lsquery$startingNumber<-1 30 | lsquery$sortOrder<-"ASC" 31 | lsquery$apiKey<-getRGISToolsOpt("LS.EE.KEY") 32 | return(toJSON(lsquery)) 33 | } -------------------------------------------------------------------------------- /R/lsRemoveMetadata.R: -------------------------------------------------------------------------------- 1 | #' Remove the Landsat-7 or Lansat-8 metadata from the environment 2 | #' 3 | #' \code{lsRemoveMetadata} removes Landsat-7 and/or Landsat-8 (\code{.LS7MD}/ 4 | #' \code{.LS8MD}) metadata from the environment in `R'. 5 | #' 6 | #' The metadata file is loaded in `R' with \code{\link{ls7Search}}, 7 | #' \code{\link{ls8Search}} and \code{\link{lsDownSearch}}. \code{lsRemoveMetadata} 8 | #' removes the metadata and frees up valuable RAM. 9 | #' 10 | #' @examples 11 | #' \dontrun{ 12 | #' # creates a MetaData folder and downloads the csv file 13 | #' # in the current working directory 14 | #' wdir <- file.path(tempdir(),"Path_for_downloading_folder") 15 | #' print(wdir) 16 | #' ls8LoadMetadata(AppRoot = wdir) 17 | #' lsRemoveMetadata() 18 | #' } 19 | lsRemoveMetadata<-function(){ 20 | setRGISToolsOpt("LS7METADATA",NULL) 21 | setRGISToolsOpt("LS8METADATA",NULL) 22 | gc() 23 | } 24 | -------------------------------------------------------------------------------- /R/lsStartSession.R: -------------------------------------------------------------------------------- 1 | startUSGSsession<-function(username, 2 | password, 3 | cookies.file=NULL, 4 | verbose=FALSE){ 5 | c.handle = new_handle() 6 | handle_setopt(c.handle, 7 | referer=getRGISToolsOpt("USGS.url"), 8 | cookiejar = cookies.file, 9 | useragent = getRGISToolsOpt("USERAGENT"), 10 | followlocation = TRUE , 11 | autoreferer = TRUE ) 12 | 13 | req <- curl(getRGISToolsOpt("USGS.login"), handle = c.handle) 14 | html<-readLines(req) 15 | html<-paste(html,collapse = "\n ") 16 | html<-read_html(html) 17 | csrf<-html %>% html_nodes(xpath = '//*[@name="csrf_token"]') %>% xml_attr("value") 18 | if(grepl("ncforminfo",html)){ 19 | nc<-html %>% html_nodes(xpath = '//*[@name="__ncforminfo"]') %>% xml_attr("value") 20 | handle_setform(c.handle, 21 | 'username' = username, 22 | 'password' = password, 23 | "csrf_token"=csrf, 24 | "__ncforminfo"=nc 25 | ) 26 | }else{ 27 | handle_setform(c.handle, 28 | 'username' = username, 29 | 'password' = password, 30 | "csrf_token"=csrf) 31 | } 32 | req <- curl_fetch_memory(getRGISToolsOpt("USGS.login"), handle = c.handle) 33 | if(verbose){ 34 | message(paste(parse_headers(req$headers),collapse="\n")) 35 | } 36 | return(c.handle) 37 | } 38 | -------------------------------------------------------------------------------- /R/lsUpdateEEDataSets.R: -------------------------------------------------------------------------------- 1 | #' Update EarthExplorer dataset names 2 | #' 3 | #' The `EE.DataSets' option of 'RGISTools' contains all the dataset names 4 | #' supported by EarthExplorer API. If these names changes, \code{\link{lsUpdateEEDataSets}} 5 | #' updates these data. 6 | #' 7 | #' @param username USGS's `EarthExplorer' username. 8 | #' @param password USGS's `EarthExplorer' password. 9 | #' @param logout logical argument. If \code{TRUE}, logges out from EarthExplorer 10 | #' API 11 | #' @param verbose logical argument. If \code{TRUE}, the function prints the 12 | #' running steps and warnings. 13 | #' 14 | #' @return the dataset names in EarthExplorer API 15 | #' 16 | #' @examples 17 | #' \dontrun{ 18 | #' setRGISToolsOpt("EE.DataSets",NULL) 19 | #' getRGISToolsOpt("EE.DataSets") 20 | #' datasetNames<-lsUpdateEEDataSets(username = "username", 21 | #' password = "password") 22 | #' 23 | #' getRGISToolsOpt("EE.DataSets") 24 | #' } 25 | lsUpdateEEDataSets<-function(username,password,logout=TRUE,verbose=FALSE){ 26 | ApiKey<-getRGISToolsOpt("LS.EE.KEY") 27 | if(is.null(ApiKey)){ 28 | loginEEAPI(username,password,verbose) 29 | } 30 | c.handle = new_handle() 31 | handle_setopt(c.handle, 32 | referer=getRGISToolsOpt("LS.EE.API"), 33 | useragent = getRGISToolsOpt("USERAGENT"), 34 | followlocation = TRUE , 35 | autoreferer = TRUE) 36 | response<-curl(paste0(getRGISToolsOpt("LS.EE.API"),'datasets?jsonRequest={"apiKey":"', getRGISToolsOpt("LS.EE.KEY"), '"}'), 37 | handle =c.handle) 38 | datasets<-fromJSON(suppressWarnings(readLines(response))) 39 | close(response) 40 | datasets<-datasets$data 41 | datasets<-unlist(lapply(datasets, function(x){x$datasetName})) 42 | 43 | if(logout){logoutEEAPI(verbose)} 44 | setRGISToolsOpt("EE.DataSets",datasets, env=optEnv) 45 | saveRDS(datasets,file.path(system.file("EE_data", package = "RGISTools"),"EE_DataSets.rds")) 46 | return(datasets) 47 | } 48 | -------------------------------------------------------------------------------- /R/modGetPathRow.R: -------------------------------------------------------------------------------- 1 | #' Return the pathrow of a tile of MODIS images 2 | #' 3 | #' \code{modGetPathRow} reads the official name of a MODIS image and returns the 4 | #' tile's path and row number, in 'hXXvYY' format (MODIS naming convention). 5 | #' 6 | #' @param str the full path(s) or official name(s) of the MODIS images from 7 | #' which the tile's path and row numbers are retrieved. 8 | #' 9 | #' @return a string with the path and row in "\code{hXXvYY}" format. 10 | #' 11 | #' @examples 12 | #' # getting the path and row number of the tile of a Landsat-8 image 13 | #' files.mod <- "MYD09GA.A2003136.h17v04.005.2008324054225" 14 | #' pr.mod <- modGetPathRow(files.mod) 15 | #' print(pr.mod) 16 | #' 17 | modGetPathRow<-function(str){ 18 | return(gsub(".*\\s*(h\\d{2}v\\d{2}).*", "\\1", str)) 19 | } 20 | -------------------------------------------------------------------------------- /R/modPreview.R: -------------------------------------------------------------------------------- 1 | #' Preview MODIS satellite images 2 | #' 3 | #' \code{modPreview} shows a preview of the \code{n}-th image from a set of 4 | #' search results on an interactive map. 5 | #' 6 | #' The function shows a preview of the \code{n}-th output image from a search 7 | #' in the MODIS archives (\code{\link{modSearch}}, with 8 | #' \code{resType = "browseurl"}). The preview is downloaded from the 9 | #' \href{https://earthdata.nasa.gov}{`EarthData' Platform}. 10 | #' Please, be aware that only some images may have a preview. 11 | #' 12 | #' @param searchres a vector with the results from \code{\link{modSearch}}. 13 | #' @param dates a vector with the dates being considered 14 | #' for previewing. This argument is mandatory if 15 | #' \code{n} is not defined. 16 | #' @param n a \code{numeric} argument identifying the location of the image in 17 | #' \code{searchres}. 18 | #' @param lpos vector argument. Defines the position of the red-green-blue 19 | #' layers to enable false color visualization. 20 | #' @param add.Layer logical argument. If \code{TRUE}, the function plots the 21 | #' image on an existing map. Allows combinations of images on a map using 22 | #' \code{\link{lsPreview}} and \code{\link{senPreview}} functions. 23 | #' @param verbose logical argument. If \code{TRUE}, the function prints the 24 | #' running steps and warnings. 25 | #' @param ... arguments for nested functions: 26 | #' \itemize{ 27 | #' \item arguments allowed by the \code{viewRGB} function from \code{mapview} 28 | #' packages are valid arguments. 29 | #' } 30 | #' @return this function does not return anything. It displays a preview of one 31 | #' of the search results. 32 | #' @examples 33 | #' \dontrun{ 34 | #' # load a spatial polygon object of Navarre 35 | #' data(ex.navarre) 36 | #' # retrieve jpg images covering Navarre region between 2011 and 2013 37 | #' sres <- modSearch(product = "MOD09GA", 38 | #' startDate = as.Date("01-01-2011", "%d-%m-%Y"), 39 | #' endDate = as.Date("31-12-2013", "%d-%m-%Y"), 40 | #' collection = 6, 41 | #' extent = ex.navarre) 42 | #' 43 | #' modPreview(sres,n=1) 44 | #' modPreview(sres,2,add.Layer=T) 45 | #' } 46 | modPreview<-function(searchres,n,dates,lpos=c(3,2,1),add.Layer=FALSE,verbose = FALSE,...){ 47 | if(class(searchres)!="modres"){stop("A response from modis search function is needed.")} 48 | searchres<-searchres$jpg 49 | if(missing(dates)){ 50 | return(.modPreviewRecursive(searchres=searchres,n=n,lpos=lpos,add.Layer=add.Layer,verbose=verbose,...)) 51 | }else{ 52 | searchres<-searchres[modGetDates(searchres)%in%dates] 53 | if(length(searchres)>0){ 54 | .modPreviewRecursive(searchres=searchres,n=1,lpos=lpos,add.Layer=add.Layer,verbose=verbose,...) 55 | if(length(searchres)>1){ 56 | for(x in 2:length(searchres)){ 57 | .modPreviewRecursive(searchres=searchres,n=x,lpos=lpos,add.Layer=TRUE,verbose=verbose,...) 58 | } 59 | } 60 | return(getRGISToolsOpt("GMapView")) 61 | }else{ 62 | stop("There is no image for preview in ") 63 | } 64 | 65 | } 66 | } 67 | .modPreviewRecursive<-function(searchres,n,lpos=c(3,2,1),add.Layer=FALSE,verbose = FALSE,...){ 68 | ser<-searchres[n] 69 | tmp <- tempfile() 70 | if(verbose){ 71 | download.file(ser,tmp,mode="wb") 72 | }else{ 73 | download.file(ser,tmp,mode="wb",quiet = TRUE) 74 | } 75 | pic<-stack(tmp) 76 | 77 | pr<-modGetPathRow(ser) 78 | ho<-as.numeric(substr(pr,2,3)) 79 | ve<-as.numeric(substr(pr,5,6)) 80 | 81 | extent(pic)<-extent(st_transform(mod.tiles[mod.tiles$Name==paste0("h:",ho," v:",ve),],crs=st_crs(54008))) 82 | projection(pic)<-st_crs(54008)$proj4string 83 | 84 | if(verbose){ 85 | return(genMapViewSession(pic,lpos,lname=paste0("MOD_",ho,"_",ve,"_D",format(modGetDates(ser),"%Y%j")),add.Layer=add.Layer,...)) 86 | }else{ 87 | return(suppressWarnings(genMapViewSession(pic,lpos,lname=paste0("MOD_",ho,"_",ve,"_D",format(modGetDates(ser),"%Y%j")),add.Layer=add.Layer,...))) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /R/senGetPathRow.R: -------------------------------------------------------------------------------- 1 | #' Return the pathrow of a tile from Sentinel-2 images 2 | #' 3 | #' \code{senGetTile} reads the official name of a Sentinel-2 image and returns 4 | #' the tile's path and row number, in "\code{TTTSSS}" format (Sentinel naming 5 | #' convention). 6 | #' 7 | #' Find more details about the Sentinel tiling system 8 | #' \href{https://sentinel.esa.int/web/sentinel/missions/sentinel-2/news/-/asset_publisher/Ac0d/content/sentinel-2-level-1c-product-tiling-grid-released}{here}. 9 | #' 10 | #' @param str the full path(s) or official name(s) of the Sentinel-2 images from 11 | #' which the tile's path and row numbers are retrieved. 12 | #' 13 | #' @return a string with the path and row in "\code{TTTSSS}" format. 14 | #' 15 | #' @examples 16 | #' # getting path and row numbers from a couple of Sentinel-2 images 17 | #' files.sen <- c("S2A_MSIL1C_20170102T111442_N0204_R137_T30TWN_20170102T111441.SAFE", 18 | #' "S2A_OPER_PRD_MSIL1C_PDMC_20160308T090616_R094_V20160305T110109_20160305T110109") 19 | #' pr.sen <- senGetTile(files.sen) 20 | #' print(pr.sen) 21 | #' 22 | senGetTile<-function(str){ 23 | name.first<-gsub(".SAFE","",basename(str)) 24 | # Sentinel-2 images 25 | if(substr(name.first,1,2)[1]=="S2"){ 26 | sizes<-sapply(name.first,nchar) 27 | sTime<-c() 28 | for(s in 1:length(sizes)){ 29 | if(sizes[s]!=78){#new name convention 30 | sTime<-c(sTime,gsub(".*\\s*([A-Za-z]{1}\\d{2}[A-Za-z]{3}).*", "\\1", names(sizes[s]))) 31 | }else{#old name convention 32 | sTime<-c(sTime,"") 33 | } 34 | } 35 | }else{ 36 | stop("Introduced image path is not a supported Sentinel image name.") 37 | } 38 | 39 | return(sTime) 40 | } 41 | 42 | 43 | #' Return the relative orbit of the Sentinel-2 satellite 44 | #' 45 | #' \code{senGetOrbit} reads the official name of a Sentinel image and returns 46 | #' relative orbit, in "\code{NXXXX_RYYY}" or "\code{RYYY}" format (Sentinel 47 | #' namig convention). 48 | #' 49 | #' Get information about the relative orbits 50 | #' \href{https://sentinel.esa.int/web/sentinel/missions/sentinel-2/satellite-description/orbit}{here}. 51 | #' 52 | #' 53 | #' @param str the full path(s) or official name(s) of the Sentinel images from 54 | #' which the orbits are retrieved. 55 | #' 56 | #' @return an string with the relative orbit of the image in "\code{NXXXX_RYYY}" 57 | #' or "\code{RYYY}" format, depending on the version of name convention. 58 | #' 59 | #' @examples 60 | #' #example of getting date from Sentinel2 image name 61 | #' files.sen <- c("S2A_MSIL1C_20170102T111442_N0204_R137_T30TWN_20170102T111441.SAFE", 62 | #' "S2A_OPER_PRD_MSIL1C_PDMC_20160308T090616_R094_V20160305T110109_20160305T110109") 63 | #' tile.sen <- senGetOrbit(files.sen) 64 | #' print(tile.sen) 65 | #' 66 | senGetOrbit<-function(str){ 67 | name.first<-gsub(".SAFE","",basename(str)) 68 | 69 | # Sentinel-2 images 70 | if(substr(name.first,1,2)[1]=="S2"){ 71 | sizes<-sapply(name.first,nchar) 72 | sTime<-c() 73 | for(s in 1:length(sizes)){ 74 | if(sizes[s]!=78){#new name convention 75 | sTime<-c(sTime,gsub(".*\\s*(N\\d{4}_R\\d{3}).*", "\\1", names(sizes[s]))) 76 | }else{#old name convention 77 | sTime<-c(sTime,gsub(".*?\\s*(R\\d{3}).*", "\\1", names(sizes[s]))) 78 | } 79 | } 80 | }else{ 81 | stop("Introduced image path is not supported Sentinel image name") 82 | } 83 | 84 | return(sTime) 85 | } 86 | -------------------------------------------------------------------------------- /R/senSearchQuery.R: -------------------------------------------------------------------------------- 1 | senSearchQuery<-function(...){ 2 | url<-paste0(getRGISToolsOpt("SCIHUBAPIURL"),"/search?q=") 3 | arg<-list(...) 4 | if(!"verbose"%in%names(arg)){ 5 | arg$verbose=FALSE 6 | } 7 | #add ingestion date to query 8 | if("startDate"%in%names(arg)){ 9 | if(arg$verbose) 10 | message("Adapting dates.") 11 | startDate<-paste0(format(arg$startDate,"%Y-%m-%d"),"T00:00:00.000Z") 12 | if(is.null(arg$endDate)){ 13 | endDate<-"NOW" 14 | }else{ 15 | endDate<-paste0(format(arg$endDate,"%Y-%m-%d"),"T23:59:59.999Z") 16 | } 17 | url<-paste0(url,"beginposition:[",startDate," TO ",endDate,"]") 18 | } 19 | if("platform"%in%names(arg)){ 20 | if(arg$verbose) 21 | message("Adding platform name.") 22 | url<-paste0(url," AND platformname:",arg$platform) 23 | } 24 | if("extent"%in%names(arg)){ 25 | stopifnot(class(extent(arg$extent))=="Extent") 26 | if(arg$verbose) 27 | message("Adding query extent.") 28 | ext<-extent(arg$extent) 29 | url<-paste0(url," AND footprint:",'"',"intersects(POLYGON((",ext@xmin," ",ext@ymin,"," 30 | ,ext@xmin," ",ext@ymax,"," 31 | ,ext@xmax," ",ext@ymax,"," 32 | ,ext@xmax," ",ext@ymin,"," 33 | ,ext@xmin," ",ext@ymin,")))",'"') 34 | 35 | } 36 | if("lonlat"%in%names(arg)){ 37 | if(arg$verbose){ 38 | message(print("Adding query intersects")) 39 | } 40 | if(!length(arg$lonlat)==2){ 41 | stop("The intersects argument is not a longitude/latitude valid location.") 42 | } 43 | url<-paste0(url," AND footprint:",'"',"intersects(",arg$lonlat[1],", ",arg$lonlat[2],")",'"') 44 | } 45 | if("region"%in%names(arg)){ 46 | if(arg$verbose){ 47 | message(print("Adding query region")) 48 | } 49 | arg$region<-transform_multiple_proj(arg$region, proj4=st_crs(4326)) 50 | ext<-st_bbox(arg$region) 51 | url<-paste0(url," AND footprint:",'"',"intersects(POLYGON((",ext$xmin," ",ext$ymin,"," 52 | ,ext$xmin," ",ext$ymax,"," 53 | ,ext$xmax," ",ext$ymax,"," 54 | ,ext$xmax," ",ext$ymin,"," 55 | ,ext$xmin," ",ext$ymin,")))",'"') 56 | } 57 | if("product"%in%names(arg)){ 58 | if(arg$verbose){ 59 | message("Added product type.") 60 | } 61 | url<-paste0(url," AND producttype:",arg$product) 62 | } 63 | if("relativeorbit"%in%names(arg)){ 64 | if(arg$verbose){ 65 | message("Added relative orbit number type.") 66 | } 67 | url<-paste0(url," AND relativeorbitnumber:",arg$relativeorbit) 68 | } 69 | if("cloudCover"%in%names(arg)){ 70 | if(arg$verbose){ 71 | message("Added cloud cover percentage.") 72 | } 73 | url<-paste0(url," AND cloudcoverpercentage:[",min(arg$cloudCover)," TO ",max(arg$cloudCover),"]") 74 | } 75 | if("timeliness"%in%names(arg)){ 76 | if(arg$verbose){ 77 | message("Added timeliness.") 78 | } 79 | url<-paste0(url,' AND timeliness:"',arg$timeliness,'"') 80 | } 81 | if("qformat"%in%names(arg)){ 82 | url<-paste0(url,"&format=",arg$qformat) 83 | }else{ 84 | url<-paste0(url,"&format=json") 85 | } 86 | url<-paste0(url,"&rows=100") 87 | return(URLencode(url)) 88 | } 89 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/R/sysdata.rda -------------------------------------------------------------------------------- /R/transform_multiple_proj.R: -------------------------------------------------------------------------------- 1 | transform_multiple_proj <- function(obj, proj4){ 2 | # Object to be transformed 3 | if(is(obj, "sf")) { 4 | new_obj<-obj 5 | }else if(is(obj, "Spatial")){ 6 | new_obj<-st_as_sf(obj) 7 | }else if(is(obj, "Raster")){ 8 | new_obj <- extent(obj) 9 | new_obj<-st_as_sf(as(new_obj, 'SpatialPolygons')) 10 | st_crs(new_obj)<-projection(obj) 11 | }else{ 12 | stop("Spatial object not supported!") 13 | } 14 | 15 | if(missing(proj4)){ 16 | return(new_obj) 17 | }else{ 18 | return(st_transform(new_obj, proj4)) 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /R/varEVI.R: -------------------------------------------------------------------------------- 1 | #' Calculate the enhanced vegetation index (EVI) 2 | #' 3 | #' \code{varEVI} computes the enhanced vegetation index (EVI) from the 4 | #' blue, near-infrared (NIR) and red bands. 5 | #' 6 | #' The enhanced vegetation index (EVI) is a vegetation indicator that improves 7 | #' the sensitivity towards high biomass densities compared to NDVI 8 | #' \insertCite{huete2002overview}{RGISTools} (See \code{\link{varNDVI}}). This 9 | #' function is used within \code{\link{ls7FolderToVar}}, 10 | #' \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 11 | #' \code{\link{senFolderToVar}}. 12 | #' 13 | #' @references \insertRef{huete2002overview}{RGISTools} 14 | #' 15 | #' @param blue a \code{raster} with the blue band of the capture. 16 | #' @param red a \code{raster} with the red band of the capture. 17 | #' @param nir a \code{raster} with the NIR band of the capture. 18 | #' @param scfun a function to re-scale the original pixel values into 19 | #' reflectance (0-1). 20 | #' 21 | #' @return An EVI image in \code{raster} format. 22 | #' 23 | #' @examples 24 | #' # path to the cropped and cutted MODIS images for the region of Navarre 25 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 26 | #' # list all the tif files 27 | #' files.mod <- list.files(wdir, pattern = "\\.tif$", recursive = TRUE, full.names = TRUE) 28 | #' # print the MOD09 bands 29 | #' getRGISToolsOpt("MOD09BANDS") 30 | #' scale.factor <- 0.0001 31 | #' 32 | #' # select the red, blue and nir bands 33 | #' img.mod.red <- raster(files.mod[1]) * scale.factor 34 | #' img.mod.blue <- raster(files.mod[3]) * scale.factor 35 | #' img.mod.nir <- raster(files.mod[2]) * scale.factor 36 | #' # calculate the EVI without scale 37 | #' img.mod.evi <- varEVI(img.mod.blue, img.mod.red, img.mod.nir) 38 | #' # calculate the EVI scaling 0-1 39 | #' img.mod.evi.2 <- varEVI(img.mod.blue, img.mod.red, img.mod.nir,scfun=getRGISToolsOpt("MOD09SCL")) 40 | #' img.mod.evi.12 <- stack(img.mod.evi,img.mod.evi.2) 41 | #' # plot the image 42 | #' spplot(img.mod.evi.12,col.regions=rev(terrain.colors(20)),at = c(seq(0,1,0.05))) 43 | varEVI<-function(blue,red,nir,scfun=function(r){r}){ 44 | blue=scfun(blue) 45 | red=scfun(red) 46 | nir=scfun(nir) 47 | evi <- 2.5*((nir - red) / (nir+6 * red-7.5*blue+1)) 48 | return(evi) 49 | } 50 | 51 | -------------------------------------------------------------------------------- /R/varMSAVI2.R: -------------------------------------------------------------------------------- 1 | #' Calculate the modified soil-adjusted vegetation index (MSAVI2) 2 | #' 3 | #' \code{varMSAVI2} computes the modified soil-adjusted vegetation index 2 4 | #' (MSAVI2) from the near-infrared (NIR) and red bands. 5 | #' 6 | #' The modified soil adjusted vegetation index 2 (MSAVI2) is a vegetation 7 | #' indicator that removes the effect from background variations 8 | #' \insertCite{qi1994modified}{RGISTools}. This function is used within 9 | #' \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 10 | #' \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 11 | #' 12 | #' @references \insertRef{qi1994modified}{RGISTools} 13 | #' 14 | #' @param red a \code{raster} with the red band of the capture. 15 | #' @param nir a \code{raster} with the NIR band of the capture. 16 | #' 17 | #' @return A MSAVI2 image in \code{raster} format. 18 | #' 19 | #' @examples 20 | #' # path to the cropped and cutted MODIS images for the region of Navarre 21 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 22 | #' # list all the tif files 23 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 24 | #' # print the MOD09 bands 25 | #' getRGISToolsOpt("MOD09BANDS") 26 | #' # select the red and NIR bands 27 | #' img.mod.red <- raster(files.mod[1]) 28 | #' img.mod.nir <- raster(files.mod[2]) 29 | #' # calculate the MSAVI2 image 30 | #' img.mod.msavi2 <- varMSAVI2(img.mod.red, img.mod.nir) 31 | #' # plot the image 32 | #' spplot(img.mod.msavi2,col.regions=rev(topo.colors(20))) 33 | varMSAVI2<-function(red, nir){ 34 | msavi<-(2*nir+1-sqrt((2*nir+1)^2-8*(nir-red)))/2 35 | return(msavi) 36 | } 37 | -------------------------------------------------------------------------------- /R/varNBR.R: -------------------------------------------------------------------------------- 1 | #' Calculate the normalized burn ratio (NBR) 2 | #' 3 | #' \code{varNBR} computes the normalized burn ratio (NBR) from the 4 | #' near-infrared (NIR) and shortwave-infrared 2 (SWIR2) bands. 5 | #' 6 | #' The normalized burn ratio (NBR) is an index that identifies burned areas by 7 | #' comparing its value before and after the fire event. It is calculated using the 8 | #' NIR and SWIR2 bands \insertCite{garcia1991mapping}{RGISTools}.This function 9 | #' is used within \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 10 | #' \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 11 | #' 12 | #' @references \insertRef{garcia1991mapping}{RGISTools} 13 | #' 14 | #' @param nir a \code{raster} with the NIR band of the capture. 15 | #' @param swir2 a \code{raster} with the SWIR2 band of the capture. 16 | #' 17 | #' @return A NBR image in \code{raster} format. 18 | #' 19 | #' @examples 20 | #' # path to the cropped and cutted MODIS images for the region of Navarre 21 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 22 | #' # list all the tif files 23 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 24 | #' # print the MOD09 bands 25 | #' getRGISToolsOpt("MOD09BANDS") 26 | #' 27 | #' # select the NIR and SWIR2 bands 28 | #' files.mod.nir <- raster(files.mod[2]) 29 | #' files.mod.swir2 <- raster(files.mod[7]) 30 | #' # calculate the NBR image 31 | #' files.mod.nbr <- varNBR(files.mod.nir, files.mod.swir2) 32 | #' # plot the image 33 | #' spplot(files.mod.nbr,col.regions=rev(heat.colors(20))) 34 | varNBR<-function(nir,swir2){ 35 | nbr<-(nir-swir2)/(nir+swir2) 36 | return(nbr) 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /R/varNBR2.R: -------------------------------------------------------------------------------- 1 | #' Calculate the normalized burn ratio 2 (NBR2) 2 | #' 3 | #' \code{varNBR2} computes the NBR2 index from the shortwave infrared 1 (SWIR1) 4 | #' and shortwave infrared 2 (SWIR2). 5 | #' 6 | #' The normalized burn ratio 2 (NRB2) is an index to identify burned areas. 7 | #' In contrast to NBR, NRB2 highlights the sensitivity to water in vegetation 8 | #' \insertCite{lutes2006firemon}{RGISTools}. This function is used within 9 | #' \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 10 | #' \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 11 | #' 12 | #' @references \insertRef{lutes2006firemon}{RGISTools} 13 | #' 14 | #' @param swir1 a \code{raster} with the the SWIR1 band of the capture. 15 | #' @param swir2 a \code{raster} with the the SWIR2 band of the capture. 16 | #' 17 | #' @return A NBR2 image in \code{raster} format. 18 | #' 19 | #' @examples 20 | #' # path to the cropped and cutted MODIS images for the region of Navarre 21 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 22 | #' # list all the tif files 23 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 24 | #' # print the MOD09 bands 25 | #' getRGISToolsOpt("MOD09BANDS") 26 | #' 27 | #' # select the SWIR1 and SWIR2 bands 28 | #' img.mod.swir1 <- raster(files.mod[6]) 29 | #' img.mod.swir2 <- raster(files.mod[7]) 30 | #' # calculate the NBR2 image 31 | #' img.mod.nbr2 <- varNBR2(img.mod.swir1,img.mod.swir2) 32 | #' # plot the image 33 | #' spplot(img.mod.nbr2,col.regions=rev(heat.colors(20))) 34 | varNBR2<-function(swir1,swir2){ 35 | nbr2<-(swir1-swir2)/(swir1+swir2) 36 | return(nbr2) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /R/varNDMI.R: -------------------------------------------------------------------------------- 1 | #' Calculate the normalized difference moisture (water) index (NDMI) 2 | #' 3 | #' \code{varNDMI} computes the normalized difference moisture index (NDMI) from 4 | #' the near-infrared (NIR) and shortwave-infrared 1 (SWIR1) bands. 5 | #' 6 | #' The normalized difference moisture index (NDMI) is an index that represents 7 | #' the water stress levels of the canopy, using the NIR and SWIR 8 | #' \insertCite{gao1995normalized}{RGISTools}. 9 | #' This function is used within \code{\link{ls7FolderToVar}}, 10 | #' \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 11 | #' \code{\link{senFolderToVar}}. 12 | #' 13 | #' @references \insertRef{gao1995normalized}{RGISTools} 14 | #' 15 | #' @param nir a \code{raster} with the nir band of the capture. 16 | #' @param swir1 a \code{raster} with the swir1 band of the capture. 17 | #' 18 | #' @return A NDMI image in \code{raster} format. 19 | #' 20 | #' @examples 21 | #' # path to the cropped and cutted MODIS images for the region of Navarre 22 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 23 | #' # list all the tif files 24 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 25 | #' # print the MOD09 bands 26 | #' getRGISToolsOpt("MOD09BANDS") 27 | #' 28 | #' # select the NIR and SWIR1 bands 29 | #' img.mod.nir <- raster(files.mod[2]) 30 | #' img.mod.swir1 <- raster(files.mod[6]) 31 | #' # calculate the NDMI image 32 | #' img.mod.ndmi <- varNDMI(img.mod.nir,img.mod.swir1) 33 | #' # plot the image 34 | #' spplot(img.mod.ndmi) 35 | varNDMI<-function(nir,swir1){ 36 | ndmi<-(nir-swir1)/(nir+swir1) 37 | return(ndmi) 38 | } 39 | -------------------------------------------------------------------------------- /R/varNDVI.R: -------------------------------------------------------------------------------- 1 | #' Calculate the normalized difference vegetation index (NDVI) 2 | #' 3 | #' \code{varNDVI} computes the normalized difference vegetation index (NDVI) 4 | #' from the red an near-infrared (NIR) bands. 5 | #' 6 | #' The normalized difference vegetation index (NDVI) is the most widely used 7 | #' index for monitoring vegetation dynamics. The NDVI reflects the vegetation vigour 8 | #' and it is closely related to the amount of photosynthetically active radiation 9 | #' absorbed \insertCite{rouse1972monitoring}{RGISTools}. This function is used 10 | #' within \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 11 | #' \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 12 | #' 13 | #' @references \insertRef{rouse1972monitoring}{RGISTools} 14 | #' 15 | #' @param red a \code{raster} with the red band of the capture. 16 | #' @param nir a \code{raster} with the NIR band of the capture. 17 | #' 18 | #' @return A NDVI image in \code{raster} format. 19 | #' 20 | #' @examples 21 | #' # path to the cropped and cutted MODIS images for the region of Navarre 22 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 23 | #' # list all the tif files 24 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 25 | #' # print the MOD09 bands 26 | #' getRGISToolsOpt("MOD09BANDS") 27 | #' 28 | #' # select the red and NIR bands 29 | #' img.mod.red <- raster(files.mod[1]) 30 | #' img.mod.nir <- raster(files.mod[2]) 31 | #' # calculate the NDVI image 32 | #' img.mod.ndvi <- varNDVI(img.mod.red,img.mod.nir) 33 | #' # plot the image 34 | #' spplot(img.mod.ndvi,col.regions=rev(terrain.colors(20))) 35 | varNDVI<-function(red, nir){ 36 | ndvi <- (nir - red) / (nir + red) 37 | return(ndvi) 38 | } 39 | -------------------------------------------------------------------------------- /R/varNDWI.R: -------------------------------------------------------------------------------- 1 | #' Calculates the normalized difference water index (NDWI) 2 | #' 3 | #' \code{varNDWI} Calculate the normalized difference water index (NDWI) from 4 | #' the green and near-infrared (NIR) bands. 5 | #' 6 | #' The normalized difference water index (NDWI) is a ratio between the green 7 | #' and near-infrared bands of the spectrum that was developed to detect open 8 | #' water areas and minimize the influence of the soil and vegetation variations 9 | #' \insertCite{mcfeeters1996use}{RGISTools}. This function is used within 10 | #' \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 11 | #' \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 12 | #' 13 | #' @references \insertRef{mcfeeters1996use}{RGISTools} 14 | #' 15 | #' @param green a \code{raster} with the green band of the capture. 16 | #' @param nir a \code{raster} with the NIR band of the capture. 17 | #' 18 | #' @return A NDWI image in \code{raster} format. 19 | #' 20 | #' @examples 21 | #' # path to the cropped and cutted MODIS images for the region of Navarre 22 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 23 | #' # list all the tif files 24 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 25 | #' # print the MOD09 bands 26 | #' getRGISToolsOpt("MOD09BANDS") 27 | #' 28 | #' # select the green and NIR bands 29 | #' img.mod.green <- raster(files.mod[4]) 30 | #' img.mod.nir <- raster(files.mod[2]) 31 | #' # calculate the NDWI image 32 | #' img.mod.ndwi <- varNDWI(img.mod.green,img.mod.nir) 33 | #' # plot the image 34 | #' spplot(img.mod.ndwi,col.regions=rev(rainbow(20))) 35 | varNDWI<-function(green,nir){ 36 | ndwi<-(green-nir)/(green+nir) 37 | return(ndwi) 38 | } 39 | -------------------------------------------------------------------------------- /R/varRGB.R: -------------------------------------------------------------------------------- 1 | #' Generate an RGB image from 3 spectral bands 2 | #' 3 | #' \code{varRGB} creates red-green-blue (RGB) images as a \code{RasterStack} by 4 | #' scaling the pixel values to 0-255 color range. 5 | #' 6 | #' The function rescales the original reflectance values to a range of 0-255. 7 | #' The function re-arranges the RGB bands to create a stack ready to visualize 8 | #' with plotRGB. Bands may contain outliers which cause the image to look dark. 9 | #' Use the \code{q.range} argument to remove the outliers and get a 10 | #' better-looking image. 11 | #' 12 | #' @param red a \code{raster} with the red band of the capture. 13 | #' @param green a \code{raster} with the green band of the capture. 14 | #' @param blue a \code{raster} with the blue band of the capture. 15 | #' @param q.range a vector with the minimum and maximum reflectance quantiles 16 | #' being considered. 17 | #' @param rPath the file path where the resulting RGB image is saved. 18 | #' @param region a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 19 | #' defining the area of interest for image masking. 20 | #' 21 | #' @examples 22 | #' # path to the cropped and cutted MODIS images for the region of Navarre 23 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 24 | #' # list all the tif files 25 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 26 | #' # print the MOD09 bands 27 | #' getRGISToolsOpt("MOD09BANDS") 28 | #' 29 | #' # select the red, blue and NIR bands 30 | #' img.mod.red <- raster(files.mod[1]) 31 | #' img.mod.blue <- raster(files.mod[3]) 32 | #' img.mod.green <- raster(files.mod[4]) 33 | #' 34 | #' q.range=c(0.001,0.999) 35 | #' img.mod.rgb<-varRGB(img.mod.red,img.mod.green,img.mod.blue,q.range) 36 | #' print(plotRGB(img.mod.rgb)) 37 | varRGB<-function(red,green,blue,q.range=c(),rPath=NULL,region=NULL){ 38 | 39 | rgb<-list(red,green,blue) 40 | names(rgb)<-c("red","green","blue") 41 | bclass<-unlist(lapply(rgb,FUN = function(x){return(class(x)=="stars")})) 42 | if(bclass[1]){rgb[[1]]<-as(rgb[[1]],"Raster")} 43 | if(bclass[2]){rgb[[2]]<-as(rgb[[2]],"Raster")} 44 | if(bclass[3]){rgb[[3]]<-as(rgb[[3]],"Raster")} 45 | 46 | if(!is.null(q.range)){ 47 | rgb<-lapply(rgb,FUN = function(r,q.range){q<-raster::quantile(r,q.range,na.rm=TRUE);r<-clamp(r,lower=q[1],upper=q[2]);return(r)},q.range) 48 | names(rgb)<-c("red","green","blue") 49 | } 50 | rgb<-lapply(rgb,raster::stretch, minv=0, maxv=255) 51 | image<-raster::stack(rgb) 52 | if(!is.null(region)){ 53 | region<-transform_multiple_proj(region,projection(image)) 54 | region<-as(region, 'Spatial') 55 | image<-raster::mask(image,region) 56 | } 57 | if(!is.null(rPath)){ 58 | writeRaster(image,rPath) 59 | }else{ 60 | if(any(bclass)){ 61 | return(st_as_stars(image)) 62 | }else{ 63 | return(image) 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /R/varSAVI.R: -------------------------------------------------------------------------------- 1 | #' Calculates the soil-adjusted vegetation index (SAVI) 2 | #' 3 | #' \code{varSAVI} Calculate the soil-adjusted vegetation index (SAVI) from the 4 | #' red and near-infrared (NIR) bands. 5 | #' 6 | #' The soil adjusted vegetation index (SAVI) is an indicator engineered to remove 7 | #' the influence of the soil background effect \insertCite{huete1988soil}{RGISTools}. 8 | #' This function is used within \code{\link{ls7FolderToVar}}, 9 | #' \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 10 | #' \code{\link{senFolderToVar}}. 11 | #' 12 | #' @references \insertRef{huete1988soil}{RGISTools} 13 | #' 14 | #' @param red a \code{raster} with the red band of the capture. 15 | #' @param nir a \code{raster} with the NIR band of the capture. 16 | #' @param L a constant to remove soil background effect. A value of 0.5 is 17 | #' recommended in the literature. 18 | #' @param scfun a function to re-scale the original pixel values into 19 | #' reflectance (0-1). 20 | #' 21 | #' @return A SAVI image in \code{raster} format. 22 | #' 23 | #' @examples 24 | #' # path to the cropped and cutted MODIS images for the region of Navarre 25 | #' wdir <- system.file("ExNavarreVar", package = "RGISTools") 26 | #' # list all the tif files 27 | #' files.mod <- list.files(wdir, pattern="\\.tif$", recursive = TRUE, full.names = TRUE) 28 | #' # print the MOD09 bands 29 | #' getRGISToolsOpt("MOD09BANDS") 30 | #' 31 | #' # select the red and NIR bands 32 | #' img.mod.red <- raster(files.mod[1]) 33 | #' img.mod.nir <- raster(files.mod[2]) 34 | #' # calculate the SAVI image 35 | #' img.mod.savi <- varSAVI(img.mod.red,img.mod.nir,scfun=getRGISToolsOpt("MOD09SCL")) 36 | #' # plot the image 37 | #' spplot(img.mod.savi,col.regions=rev(topo.colors(20))) 38 | varSAVI<-function(red,nir,L=0.5,scfun=function(r){r}){ 39 | red=scfun(red) 40 | nir=scfun(nir) 41 | savi<-((nir-red)/(nir+red+L))*(1+L) 42 | return(savi) 43 | } 44 | -------------------------------------------------------------------------------- /RGISTools.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageCheckArgs: --as-cran 19 | PackageRoxygenize: rd,collate,namespace 20 | DisableExecuteRprofile: Yes 21 | -------------------------------------------------------------------------------- /data/ex.dem.navarre.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/data/ex.dem.navarre.rda -------------------------------------------------------------------------------- /data/ex.navarre.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/data/ex.navarre.rda -------------------------------------------------------------------------------- /data/ex.ndvi.navarre.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/data/ex.ndvi.navarre.rda -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citEntry(entry = "Manual", 2 | title = "RGISTools: Handling Multiplatform Satellite Images", 3 | author = personList(as.person("U P{\\'e}rez-Goya"), 4 | as.person("M Montesino-SanMartin"), 5 | as.person("A F Militino"), 6 | as.person("M D Ugarte")), 7 | year = "2020", 8 | note = "R package version 1.0.0", 9 | url = "https://CRAN.R-project.org/package=RGISTools", 10 | textVersion = 11 | paste("U Pérez-Goya, M Montesino-SanMartin, A F Militino, M D Ugarte (2020).", 12 | "RGISTools: Handling Multiplatform Satellite Images. R package version 1.0.0.", 13 | "https://CRAN.R-project.org/package=RGISTools."), 14 | header = "To cite the package:" 15 | ) 16 | 17 | citEntry(entry = "Article", 18 | title = "Interpolation of the Mean Anomalies for Cloud-Filling in Land Surface Temperature and Normalized Difference Vegetation Index", 19 | author = personList(as.person("A F Militino"), 20 | as.person("M D Ugarte"), 21 | as.person("U P{\\'e}rez-Goya"), 22 | as.person("M G Genton")), 23 | journal = "IEEE Transactions on Geoscience and Remote Sensing", 24 | year = "2019", 25 | volume = "57", 26 | number = "8", 27 | pages = "6068--6078", 28 | url = "http://dx.doi.org/10.1109/TGRS.2019.2904193", 29 | textVersion = 30 | paste("Militino, A.F., Ugarte, M.D., Pérez-Goya, U., M G Genton (2019).", 31 | "Interpolation of the Mean Anomalies for Cloud-Filling in Land Surface Temperature and Normalized Difference Vegetation Index.", 32 | "IEEE Transactions on Geoscience and Remote Sensing 2019. 57(8), pp 6068-6078. (Open-access) doi:http://dx.doi.org/10.1109/TGRS.2019.2904193"), 33 | header = "To cite the gap filling method implemented in the function genSmoothingIMA:" 34 | ) 35 | 36 | citEntry(entry = "Article", 37 | title = "Improving the Quality of Satellite Imagery Based on Ground-Truth Data from Rain Gauge Stations", 38 | author = personList(as.person("A F Militino"), 39 | as.person("M D Ugarte"), 40 | as.person("U P{\\'e}rez-Goya")), 41 | journal = "Remote Sensing", 42 | year = "2018", 43 | volume = "10", 44 | number = "398", 45 | pages = "1--16", 46 | url = "http://dx.doi.org/10.3390/rs10030398", 47 | textVersion = 48 | paste("Militino, A.F., Ugarte, M.D., Pérez-Goya, U. (2018).", 49 | "Improving the Quality of Satellite Imagery Based on Ground-Truth Data from Rain Gauge Stations.", 50 | "Remote Sensing 2018; 10(398). (Open-access) doi:http://dx.doi.org/10.3390/rs10030398"), 51 | header = "To cite the smoothing method implemented in the function genSmoothingCovIMA:" 52 | ) -------------------------------------------------------------------------------- /inst/EE_data/EE_DataSets.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/EE_data/EE_DataSets.rds -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b01_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b01_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b02_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b02_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b03_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b03_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b04_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b04_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b05_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b05_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b06_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b06_1.tif -------------------------------------------------------------------------------- /inst/ExNavarreVar/ExNavarreVar_MODIS_b07_1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spatialstatisticsupna/RGISTools/4d1c72ff0ba6ddac86671175e1d358570cd61a81/inst/ExNavarreVar/ExNavarreVar_MODIS_b07_1.tif -------------------------------------------------------------------------------- /inst/REFERENCES.bib: -------------------------------------------------------------------------------- 1 | @Article{militino2019interpolation, 2 | title = {Interpolation of the Mean Anomalies for Cloud-Filling in Land Surface Temperature (LST) and Normalized Difference Vegetation Index (NDVI)}, 3 | author = {A F Militino and M D Ugarte and U Perez-Goya and Marc G. Genton}, 4 | journal = {IEEE Transactions on Geoscience and Remote Sensing. (Open-Access)}, 5 | year = {2019}, 6 | url = {http://dx.doi.org/10.1109/TGRS.2019.2904193}, 7 | } 8 | @Article{militino2018improving, 9 | title = {Improving the Quality of Satellite Imagery Based on Ground-Truth Data from Rain Gauge Stations}, 10 | author = {A F Militino and M D Ugarte and U Perez-Goya}, 11 | journal = {Remote Sensing. (Open-Access)}, 12 | year = {2018}, 13 | volume = {10}, 14 | number = {398}, 15 | pages = {1--16}, 16 | url = {http://dx.doi.org/10.3390/rs10030398}, 17 | } 18 | @article{huete2002overview, 19 | title={Overview of the radiometric and biophysical performance of the MODIS vegetation indices}, 20 | author={Huete, Alfredo and Didan, Kamel and Miura, Tomoaki and Rodriguez, E Patricia and Gao, Xiang and Ferreira, Laerte G}, 21 | journal={Remote sensing of environment}, 22 | volume={83}, 23 | number={1-2}, 24 | pages={195--213}, 25 | year={2002}, 26 | publisher={Elsevier} 27 | } 28 | @article{qi1994modified, 29 | title={A modified soil adjusted vegetation index}, 30 | journal={Remote Sensing Environment}, 31 | author={Qi, J and Chehbouni, A and Huerte, AR and Kerr, YH and Sorooshian, S}, 32 | volume={48}, 33 | pages={119--126}, 34 | year={1994} 35 | } 36 | @article{garcia1991mapping, 37 | title={Mapping burns and natural reforestation using Thematic Mapper data}, 38 | author={Garcia, MJ Lopez and Caselles, V}, 39 | journal={Geocarto International}, 40 | volume={6}, 41 | number={1}, 42 | pages={31--37}, 43 | year={1991}, 44 | publisher={Taylor \& Francis} 45 | } 46 | @article{lutes2006firemon, 47 | title={FIREMON: Fire effects monitoring and inventory system}, 48 | author={Lutes, Duncan C and Keane, Robert E and Caratti, John F and Key, Carl H and Benson, Nathan C and Sutherland, Steve and Gangi, Larry J}, 49 | journal={Gen. Tech. Rep. RMRS-GTR-164. Fort Collins, CO: US Department of Agriculture, Forest Service, Rocky Mountain Research Station. 1 CD.}, 50 | volume={164}, 51 | year={2006} 52 | } 53 | @inproceedings{gao1995normalized, 54 | title={Normalized difference water index for remote sensing of vegetation liquid water from space}, 55 | author={Gao, Bo-Cai}, 56 | booktitle={Imaging Spectrometry}, 57 | volume={2480}, 58 | pages={225--237}, 59 | year={1995}, 60 | organization={International Society for Optics and Photonics} 61 | } 62 | @article{rouse1972monitoring, 63 | title={Monitoring the vernal advancement and retrogradation (green wave effect) of natural vegetation}, 64 | journal={NASA technical Reports Server}, 65 | author={Rouse Jr, John W}, 66 | year={1972}, 67 | url = {https://ntrs.nasa.gov/search.jsp?R=19730009607} 68 | } 69 | @article{mcfeeters1996use, 70 | title={The use of the Normalized Difference Water Index (NDWI) in the delineation of open water features}, 71 | author={McFeeters, Stuart K}, 72 | journal={International journal of remote sensing}, 73 | volume={17}, 74 | number={7}, 75 | pages={1425--1432}, 76 | year={1996}, 77 | publisher={Taylor \& Francis} 78 | } 79 | @article{huete1988soil, 80 | title={A soil-adjusted vegetation index (SAVI)}, 81 | author={Huete, Alfredo R}, 82 | journal={Remote sensing of environment}, 83 | volume={25}, 84 | number={3}, 85 | pages={295--309}, 86 | year={1988}, 87 | publisher={Elsevier} 88 | } -------------------------------------------------------------------------------- /man/ex.dem.navarre.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ex.dem.navarre} 5 | \alias{ex.dem.navarre} 6 | \title{A Digital Elevation Model (DEM) of the region of Navarre (Spain)} 7 | \format{ 8 | The \code{RasterStack} contains 6 layers with the same DEM, one for 9 | every image in the time series of the \code{\link{genSmoothingCovIMA}} example. 10 | The \code{RasterStack} coordinates are in the Sinusoidal projection: 11 | 12 | \describe{ 13 | \item{name}{layer names contain the capturing date of the corresponding image in the format "\code{YYYYJJJ}"}. 14 | \item{size}{113 rows by 105 columns and 6 layers}. 15 | } 16 | } 17 | \description{ 18 | Geographically projected \code{RasterStack} with the digital elevation model 19 | (DEM) of the region of Navarre (Spain). The DEM was obtained from the 20 | \href{http://centrodedescargas.cnig.es/CentroDescargas/locale?request_locale=en#}{National Center for Geographic Information} 21 | of Spain. The DEM is used as a covariable in the Image Mean Anomaly (IMA) 22 | algorithm (\code{\link{genSmoothingCovIMA}}). 23 | } 24 | \keyword{data} 25 | -------------------------------------------------------------------------------- /man/ex.navarre.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ex.navarre} 5 | \alias{ex.navarre} 6 | \title{A polygon with the border of Navarre (Spain)} 7 | \description{ 8 | Spatial feature (\code{sf}) representing the border of Navarre with 9 | coordinates in the longitude/latitude format. 10 | } 11 | \keyword{data} 12 | -------------------------------------------------------------------------------- /man/ex.ndvi.navarre.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ex.ndvi.navarre} 5 | \alias{ex.ndvi.navarre} 6 | \title{A time series of NDVI of Navarre (Spain)} 7 | \format{ 8 | The \code{RasterBrick} contains 6 images, from the 2nd to the 4th of 9 | August in 2017 and 2018. The \code{RasterBrick} coordinates are in the 10 | Sinusoidal projection: 11 | 12 | \describe{ 13 | \item{name}{layer names contain the date of the image in the format "\code{YYYYJJJ}"}. 14 | \item{size}{each layer contains 113 rows and 105 columns}. 15 | } 16 | } 17 | \description{ 18 | Geographically projected \code{RasterBrick} object of the normalized 19 | difference vegetation index (NDVI) of Navarre. 20 | } 21 | \keyword{data} 22 | -------------------------------------------------------------------------------- /man/genCompositions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genCompositions.R 3 | \name{genCompositions} 4 | \alias{genCompositions} 5 | \title{Create image compositions from a time series of satellite images} 6 | \usage{ 7 | genCompositions(rstack, by, fun, n, by.days = FALSE, verbose = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{rstack}{a \code{RasterStack}, where layer names contain the capturing 11 | date of an image in "\code{YYYYJJJ}" format.} 12 | 13 | \item{by}{character argument. Accepts \code{"month"} or \code{"year"} for creating monthly 14 | or yearly composites. Only required if \code{n} is provided.} 15 | 16 | \item{fun}{the function used to create the composite, such as \code{max}, 17 | \code{min}, \code{mean}, ...} 18 | 19 | \item{n}{number of images combined in the aggregation. Only required if 20 | \code{by} is not provided.} 21 | 22 | \item{by.days}{logical argument. If \code{FALSE}, \code{n} indicates the 23 | number of consucutive images being aggregated. If \code{TRUE}, the function 24 | aggregates the imagery within every \code{n} days. The aggregation requires 25 | at least one image avaiable.} 26 | 27 | \item{verbose}{logical argument. If \code{TRUE}, the function prints 28 | the running steps and warnings.} 29 | 30 | \item{...}{arguments for nested functions: 31 | \itemize{ 32 | \item \code{AppRoot} the path where the images will be saved in the 33 | GTiff format. 34 | }} 35 | } 36 | \value{ 37 | a \code{RasterStack} with the time series of the composite images. 38 | } 39 | \description{ 40 | \code{genCompositions} combines a series of satellite images to create compositions. 41 | } 42 | \details{ 43 | The layer of the composite image takes its name from the first image used in 44 | the composition. 45 | 46 | \code{genCompositions} reduces the number of images but improves the total 47 | quality of the time-series by removing cloulds and outliers. One widespread 48 | compositing technique is the maximum value composition (MVC). This technique 49 | allocates in each pixel of the composite the maximum value (fun = max) that 50 | the pixel reaches during a time period (\code{n}, \code{by.days = TRUE}). 51 | } 52 | \examples{ 53 | # loading NDVI images of Navarre 54 | data("ex.ndvi.navarre") 55 | # Ploting the images: clouds are found 56 | genPlotGIS(ex.ndvi.navarre) 57 | # the first composite image is made with images 1, 2 and 3, 58 | # and the second composite image is made with images 4, 5 and 6 59 | composite.NDVI.a <- genCompositions(rstack = ex.ndvi.navarre, 60 | n = 3, 61 | fun = max) 62 | genPlotGIS(composite.NDVI.a) 63 | # when by.days=TRUE, the first composite image is made with images 1, 2 and 3, 64 | # the second with image 4, and the third with images 5 and 6. 65 | composite.NDVI.3a <- genCompositions(rstack = ex.ndvi.navarre, 66 | n = 3, 67 | by.days = TRUE, 68 | fun = max) 69 | # Check that the clouds were removed 70 | genPlotGIS(composite.NDVI.3a) 71 | } 72 | -------------------------------------------------------------------------------- /man/genFilterStack.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genFilterStack.R 3 | \name{genFilterStack} 4 | \alias{genFilterStack} 5 | \title{Subset a RasterStack given a range of dates} 6 | \usage{ 7 | genFilterStack(r, ...) 8 | } 9 | \arguments{ 10 | \item{r}{the \code{RasterStack} to be filtered.} 11 | 12 | \item{...}{arguments for nested functions: 13 | \itemize{ 14 | \item \code{startDate} a \code{Date} class object with the starting date of the study period. 15 | \item \code{endDate} a \code{Date} class object with the ending date of the study period. 16 | \item \code{AppRoot} the path where the RData will be saved. 17 | }} 18 | } 19 | \value{ 20 | a \code{RasterStack} with images within the specified dates. 21 | } 22 | \description{ 23 | \code{genFilterStack} filters the \code{RasterLayer}s within a range of dates. 24 | } 25 | \details{ 26 | This is a helper function used by other functions in this package. 27 | } 28 | \examples{ 29 | # generate random images 30 | img <- matrix(1:16, ncol = 4, byrow = TRUE) 31 | r <- raster(img) 32 | r <- stack(r, r, r, r, r, r) 33 | names(r) <- paste0("RandomImage_201803", 1:6) 34 | # print the names and dates of the random images 35 | print(names(r)) 36 | genGetDates(names(r)) 37 | # example of filtering the raster stack 38 | r2 <- genFilterStack(r = r, 39 | startDate = as.Date("2018-02-02", "\%Y-\%m-\%d"), 40 | endDate = as.Date("2018-02-04", "\%Y-\%m-\%d")) 41 | # print the names and the number of layers of the filtered stack 42 | genGetDates(names(r2)) 43 | nlayers(r2) 44 | } 45 | -------------------------------------------------------------------------------- /man/genGetDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genGetDates.R 3 | \name{genGetDates} 4 | \alias{genGetDates} 5 | \title{Return the capturing date from the name of a raster layer} 6 | \usage{ 7 | genGetDates(str, ...) 8 | } 9 | \arguments{ 10 | \item{str}{\code{character} containing the date as "\code{YYYYJJJ}", 11 | where \code{Y} and \code{J} are year and julian day digits.} 12 | 13 | \item{...}{arguments for nested functions: 14 | \itemize{ 15 | \item \code{format} the format of the date being returned. 16 | }} 17 | } 18 | \value{ 19 | a \code{Date} class object with the date of the image or \code{character} class, 20 | if \code{format} argument is used. 21 | } 22 | \description{ 23 | \code{genGetDates} extracts the date of one or several images when the name 24 | of the layer includes the date in the "\code{YYYYJJJ}" format. 25 | } 26 | \details{ 27 | The function reads a date from a \code{character} class object in year-julian 28 | ("\code{YYYYJJJ}") format and returns a \code{Date} class object. 29 | } 30 | \examples{ 31 | img <- matrix(1:16, ncol = 4, byrow = TRUE) 32 | r <- raster(img) 33 | names(r) <- c("RandomImage_2018034") 34 | 35 | spplot(r) 36 | genGetDates(names(r), format = "\%Y\%j") 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/genMosaicList.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genMosaicList.R 3 | \name{genMosaicList} 4 | \alias{genMosaicList} 5 | \title{Mosaic a list of raster images} 6 | \usage{ 7 | genMosaicList(imageList, fun = "max", verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{imageList}{\code{list} of \code{RasterLayers}.} 11 | 12 | \item{fun}{the function being applied to pixels that overlap.} 13 | 14 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 15 | running steps and warnings.} 16 | } 17 | \value{ 18 | a \code{raster} with the mosaicked images. 19 | } 20 | \description{ 21 | \code{genMosaicList} makes a single mosaic from a list of raster images. 22 | } 23 | \details{ 24 | This is a helper function used by other functions in this package. It combines 25 | a list of \code{raster} images with different geolocations. If images overlap, 26 | the function applies \code{fun} to calculate the new values for the 27 | overlapping pixels. If not specified, \code{fun = max}. 28 | } 29 | \examples{ 30 | # create simulated rasters 31 | img <- matrix(1:16, ncol = 4, byrow = TRUE) 32 | r1 <- raster(img) 33 | r2 <- r1 34 | r3 <- r1 35 | extent(r2) <- extent(1, 2, 1, 2) 36 | extent(r3) <- extent(1, 2, 0, 1) 37 | imageList <- list(r1, r2, r3) 38 | # mosaic simulated rasters 39 | mr <- genMosaicList(imageList) 40 | spplot(mr) 41 | } 42 | -------------------------------------------------------------------------------- /man/genSaveTSRData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genSaveTSRData.R 3 | \name{genSaveTSRData} 4 | \alias{genSaveTSRData} 5 | \title{Saves a time series of images as an RData} 6 | \usage{ 7 | genSaveTSRData( 8 | src, 9 | AppRoot = NULL, 10 | ts.name = "TS.Name", 11 | startDate = NULL, 12 | endDate = NULL, 13 | dextent = FALSE, 14 | recursive = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{src}{path to the folder where the time series of images is located.} 19 | 20 | \item{AppRoot}{the path where the RData is saved.} 21 | 22 | \item{ts.name}{the name of the \code{RasterStack} in the RData.} 23 | 24 | \item{startDate}{a \code{Date} class object with the starting date of the 25 | study period.} 26 | 27 | \item{endDate}{a \code{Date} class object with the ending date of the study 28 | period.} 29 | 30 | \item{dextent}{a logical argument. If \code{TRUE}, the function expands the 31 | extent of the \code{RasterStack} to embrace the extents of all GTiff images.} 32 | 33 | \item{recursive}{logical argument. If \code{TRUE}, reads folders recursively, 34 | searching for GTiff images.} 35 | } 36 | \value{ 37 | a \code{RasterStack} when the \code{AppRoot} argument is not defined. 38 | The function does not return anything otherwise. 39 | } 40 | \description{ 41 | \code{genSaveTSRData} imports a time series of images from a folder (GTiff 42 | format), builds a \code{RasterStack} and saves it in an RData. 43 | } 44 | \details{ 45 | The function reads all the images inside the folder specified in \code{src}. 46 | Images files must be GTiffs. The \code{src} can take the path created by 47 | other functions of this package, such as \code{\link{senMosaic}}, 48 | \code{\link{modMosaic}}, \code{\link{senFolderToVar}}, etc. The images are 49 | imported into `R' to build a \code{RasterStack}. The 50 | name of the \code{RasterStack} is specified in \code{ts.name}. The 51 | \code{RasterStack} is saved in an RData file in the \code{AppRoot} directory. 52 | } 53 | \examples{ 54 | \dontrun{ 55 | # load a spatial polygon object of Navarre 56 | data(ex.navarre) 57 | # set the download folder 58 | s.start <- Sys.time() 59 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 60 | print(wdir) 61 | # download the images 62 | modDownSearch(product = "MOD09GA", 63 | startDate = as.Date("30-07-2018", "\%d-\%m-\%Y"), 64 | endDate = as.Date("06-08-2018", "\%d-\%m-\%Y"), 65 | username = "username", 66 | password = "password", 67 | AppRoot = wdir, 68 | extract.tif = TRUE, 69 | collection = 6, 70 | extent = ex.navarre) 71 | # set folder path where MOD09GA images will be saved 72 | wdir.mod <- file.path(wdir,"Modis","MOD09GA") 73 | # set the tif folder path 74 | wdir.mod.tif <- file.path(wdir.mod,"tif") 75 | # mosaic and cut navarre region 76 | modMosaic(wdir.mod.tif, 77 | AppRoot = wdir.mod, 78 | out.name = "Navarre", 79 | extent = ex.navarre) 80 | # change src to navarre folder 81 | wdir.mod.navarre <- file.path(wdir.mod,"Navarre") 82 | # calculate NDVI from navarre folder 83 | modFolderToVar(wdir.mod.navarre, 84 | fun = varNDVI, 85 | AppRoot = dirname(wdir.mod.navarre), 86 | overwrite = TRUE) 87 | # change src TS_sample 88 | wdir.mod.ndvi <- file.path(dirname(wdir.mod.navarre),"NDVI") 89 | # create the Rdata 90 | tiles.mod.ndvi<-genSaveTSRData(wdir.mod.ndvi, ts.name = "ModisNDVI") 91 | # remove values out of 0-1 range 92 | tiles.mod.ndvi.lim <- clamp(tiles.mod.ndvi,lower=0,upper=1) 93 | # plot the ndvi images 94 | spplot(tiles.mod.ndvi.lim) 95 | s.end <- Sys.time() 96 | s.end - s.start 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /man/genSmoothingCovIMA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genSmoothingCovIMA.R 3 | \name{genSmoothingCovIMA} 4 | \alias{genSmoothingCovIMA} 5 | \title{Fill data gaps and smooth outliers in a time series of satellite images using 6 | covariates} 7 | \usage{ 8 | genSmoothingCovIMA( 9 | rStack, 10 | cStack, 11 | Img2Process = NULL, 12 | nDays = 3, 13 | nYears = 1, 14 | r.dates, 15 | fact = 5, 16 | fun = mean, 17 | aFilter = c(0.05, 0.95), 18 | snow.mode = FALSE, 19 | out.name = "out", 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{rStack}{a \code{RasterStack} class argument containing a time series of 25 | satellite images. Layer names should contain the date of the image in 26 | "\code{YYYYJJJ}" format.} 27 | 28 | \item{cStack}{a \code{RasterStack} class argument containing a time series of 29 | covariates.} 30 | 31 | \item{Img2Process}{a \code{vector} class argument defining the images to be 32 | filled/smoothed.} 33 | 34 | \item{nDays}{a \code{numeric} argument with the number of previous and 35 | subsequent days that define the temporal neighborhood.} 36 | 37 | \item{nYears}{a \code{numeric} argument with the number of previous and 38 | subsequent years that define the temporal neighborhood.} 39 | 40 | \item{r.dates}{a \code{vector} argument containing the dates of the layers in rstack} 41 | 42 | \item{fact}{a \code{numeric} argument with an aggregation factor of the 43 | anomalies carried out before the interpolation.} 44 | 45 | \item{fun}{a \code{function} used to aggregate the image of anomalies. Both 46 | \code{mean}(default) or \code{median} are acceptted.} 47 | 48 | \item{aFilter}{a \code{vector} with the lower and upper quantiles that define 49 | the outliers of the anomalies. Ex. c(0.05,0.95).} 50 | 51 | \item{snow.mode}{logical argument. If \code{TRUE}, the filling process will 52 | be parallelized using the `\code{raster}' package.} 53 | 54 | \item{out.name}{the name of the folder containing the filled/smoothed images 55 | when saved in the Hard Disk Drive (HDD).} 56 | 57 | \item{...}{arguments for nested functions: 58 | \itemize{ 59 | \item \code{AppRoot} the path where the filled/smoothed time series of 60 | images are saved as GTiff. 61 | }} 62 | } 63 | \value{ 64 | a \code{RasterStack} with the filled/smoothed images. 65 | } 66 | \description{ 67 | \code{genSmoothingCovIMA} runs the image mean anomaly (IMA) algorithm 68 | with covariates \insertCite{militino2018improving}{RGISTools}. 69 | } 70 | \details{ 71 | This filling/smoothing method was developed by 72 | \insertCite{militino2018improving;textual}{RGISTools}. This technique 73 | decomposes a time series of images into a new series of mean and anomaly 74 | images. The procedure applies the filling/smoothing algorithm with covariates 75 | over the anomaly images. The procedure requires a proper definition of a 76 | temporal neighbourhood for the target image and aggregation factor. 77 | } 78 | \examples{ 79 | \dontrun{ 80 | set.seed(0) 81 | # load example ndvi and dem data of Navarre 82 | data(ex.ndvi.navarre) 83 | data(ex.dem.navarre) 84 | # plot example data 85 | genPlotGIS(ex.ndvi.navarre) 86 | genPlotGIS(ex.dem.navarre) 87 | 88 | # distorts 5\% of the original ndvi data by 89 | # altering 50\% its values 90 | for(x in c(2,5)){ 91 | aux <- sampleRandom(ex.ndvi.navarre[[x]], 92 | ncell(ex.ndvi.navarre) * 0.05, 93 | cells = TRUE, 94 | na.rm = TRUE) 95 | ex.ndvi.navarre[[x]][aux[,1]] <- aux[,2] * 1.5 96 | } 97 | genPlotGIS(ex.ndvi.navarre) 98 | 99 | # smoothing the image using the DEM as covariate 100 | smth.ndvi <- genSmoothingCovIMA(rStack = ex.ndvi.navarre, 101 | cStack = ex.dem.navarre, 102 | Img2Process = c(2)) 103 | # plot the distorted 1, smoothed 1, 104 | # distorted 5, smoothed 5 images 105 | plot(stack(ex.ndvi.navarre[[2]], 106 | smth.ndvi[[1]], 107 | ex.ndvi.navarre[[5]], 108 | smth.ndvi[[2]])) 109 | } 110 | } 111 | \references{ 112 | \insertRef{militino2018improving}{RGISTools} 113 | } 114 | -------------------------------------------------------------------------------- /man/genSmoothingIMA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genSmoothingIMA.R 3 | \name{genSmoothingIMA} 4 | \alias{genSmoothingIMA} 5 | \title{Fill data gaps and smooth outliers in a time series of satellite images} 6 | \usage{ 7 | genSmoothingIMA( 8 | rStack, 9 | Img2Fill = NULL, 10 | nDays = 3, 11 | nYears = 1, 12 | fact = 5, 13 | fun = mean, 14 | r.dates, 15 | aFilter = c(0.05, 0.95), 16 | only.na = FALSE, 17 | factSE = 8, 18 | predictSE = FALSE, 19 | snow.mode = FALSE, 20 | out.name = "outname", 21 | ... 22 | ) 23 | } 24 | \arguments{ 25 | \item{rStack}{a \code{RasterStack} class argument containing a time series of 26 | satellite images. Layer names should contain the date of the image in 27 | "\code{YYYYJJJ}" format.} 28 | 29 | \item{Img2Fill}{a \code{vector} argument defining the images to be 30 | filled/smoothed.} 31 | 32 | \item{nDays}{a \code{numeric} argument with the number of previous and 33 | subsequent days that define the temporal neighborhood.} 34 | 35 | \item{nYears}{a \code{numeric} argument with the number of previous and 36 | subsequent years that define the temporal neighborhood.} 37 | 38 | \item{fact}{a \code{numeric} argument with an aggregation factor of the 39 | anomalies before the interpolation.} 40 | 41 | \item{fun}{a \code{function} used to aggregate the image of anomalies. Both 42 | \code{mean} (default) or \code{median} are acceptted.} 43 | 44 | \item{r.dates}{a \code{vector} argument containing the dates of the layers in rstack} 45 | 46 | \item{aFilter}{a \code{vector} with the lower and upper quantiles that define 47 | the outliers of the anomalies. Ex. c(0.05,0.95).} 48 | 49 | \item{only.na}{logical argument. If \code{TRUE} only fills the \code{NA} values. 50 | \code{FALSE} by default.} 51 | 52 | \item{factSE}{the \code{fact} used in the standard error prediction.} 53 | 54 | \item{predictSE}{calculate the standard error instead the prediction.} 55 | 56 | \item{snow.mode}{logical argument. If \code{TRUE}, the filling process will 57 | be parallelized using the `\code{raster}' package.} 58 | 59 | \item{out.name}{the name of the folder containing the smoothed/filled images 60 | when saved in the Hard Disk Device (HDD).} 61 | 62 | \item{...}{arguments for nested functions: 63 | \itemize{ 64 | \item \code{AppRoot} the path where the filled/smoothed time series of 65 | images will be saved in GTiff format. 66 | }} 67 | } 68 | \value{ 69 | a \code{RasterStack} with the filled/smoothed images. 70 | } 71 | \description{ 72 | \code{genSmoothingIMA} is the implementation of a spatio temporal method 73 | called image mean anomaly (IMA) for gap filling and smoothing satellite 74 | data \insertCite{militino2019interpolation}{RGISTools}. 75 | } 76 | \details{ 77 | This filling/smoothing method was developed by 78 | \insertCite{militino2019interpolation;textual}{RGISTools}. This technique decomposes 79 | a time series of images into a new series of mean and anomaly images. The 80 | procedure applies the smoothing algorithm over the anomaly images. The 81 | procedure requires a proper definition of a temporal neighbourhood for the 82 | target image and aggregation factor. 83 | } 84 | \examples{ 85 | \dontrun{ 86 | # load an example of NDVI time series in Navarre 87 | data(ex.ndvi.navarre) 88 | # the 2 images to be filled and the neighbourhood 89 | genPlotGIS(ex.ndvi.navarre) 90 | 91 | # filled images 92 | tiles.mod.ndvi.filled <- genSmoothingIMA(ex.ndvi.navarre, 93 | Img2Fill = c(1), 94 | only.na=TRUE) 95 | # show the filled images 96 | genPlotGIS(tiles.mod.ndvi.filled) 97 | # plot comparison of the cloud and the filled images 98 | tiles.mod.ndvi.comp <- stack(ex.ndvi.navarre[[1]], tiles.mod.ndvi.filled[[1]], 99 | ex.ndvi.navarre[[2]], tiles.mod.ndvi.filled[[2]]) 100 | genPlotGIS(tiles.mod.ndvi.comp, layout=c(2, 2)) 101 | } 102 | } 103 | \references{ 104 | \insertRef{militino2019interpolation}{RGISTools} 105 | } 106 | -------------------------------------------------------------------------------- /man/getRGISToolsOpt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RGISToolsOpts.R 3 | \name{getRGISToolsOpt} 4 | \alias{getRGISToolsOpt} 5 | \title{Get the default value of an RGISTools option} 6 | \usage{ 7 | getRGISToolsOpt(opt, env = optEnv) 8 | } 9 | \arguments{ 10 | \item{opt}{a \code{character} with the name of the option.} 11 | 12 | \item{env}{the environment where the `\code{RGISTools}' option are saved.} 13 | } 14 | \value{ 15 | an option of `RGISTools’ configuration variable. 16 | } 17 | \description{ 18 | \code{getRGISToolsOpt} gets the current value of an `\code{RGISTools}' 19 | configuration variable. This function can be jointly used with 20 | \code{\link{setRGISToolsOpt}} and \code{\link{showRGISToolsOpt}}. 21 | } 22 | \examples{ 23 | # list avaliable options names 24 | showRGISToolsOpt() 25 | # list the Sentinel-2 bands 26 | getRGISToolsOpt("SEN2BANDS") 27 | # list the Landsat-8 bands 28 | getRGISToolsOpt("LS8BANDS") 29 | # list the MODIS09 bands 30 | getRGISToolsOpt("MOD09BANDS") 31 | } 32 | -------------------------------------------------------------------------------- /man/ls7FolderToVar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ls7FolderToVar.R 3 | \name{ls7FolderToVar} 4 | \alias{ls7FolderToVar} 5 | \title{Compute a remote sensing index from a time series of Landsat-7 images} 6 | \usage{ 7 | ls7FolderToVar( 8 | src, 9 | fun, 10 | AppRoot, 11 | getStack = FALSE, 12 | overwrite = FALSE, 13 | verbose = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{src}{the path to the folder with the Landsat-7 multispectral imagery.} 19 | 20 | \item{fun}{a \code{function} that computes the remote sensing index.} 21 | 22 | \item{AppRoot}{the directory of the outcoming time series.} 23 | 24 | \item{getStack}{logical argument. If \code{TRUE}, returns the time series 25 | as a \code{RasterStack}, otherwise the images are saved in the Hard Drive 26 | Device (HDD).} 27 | 28 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 29 | images with the same name.} 30 | 31 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 32 | running steps and warnings.} 33 | 34 | \item{...}{arguments for nested functions. 35 | \itemize{ 36 | \item \code{dates} a vector with the capturing dates being considered 37 | for mosaicking. If not supplied, all dates are mosaicked. 38 | }} 39 | } 40 | \value{ 41 | this function does not return anything, unless \code{getStack = TRUE} 42 | which then returns a \code{RasterStack} with the time series of with the 43 | index. 44 | } 45 | \description{ 46 | \link{ls7FolderToVar} computes a remote sensing index from the 47 | spectral bands of a time series of Landsat-7 images. The images are specified 48 | by the path to the folder that stores the imagery (resulting from the 49 | \code{\link{lsMosaic}} function). The function returns a \code{RasterStack} 50 | with the time series of images of the remote sensing index. 51 | } 52 | \details{ 53 | The function requires the definition of the \code{src} and \code{fun} 54 | arguments. The \code{src} is usually the path resulting from 55 | \code{\link{lsMosaic}}. The \code{fun} argument can be any function from this 56 | package beginning with “var” (\code{\link{varNDVI}}, \code{\link{varEVI}}, 57 | etc.). Custom functions can also be implemented. Caution! It is mandatory to 58 | use level-2 products to get accurate derived variables. 59 | } 60 | \examples{ 61 | \dontrun{ 62 | # load a spatial polygon object of Navarre 63 | data(ex.navarre) 64 | # main output directory 65 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 66 | print(wdir) 67 | # download Landsat-7 images 68 | lsDownSearch(satellite = "ls7", 69 | username = "username", 70 | password = "password", 71 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 72 | endDate = as.Date("20-01-2018", "\%d-\%m-\%Y"), 73 | extent = ex.navarre, 74 | untar = TRUE, 75 | AppRoot = wdir) 76 | # folder with the Landsat-7 untared images 77 | wdir.ls7 <-file.path(wdir,"Landsat7") 78 | wdir.ls7.untar <- file.path(wdir.ls7, "untar") 79 | # mosaic the Landsat-7 images 80 | lsMosaic(wdir.ls7.untar, 81 | AppRoot = wdir.ls7, 82 | out.name = "Navarre", 83 | extent = ex.navarre, 84 | gutils = TRUE) 85 | # folder with the mosaicked images 86 | wdir.ls7.navarre <- file.path(wdir.ls7, "Navarre") 87 | # generate NDVI images of Navarre 88 | wdir.ls7.var <- file.path(wdir.ls7, "Navarre_Variables") 89 | dir.create(wdir.ls7.var) 90 | ls7FolderToVar(wdir.ls7.navarre, 91 | fun = varNDVI, 92 | AppRoot = wdir.ls7.var, 93 | overwrite = TRUE) 94 | 95 | files.ls7.ndvi <- list.files(file.path(wdir.ls7.var,"NDVI"), 96 | pattern = "\\\\.tif$", 97 | full.names = TRUE, 98 | recursive = TRUE) 99 | img.ls7.ndvi <- raster(files.ls7.ndvi[1]) 100 | spplot(img.ls7.ndvi) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /man/ls7LoadMetadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ls7LoadMetadata.R 3 | \name{ls7LoadMetadata} 4 | \alias{ls7LoadMetadata} 5 | \title{Load or update the Landsat-7 metadata file} 6 | \usage{ 7 | ls7LoadMetadata( 8 | AppRoot, 9 | update = FALSE, 10 | verbose = TRUE, 11 | omit.question = TRUE, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{AppRoot}{the directory where the metadata file should be located.} 17 | 18 | \item{update}{logical argument. If \code{TRUE}, updates the metadata file.} 19 | 20 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 21 | running steps and warnings.} 22 | 23 | \item{omit.question}{logical argument. If \code{TRUE}, the question about 24 | loading the metadata is omitted.} 25 | 26 | \item{...}{arguments for nested functions.} 27 | } 28 | \value{ 29 | this function does not return anything, but loads the “.LS7MD” 30 | \code{data.frame} on the environment of the `RGISTools' package. 31 | } 32 | \description{ 33 | \code{ls7LoadMetadata} loads a \code{data.frame} called "\code{.LS7MD}" 34 | with the names of the Landsat-7 images and their metadata. The metadata provides 35 | auxiliary information, such as image quality, acquisition date, cloud cover, 36 | etc. You can find a description of the metadata on the 37 | \href{https://www.usgs.gov/land-resources/nli/landsat/bulk-metadata-service}{USGS's website}. 38 | } 39 | \details{ 40 | All captures done by Landsat-7 are catalogued and documented in a unique csv 41 | file. The size of the file could be larger than 360MB. The function downloads 42 | and imports the metadata into `R', which may take several minutes (roughly 15 43 | minutes in a Intel Core i7-4790, 16Gb of RAM and Hard Drive Device). The 44 | function creates an RData file with the csv metadata. Thus, every time 45 | \code{ls7LoadMetadata} is called, this function loads the existing RData from 46 | the \code{AppRoot} directory, which aims to reduce the loading time of the 47 | metadata in the future. 48 | } 49 | \examples{ 50 | \dontrun{ 51 | # creates a MetaData folder and downloads the csv in the "Path_for_downloading_folder" directory 52 | ls7LoadMetadata(AppRoot = file.path(tempdir(),"Path_for_downloading_folder")) 53 | 54 | # update the metadata file 55 | ls7LoadMetadata(AppRoot = file.path(tempdir(),"Path_for_downloading_folder"), update = TRUE) 56 | 57 | # get metadata data frame 58 | LS7MD <- getRGISToolsOpt("LS7METADATA") 59 | head(LS7MD) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /man/ls8FolderToVar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ls8FolderToVar.R 3 | \name{ls8FolderToVar} 4 | \alias{ls8FolderToVar} 5 | \title{Compute a remote sensing index from a time series of Landsat-8 images} 6 | \usage{ 7 | ls8FolderToVar( 8 | src, 9 | fun, 10 | AppRoot, 11 | getStack = FALSE, 12 | overwrite = FALSE, 13 | verbose = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{src}{path to the folder with the Landsat-8 multispectral image.} 19 | 20 | \item{fun}{a \code{function} that computes the remote sensing index.} 21 | 22 | \item{AppRoot}{the directory of the outcoming time series.} 23 | 24 | \item{getStack}{logical argument. If \code{TRUE}, returns the time series of 25 | images as a \code{RasterStack}, otherwise the images are saved in the Hard 26 | Drive Device (HDD).} 27 | 28 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 29 | images with the same name.} 30 | 31 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 32 | running steps and warnings.} 33 | 34 | \item{...}{arguments for nested functions. 35 | \itemize{ 36 | \item \code{dates} a vector with the capturing dates being considered 37 | for mosaicking. If not supplied, all dates are mosaicked. 38 | }} 39 | } 40 | \value{ 41 | this function does not return anything, unless \code{getStack = TRUE} 42 | which then returns a \code{RasterStack} with the time series of with the 43 | index. 44 | } 45 | \description{ 46 | \code{ls8FolderToVar} computes a remote sensing index from the spectral bands 47 | of a time series of Landsat-8 images. The images are specified by the path to 48 | the folder that stores the imagery (resulting from the \code{\link{lsMosaic}} 49 | function). The function returns a \code{RasterStack} with a time series of 50 | images of the remote sensing index. 51 | } 52 | \details{ 53 | The function requires the definition of the \code{src} and \code{fun} 54 | arguments. The \code{src} is usually the path resulting from 55 | \code{\link{lsMosaic}}.The \code{fun} argument can be any function from this 56 | package beginning with “var” (\code{\link{varNDVI}}, \code{\link{varEVI}}, 57 | etc.). Custom functions can also be implemented. If \code{fun = varRGB}, 58 | then the argument \code{getStack} must be equal to \code{FALSE} and the 59 | red-green-blue (RGB) images must be imported afterwards. Caution! It is mandatory to 60 | use level-2 products to get accurate derived variables. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | # load a spatial polygon object of Navarre 65 | data(ex.navarre) 66 | # main output directory 67 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 68 | print(wdir) 69 | # download Landsat-8 images 70 | lsDownSearch(satellite = "ls8", 71 | username = "username", 72 | password = "password", 73 | startDate = as.Date("01-01-2018","\%d-\%m-\%Y"), 74 | endDate = as.Date("18-01-2018","\%d-\%m-\%Y"), 75 | pathrow = list(c(200, 31), c(200, 30)), 76 | untar = TRUE, 77 | AppRoot = wdir) 78 | # folder with the Landsat-8 untared images 79 | src.ls8 <-file.path(wdir,"Landsat8") 80 | src.ls8.untar <- file.path(src.ls8, "untar") 81 | # mosaic the Landsat-8 images 82 | lsMosaic(src = src.ls8.untar, 83 | AppRoot = src.ls8, 84 | out.name = "Navarre", 85 | extent = ex.navarre, 86 | gutils = TRUE) 87 | # path to the folder with mosaicked images 88 | src.ls8.navarre <- file.path(src.ls8, "Navarre") 89 | # generate NDVI images of Navarre 90 | src.ls8.var <- file.path(src.ls8, "Navarre_Variables") 91 | dir.create(src.ls8.var) 92 | ls8FolderToVar(src.ls8.navarre, 93 | fun = varNDVI, 94 | AppRoot = src.ls8.var, 95 | overwrite = TRUE) 96 | 97 | files.ls8.ndvi <- list.files(file.path(src.ls8.var,"NDVI"), 98 | pattern = "\\\\.tif$", 99 | full.names = TRUE, 100 | recursive = TRUE) 101 | 102 | img.ls8.ndvi <- raster(files.ls8.ndvi[1]) 103 | spplot(img.ls8.ndvi) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /man/ls8LoadMetadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ls8LoadMetadata.R 3 | \name{ls8LoadMetadata} 4 | \alias{ls8LoadMetadata} 5 | \title{Load or update the Landsat-8 metadata file} 6 | \usage{ 7 | ls8LoadMetadata( 8 | AppRoot, 9 | update = FALSE, 10 | verbose = TRUE, 11 | omit.question = FALSE, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{AppRoot}{the directory where the metadata file should be located.} 17 | 18 | \item{update}{logical argument. If \code{TRUE}, updates the metadata file.} 19 | 20 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 21 | running steps and warnings.} 22 | 23 | \item{omit.question}{logical argument. If \code{TRUE}, the question about 24 | loading the metadata is omitted.} 25 | 26 | \item{...}{arguments for nested functions.} 27 | } 28 | \value{ 29 | this function does not return anything, but loads the “.LS8MD” 30 | \code{data.frame} on the `RGISTools' package. 31 | } 32 | \description{ 33 | \code{ls8LoadMetadata} loads a \code{data.frame} called "\code{.LS8MD}" 34 | with the names of the Landsat-8 images and their metadata. The metadata provides 35 | auxiliary information, such as image quality, acquisition date, cloud cover, 36 | etc. You can find a description of the metadata on the 37 | \href{https://www.usgs.gov/land-resources/nli/landsat/bulk-metadata-service}{USGS's website}. 38 | } 39 | \details{ 40 | All captures done by Landsat-8 are catalogued and documented in a unique csv 41 | file. The size of the file could be larger than 210MB. The function downloads 42 | and imports the metadata into `R', which may take several minutes (roughly 7 43 | minutes in a Intel Core i7-4790, 16Gb of RAM and Hard Drive Device). The 44 | function creates an RData file with the csv metadata. Thus, every time 45 | \code{ls8LoadMetadata} is called, this function loads the existing RData from 46 | the \code{AppRoot} directory, which aims to reduce the loading time of the 47 | metadata in the future. 48 | } 49 | \examples{ 50 | \dontrun{ 51 | 52 | # creates a MetaData folder and downloads the csv in the "Path_for_downloading_folder" directory 53 | ls8LoadMetadata(AppRoot = file.path(tempdir(),"Path_for_downloading_folder")) 54 | 55 | # update the metadata file 56 | ls8LoadMetadata(AppRoot = file.path(tempdir(),"Path_for_downloading_folder"), update = TRUE) 57 | 58 | # get metadata data frame 59 | LS8MD <- getRGISToolsOpt("LS8METADATA") 60 | head(LS8MD) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /man/lsCloudMask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsCloudMask.R 3 | \name{lsCloudMask} 4 | \alias{lsCloudMask} 5 | \title{Create cloud masks for Landsat images} 6 | \usage{ 7 | lsCloudMask( 8 | src, 9 | AppRoot, 10 | out.name, 11 | ls8 = TRUE, 12 | overwrite = FALSE, 13 | verbose = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{src}{the path to the folder with the untarred images from Landsat-7 or 19 | Landsat-8.} 20 | 21 | \item{AppRoot}{the directory where the cloud masks are saved.} 22 | 23 | \item{out.name}{the name of the folder that stores the outputs. 24 | If the arguemnt is not defined the folder will be named as "CloudMask".} 25 | 26 | \item{ls8}{\code{logical} argument. Defines the lansat satellite number. 27 | If \code{TRUE} clouds for landsat-8 are computed, otherwise, landsat 4-7 28 | clouds are computed.} 29 | 30 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 31 | images with the same name.} 32 | 33 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 34 | running steps and warnings.} 35 | 36 | \item{...}{arguments for nested functions. 37 | \itemize{ 38 | \item \code{dates} a vector with the dates being considered 39 | for creating cloud masks. This argument is optional. 40 | }} 41 | } 42 | \value{ 43 | this function does not return anything. It saves the cloud masks (CLD) 44 | as GTiff files in the \code{AppRoot} directory. 45 | } 46 | \description{ 47 | \code{lsCloudMask} creates a cloud mask derived from the band for quality 48 | assurance (BQA) from Landsat-7 or Landsat-8 time series. The function is 49 | applied to untarred images, such as those resulting from 50 | \code{\link{lsDownload}} or \code{\link{lsDownSearch}}. The result is a new 51 | image band, called cloud (CLD), that is saved as separate GoeTiffs. 52 | } 53 | \details{ 54 | The valid range for the \code{sensitivity} threshold is 0-80000. By defualt, 55 | the argument is set to 28000. We recommend 6000 and 28000 for Landsat-7 and 56 | Landsat-8 respectively. The \code{NA} and \code{1} values of the mask represent 57 | cloudy and clear-sky pixels pixels respectively. 58 | } 59 | \examples{ 60 | \dontrun{ 61 | # load a spatial polygon object of Navarre 62 | data(ex.navarre) 63 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 64 | print(wdir) 65 | 66 | # search and download images from Landsat-8 between 67 | # 01-01-2018 and 20-01-2018 for the region of Navarre 68 | lsDownSearch(satellite = "ls8", 69 | username = "username", 70 | password = "password", 71 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 72 | endDate = as.Date("20-01-2018", "\%d-\%m-\%Y"), 73 | pathrow = list(c(200, 31), c(200, 30)), 74 | untar = TRUE, 75 | AppRoot = wdir) 76 | 77 | # define the path where the GTiff images are located 78 | wdir.ls8 <- file.path(wdir,"Landsat8") 79 | wdir.ls8.untar <- file.path(wdir.ls8,"untar") 80 | 81 | # mosaic and crop the imagery 82 | lsMosaic(src = wdir.ls8.untar, 83 | AppRoot = wdir.ls8, 84 | out.name = "Navarre", 85 | extent = ex.navarre, 86 | gutils = TRUE, # using gdalUtils 87 | overwrite = TRUE) # overwrite 88 | 89 | # generate the path where mosaicked images are located 90 | wdir.ls8.navarre <- file.path(wdir.ls8, "Navarre") 91 | 92 | # calculate the cloud mask from QC layer 93 | lsCloudMask(src=wdir.ls8.navarre, 94 | overwrite=TRUE) 95 | 96 | # load the B1 layer and calculate the CLD layer 97 | files.ls8.navarre.path <- list.files(wdir.ls8.navarre, 98 | full.names = TRUE, 99 | recursive = TRUE, 100 | pattern = "\\\\.tif$") 101 | tiles.ls8.cld <- files.ls8.navarre.path[grepl("CLD",files.ls8.navarre.path)] 102 | tiles.ls8.b1 <- files.ls8.navarre.path[grepl("B1.tif",files.ls8.navarre.path)] 103 | img.ls8.cld <- lapply(tiles.ls8.cld,raster) 104 | img.ls8.b1 <- lapply(tiles.ls8.b1,raster) 105 | 106 | # calculate cloud free b1 layers 107 | img.ls8.b1.cloud.free <- img.ls8.b1[[1]] * img.ls8.cld[[1]] 108 | spplot(img.ls8.b1.cloud.free) 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /man/lsDownSearch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsDownSearch.R 3 | \name{lsDownSearch} 4 | \alias{lsDownSearch} 5 | \title{Search and download Landsat-7 or Landsat-8 images} 6 | \usage{ 7 | lsDownSearch( 8 | satellite, 9 | username, 10 | password, 11 | AppRoot, 12 | lvl = 1, 13 | product = c("sr", "source_metadata"), 14 | verbose = FALSE, 15 | untar = TRUE, 16 | raw.rm = FALSE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{satellite}{string containing the type of satellite 22 | (\code{"ls7"} or \code{"ls8"}).} 23 | 24 | \item{username}{USGS’s `EarthExplorer' username.} 25 | 26 | \item{password}{USGS’s `EarthExplorer' password.} 27 | 28 | \item{AppRoot}{the download directory.} 29 | 30 | \item{lvl}{a number specifying the processing level. Default value, 1.} 31 | 32 | \item{product}{a \code{character} vector with the requested Level-2 products. 33 | By default \code{c("sr", "source_metadata")}.} 34 | 35 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 36 | running steps and warnings.} 37 | 38 | \item{untar}{logical argument. If \code{TRUE}, untars downloaded images.} 39 | 40 | \item{raw.rm}{logical argument. If \code{TRUE}, removes the raw images.} 41 | 42 | \item{...}{argumetns for nested functions: 43 | \itemize{ 44 | \item \code{dates} a vector with the capturing dates being searched. This 45 | argument is mandatory if \code{startDate} and \code{endDate} are not defined. 46 | \item \code{startDate} a \code{Date} class object with the starting date of the 47 | study period. This argument is mandatory if 48 | \code{dates} is not defined. 49 | \item \code{endDate} a \code{Date} class object with the ending date of the 50 | study period. This argument is mandatory if 51 | \code{dates} is not defined. 52 | \item \code{region} a \code{Spatial*}, projected \code{raster*}, or \code{sf*} class object 53 | defining the area of interest. 54 | \item any argument for \code{\link{ls8Search}}/\code{\link{ls7Search}} or 55 | \code{\link{lsDownload}}. 56 | }} 57 | } 58 | \value{ 59 | this function does not return anything. It saves the imagery as 60 | `tar.gz’ (and GTiff files) in a folder called `raw’ (`untar’) in the 61 | \code{AppRoot} directory. 62 | } 63 | \description{ 64 | \code{lsDownSearch} searches and downloads Landsat-7 or Landsat-8 images 65 | concerning a particular location and time interval from the 66 | \href{https://earthexplorer.usgs.gov/}{`EarthExplorer' repository}. 67 | Images are saved as GTiff files in the \code{AppRoot} directory. 68 | } 69 | \details{ 70 | \code{lsDownSearch} is a wrapper function of \code{\link{ls7Search}}, 71 | \code{\link{ls8Search}}, and \code{\link{lsDownload}} to search and 72 | download images in a single step. The function requires USGS's `EarthExplorer' 73 | credentials, which can be obtained 74 | \href{https://ers.cr.usgs.gov/register/}{here}. 75 | 76 | The files from `EarthExplorer' are compressed as ‘tar.gz’. \code{lsDownSearch} 77 | decompresses the images and obtains the corresponding GTiffs. The GTiffs are 78 | saved in the \code{AppRoot} directory. To change this option, provide 79 | \code{AppRoot = “full path”}. When \code{untar=TRUE}, the function untars 80 | the imagery in this location. Image decompression duplicates the information 81 | due to the presence of both, compressed and decompressed images. Set 82 | \code{raw.rm = TRUE} to remove the former ones. 83 | } 84 | \examples{ 85 | \dontrun{ 86 | # load a spatial polygon object of Navarre 87 | data(ex.navarre) 88 | 89 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 90 | print(wdir) 91 | # search and download the images from Landsat-8 between 92 | # 01-01-2018 and 20-01-2018 for the region of Navarre 93 | lsDownSearch(satellite = "ls8", 94 | username = "username", 95 | password = "password", 96 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 97 | endDate = as.Date("20-01-2018", "\%d-\%m-\%Y"), 98 | extent = ex.navarre, 99 | AppRoot = wdir) 100 | 101 | # remove metadata to free memory space 102 | lsRemoveMetadata() 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /man/lsEspaDownloadOrders.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsEspaDownloadOrders.R 3 | \name{lsEspaDownloadOrders} 4 | \alias{lsEspaDownloadOrders} 5 | \title{Downloads the images that have been pre-processed by ESPA} 6 | \usage{ 7 | lsEspaDownloadOrders( 8 | orders, 9 | AppRoot, 10 | username = NULL, 11 | password = NULL, 12 | c.handle = NULL, 13 | verbose = FALSE, 14 | overwrite = FALSE, 15 | n.attempts = 5, 16 | untar = FALSE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{orders}{a list of the requested images as returned by 22 | \code{\link{lsEspaGetOrderImages}}.} 23 | 24 | \item{AppRoot}{the download directory.} 25 | 26 | \item{username}{USGS's `EarthExplorer' username.} 27 | 28 | \item{password}{USGS's `EarthExplorer' password.} 29 | 30 | \item{c.handle}{a curl handler created with the package `\code{curl}' to stablish 31 | a connection with a preset password and username. This argument is mandatory 32 | if \code{username} and \code{password} are not defined.} 33 | 34 | \item{verbose}{logical argument. If TRUE, the function prints the running 35 | steps and warnings.} 36 | 37 | \item{overwrite}{logical argument. If TRUE, overwrites the existing images 38 | with the same name.} 39 | 40 | \item{n.attempts}{the number of attempts to download an image in case it 41 | becomes corrupted files.} 42 | 43 | \item{untar}{logical argument. If TRUE, untars the downloaded images.} 44 | 45 | \item{...}{argument for nested functions} 46 | } 47 | \value{ 48 | this function does not return anything. It saves the imagery as 49 | `tar.gz’ (and GTiff files) in a folder called `raw’ (`untar’) in the 50 | \code{AppRoot} directory. 51 | } 52 | \description{ 53 | \code{lsEspaDownloadOrders} downloads a set of images processed by the EROS 54 | Centre Science Processing Architecture (ESPA) through its application 55 | programming interface (API). 56 | } 57 | \details{ 58 | This function is part of a group of functions used to pre-process Landsat 59 | level-1 images. The pre-processing is carried out by ESPA on demand. 60 | \code{\link{lsEspaDownloadOrders}} downloads the images whose processing was 61 | completed according to \code{\link{lsEspaUpdateOrders}}. The function 62 | downloads and saves the imagery under the \code{AppRoot} directory. The 63 | function automatically creates two folders, called "raw" and "untar", to 64 | save the compressed and decompressed images respectively. The imagery is only 65 | decompressed when \code{untar = TRUE}. 66 | } 67 | \examples{ 68 | \dontrun{ 69 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 70 | print(wdir) 71 | # search Landsat-7 level-1 72 | sres <- ls7Search(startDate = as.Date("01-01-2017", "\%d-\%m-\%Y"), 73 | endDate = as.Date("15-01-2017", "\%d-\%m-\%Y"), 74 | lonlat = c(-1.64323, 42.81687), 75 | AppRoot = wdir) 76 | # request to ESPA the prepocessing of level-1 images to get the surface reflectance 77 | order <- lsEspaOrderImages(search.res = sres, 78 | username = "username", 79 | password = "password", 80 | product = 'sr', 81 | verbose = FALSE) 82 | # get an ID for our request 83 | orders <- lsEspaGetOrderImages(username = "username", 84 | password = "password") 85 | # follow up the status of the request 86 | orders <- lsEspaUpdateOrders(orders = orders, 87 | username = "username", 88 | password = "password") 89 | # saving directory 90 | wdir.ls7.ESPA <- file.path(wdir,"Landsat7","ESPA") 91 | dir.create(wdir.ls7.ESPA, recursive = TRUE) 92 | # download when status says: complete 93 | lsEspaDownloadOrders(orders = orders, 94 | username = "username", 95 | password = "password", 96 | untar = TRUE, 97 | AppRoot = wdir.ls7.ESPA) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /man/lsEspaGetOrderImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsEspaGetOrderImages.R 3 | \name{lsEspaGetOrderImages} 4 | \alias{lsEspaGetOrderImages} 5 | \title{Gets a first response from ESPA regarding a recent request} 6 | \usage{ 7 | lsEspaGetOrderImages( 8 | username = NULL, 9 | password = NULL, 10 | c.handle = NULL, 11 | order.list = NULL, 12 | verbose = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{username}{USGS's `EarthExplorer' username.} 17 | 18 | \item{password}{USGS's `EarthExplorer' password.} 19 | 20 | \item{c.handle}{a curl handler created with the package `\code{curl}' to 21 | stablish a connection with a preset password and username. This argument 22 | is mandatory if \code{username} and \code{password} are not defined.} 23 | 24 | \item{order.list}{a list of orders from \code{\link{lsEspaOrderImages}}} 25 | 26 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 27 | running steps and warnings.} 28 | } 29 | \description{ 30 | \code{lsEspaGetOrderImages} obtains the identification number and the status 31 | of the request from the EROS Centre Science Processing Architecture (ESPA). 32 | } 33 | \details{ 34 | This function is part of a group of functions used to pre-process Landsat 35 | level-1 images. The pre-processing is carried out by ESPA on demand. 36 | \code{lsEspaGetOrderImages} takes the identification (ID) number of a 37 | request carried out by \code{\link{lsEspaOrderImages}}. This ID is used to 38 | follow up the processing status with \code{\link{lsEspaUpdateOrders}}. All the 39 | status messages and their interpretation can be found in the ESPA's API 40 | \href{https://www.usgs.gov/media/files/eros-science-processing-architecture-demand-interface-user-guide}{User Guide}. 41 | } 42 | \examples{ 43 | \dontrun{ 44 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 45 | # search Landsat 7 level-2 46 | sres <- ls7Search(startDate = as.Date("01-01-2017", "\%d-\%m-\%Y"), 47 | endDate = as.Date("07-01-2017", "\%d-\%m-\%Y"), 48 | lonlat = c(-1.64323, 42.81687), 49 | AppRoot = wdir) 50 | # request to ESPA the pre-pocessing of level-2 images to 51 | # get the surface reflectance 52 | order <- lsEspaOrderImages(search.res = sres, 53 | username = "username", 54 | password = "password", 55 | product = 'sr', 56 | verbose = FALSE) 57 | # get an ID for our request 58 | lsEspaGetOrderImages(username = "username", 59 | password = "password") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /man/lsEspaOrderImages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsEspaOrderImages.R 3 | \name{lsEspaOrderImages} 4 | \alias{lsEspaOrderImages} 5 | \title{Make a request to ESPA for pre-processing Landsat images} 6 | \usage{ 7 | lsEspaOrderImages( 8 | search.res, 9 | username, 10 | password, 11 | product = c("sr", "source_metadata"), 12 | verbose = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{search.res}{the results from \code{\link{ls7Search}} or 17 | \code{\link{ls8Search}}.} 18 | 19 | \item{username}{USGS's `EarthExplorer' username.} 20 | 21 | \item{password}{USGS's `EarthExplorer' password.} 22 | 23 | \item{product}{the acronym of the requested product (see the details).} 24 | 25 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 26 | running steps and warnings.} 27 | } 28 | \value{ 29 | this function does not return anything. It makes a petition to 30 | process level-1 images before doing the download. 31 | } 32 | \description{ 33 | \code{lsEspaOrder} makes a request to the EROS Centre Science Processing 34 | Architecture (ESPA) to further process level-1 Landsat scenes. 35 | } 36 | \details{ 37 | Landsat Level-1 images are pre-processed on demand by the EROS Centre Science 38 | Processing Architecture (ESPA). An order is placed to ESPA with the level-1 39 | images that must be pre-processed (\code{search.res} and the requested 40 | final product (\code{product}). The products are identified by the following 41 | short-names: 42 | \itemize{ 43 | \item \code{toa}: for top of atmosphere reflectance. 44 | \item \code{bt}: for brightness temperature (thermal band TOA processing). 45 | \item \code{sr}: for surface reflectance. 46 | \item \code{sr_ndvi}: the normalized difference vegetation index from 47 | surface reflectance imagery. 48 | \item \code{sr_evi}: the enhanced vegetation index from surface 49 | reflectance imagery. 50 | \item \code{sr_savi}: the soil adjusted vegetation index from surface 51 | reflectance imagery. 52 | \item \code{sr_msavi}: the modified soil adjusted vegetation index from 53 | surface reflectance imagery. 54 | \item \code{sr_ndmi}: the normalized difference moisture index from surface 55 | reflectance imagery. 56 | \item \code{sr_nbr}: the normalized burn ratio from surface reflectance 57 | imagery. 58 | \item \code{sr_nbr2}: the normalized burn ratio 2 index from surface 59 | reflectance imagery. 60 | \item \code{prixel_qa}: for pixel quality assurance. 61 | } 62 | } 63 | \examples{ 64 | \dontrun{ 65 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 66 | # search Landsat 7 level-1 67 | sres <- ls7Search(startDate = as.Date("01-01-2017", "\%d-\%m-\%Y"), 68 | endDate = as.Date("07-01-2017", "\%d-\%m-\%Y"), 69 | lonlat = c(-1.64323, 42.81687), 70 | AppRoot = wdir) 71 | # request to ESPA the pre-pocessing of level-1 images 72 | # to get the surface reflectance 73 | order <- lsEspaOrderImages(search.res = sres, 74 | username = "username", 75 | password = "password", 76 | product = 'sr', 77 | verbose = FALSE) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /man/lsEspaUpdateOrders.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsEspaUpdateOrders.R 3 | \name{lsEspaUpdateOrders} 4 | \alias{lsEspaUpdateOrders} 5 | \title{Updates the status of a request made to ESPA} 6 | \usage{ 7 | lsEspaUpdateOrders( 8 | orders, 9 | username = NULL, 10 | password = NULL, 11 | c.handle = NULL, 12 | verbose = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{orders}{a list of the requested orders as returned by 17 | \code{\link{lsEspaGetOrderImages}}.} 18 | 19 | \item{username}{USGS's `EarthExplorer' username.} 20 | 21 | \item{password}{USGS's `EarthExplorer' password.} 22 | 23 | \item{c.handle}{a curl handler created with the package `\code{curl}' to 24 | stablish a connection with a preset password and username. This argument 25 | is mandatory if \code{username} and \code{password} are not defined.} 26 | 27 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 28 | running steps and warnings.} 29 | } 30 | \value{ 31 | this function returns a \code{dataframe} with the updated order information from ESPA. 32 | } 33 | \description{ 34 | \code{lsEspaUpdateOrders} checks the current status of a request made to EROS 35 | Centre Science Processing Architecture (ESPA) to pre-process Landsat level-1 36 | images 37 | } 38 | \details{ 39 | This function is part of a group of functions used to pre-process Landsat 40 | level 1 images. The pre-processing is carried out by ESPA on demand. 41 | \code{lsEspaUpdateOrders} uses the ID numbers gathered by 42 | \code{\link{lsEspaGetOrderImages}} regarding previous order requests 43 | to check the processing status. The function has to be run repeatedly 44 | until the status message states “complete”. All the status messages and their 45 | interpretation can be found in the ESPA's API 46 | \href{https://www.usgs.gov/media/files/eros-science-processing-architecture-demand-interface-user-guide}{User Guide}. 47 | } 48 | \examples{ 49 | \dontrun{ 50 | src <- file.path(tempdir(),"Path_for_downloading_folder") 51 | # search Landsat 7 level-1 52 | search.res <- ls7Search(startDate = as.Date("01-01-2017", "\%d-\%m-\%Y"), 53 | endDate = as.Date("15-01-2017", "\%d-\%m-\%Y"), 54 | lonlat = c(-1.64323, 42.81687), 55 | AppRoot = src) 56 | # request to ESPA the prepocessing of level-1 images to get the surface reflectance 57 | orders <- lsEspaOrderImages(search.res = search.res, 58 | username = "username", 59 | password = "password", 60 | product = 'sr', 61 | verbose = FALSE) 62 | # get an ID for our request 63 | orders <- lsEspaGetOrderImages(username = "username", 64 | password = "password") 65 | # follow up the status of the request 66 | orders <- lsEspaUpdateOrders(orders = orders, 67 | username = "username", 68 | password = "password") 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /man/lsGetDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genMissionGetDates.R 3 | \name{lsGetDates} 4 | \alias{lsGetDates} 5 | \title{Return the capturing dates of Landsat-7 or Landsat-8 images} 6 | \usage{ 7 | lsGetDates(str, ...) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the Landsat-7 or 11 | Landsat-8 images from which the capturing date is retrieved.} 12 | 13 | \item{...}{arguments for nested functions: 14 | \itemize{ 15 | \item \code{format} the format of the date being returned. 16 | }} 17 | } 18 | \value{ 19 | a \code{Date} class object with the date of the Landsat image or \code{character} class, 20 | if the \code{format} argument is used. 21 | } 22 | \description{ 23 | \code{lsGetDates} reads the official name of a Landsat-7 or Landsat-8 image 24 | and returns the capturing date, as a \code{Date} class object. 25 | } 26 | \details{ 27 | The function works with file names (or their paths) regardless of their 28 | extension. The function accepts more than on file path, which can be passed 29 | as a vector of \code{character}s. Dates are returned as `\code{YYYY-mm-dd}' by 30 | default. If another format is required, it can be modified through the 31 | argument \code{format}. 32 | } 33 | \examples{ 34 | # getting the capturing date from the name of a Landsat-8 image 35 | file.ls8 <- "LC82000312017010LGN01.tar.gz" 36 | date.ls8 <- lsGetDates(file.ls8) 37 | print(date.ls8) 38 | print(format(date.ls8, "\%Y\%j")) 39 | 40 | # getting the capturing date from the name of a Landsat-7 and a Landsat-8 41 | # image 42 | file.ls7 <- c("LE72330822017009ASN01") 43 | date.ls7 <- lsGetDates(file.ls7) 44 | print(date.ls7) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/lsGetPathRow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsGetPathRow.R 3 | \name{lsGetPathRow} 4 | \alias{lsGetPathRow} 5 | \title{Return the pathrow of a tile of Landsat-7 or Landsat-8 images} 6 | \usage{ 7 | lsGetPathRow(str) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the Landsat-7 or Landsa-8 11 | images from which the tile’s path and row numbers are retrieved.} 12 | } 13 | \value{ 14 | a string with the path and row in "\code{PPPRRR}" format. 15 | } 16 | \description{ 17 | \code{lsGetPathRow} reads the official name of a Landsat-7 or Landsa-8 image 18 | and returns the tile’s path and row number, in "PPPRRR" format (Landsat 19 | naming convention). 20 | } 21 | \examples{ 22 | # example of getting date from Landsat-8 image name 23 | str <- c("LE72000302011066ASN00", 24 | "LE72000302011066ASN00") 25 | pr <- lsGetPathRow(str) 26 | print(pr) 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/lsMosaic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsMosaic.R 3 | \name{lsMosaic} 4 | \alias{lsMosaic} 5 | \title{Mosaic a set of Landsat-7 or Landsat-8 images} 6 | \usage{ 7 | lsMosaic( 8 | src, 9 | AppRoot, 10 | region, 11 | out.name = "outfile", 12 | verbose = FALSE, 13 | gutils = TRUE, 14 | overwrite = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{src}{the path to the folder with the Landsat-7 or Landsa-8 images in 20 | GTiff format.} 21 | 22 | \item{AppRoot}{the directory to save the mosaicked images.} 23 | 24 | \item{region}{a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 25 | defining the area of interest.} 26 | 27 | \item{out.name}{the name of the folder that stores the outputs. By default, 28 | “outfile” is assigned.} 29 | 30 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 31 | running steps and warnings.} 32 | 33 | \item{gutils}{logical argument. If \code{TRUE}, the function uses `GDAL' 34 | utilities for mosaicking.} 35 | 36 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 37 | images with the same name.} 38 | 39 | \item{...}{arguments for nested functions: 40 | \itemize{ 41 | \item \code{pathrow} a list of vectors with the path and row numbers of 42 | the tiles concerning the region of interest. This argument is mandatory if 43 | \code{region} is not provided. 44 | \item \code{bFilter} a vector with the bands to be mosaicked. If not 45 | supplied, all bands are mosaicked. 46 | \item \code{dates} a vector with the capturing dates being considered 47 | for mosaicking. If not supplied, all dates are mosaicked. 48 | }} 49 | } 50 | \value{ 51 | this function does not return anything. It saves the imagery in the 52 | \code{AppRoot} directory. 53 | } 54 | \description{ 55 | \code{lsMosaic} merges the Landsat-7 or Landsat-8 imagery that covers a 56 | region of interest on the same dates. 57 | } 58 | \details{ 59 | The function mosaics the imagery in the \code{src} folder. The folder can 60 | hold GTiff images from several tiles, dates and bands. When only a subset 61 | of dates has to be mosaicked, the dates should be provided through the 62 | argument \code{dateFilter}. The dates must be provided as a \code{Date} 63 | class objects. For further details about the \code{bFilter} argument go 64 | to \code{\link{lsDownload}}.Once mosaicked, the images can be cropped to fit 65 | the extent (optional). The extent can be defined in any coordinate reference 66 | system, since \code{lsMosaic} automatically reprojects the extent to match 67 | the projection of the image. The outputs are placed in the \code{AppRoot} 68 | directory, under the folder named as \code{out.name}. If no name is provided, 69 | the folder isn named “outfile”. To use `\code{gutils = TRUE}', a proper installation of `GDAL' 70 | and the `\code{gdalUtils}' library is required. This method is faster than 71 | native `R' functions. 72 | } 73 | \examples{ 74 | \dontrun{ 75 | # load a spatial polygon object of Navarre 76 | data(ex.navarre) 77 | # main output directory 78 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 79 | print(wdir) 80 | # download Landsat-8 images 81 | lsDownSearch(satellite = "ls8", 82 | username = "username", 83 | password = "password", 84 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 85 | endDate = as.Date("20-01-2018", "\%d-\%m-\%Y"), 86 | extent = ex.navarre, 87 | untar = TRUE, 88 | AppRoot = wdir) 89 | # folder with the Landsat-8 untared images 90 | wdir.ls8 <- file.path(wdir, "Landsat8") 91 | tif.src <- file.path(wdir.ls8,"untar") 92 | # mosaic the Landsat-8 images 93 | lsMosaic(src = tif.src, 94 | AppRoot = wdir.ls8, 95 | out.name = "Navarre", 96 | extent = ex.navarre, 97 | gutils = TRUE, # using gdalUtils 98 | overwrite = TRUE) # overwrite 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /man/lsPreview.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsPreview.R 3 | \name{lsPreview} 4 | \alias{lsPreview} 5 | \title{Preview Landsat-7 or Landsat-8 satellite images} 6 | \usage{ 7 | lsPreview( 8 | searchres, 9 | n, 10 | dates, 11 | lpos = c(3, 2, 1), 12 | add.Layer = FALSE, 13 | verbose = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{searchres}{a \code{data.frame} with the results from 19 | \code{\link{ls7Search}} or \code{\link{ls8Search}}.} 20 | 21 | \item{n}{a \code{numeric} argument identifying the location of the image in 22 | \code{searchres}.} 23 | 24 | \item{dates}{a vector of \code{Date}s being considered 25 | for previewing. This argument is mandatory if 26 | \code{n} is not defined.} 27 | 28 | \item{lpos}{vector argument. Defines the position of the red-green-blue 29 | layers to enable false color visualization.} 30 | 31 | \item{add.Layer}{logical argument. If \code{TRUE}, the function plots the 32 | image on an existing map. Allows combinations of images on a map using 33 | \code{\link{senPreview}} and \code{\link{modPreview}} functions.} 34 | 35 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 36 | running steps and warnings.} 37 | 38 | \item{...}{arguments for nested functions: 39 | \itemize{ 40 | \item arguments allowed by the \code{viewRGB} function from the 41 | \code{mapview} packages are valid arguments. 42 | }} 43 | } 44 | \value{ 45 | this function does not return anything. It displays a preview of 46 | one of the search results. 47 | } 48 | \description{ 49 | \code{lsPreview} shows a preview of the \code{n}-th image from a set of 50 | search results on an interactive map. 51 | } 52 | \details{ 53 | The function shows a preview of the \code{n}-th output image from a search 54 | in the Landsat archives (\code{\link{ls7Search}} or \code{\link{ls8Search}}, 55 | with \code{browseAvailable = "Y"}). The preview is downloaded from 56 | \href{https://www.usgs.gov/land-resources/nli/landsat/bulk-metadata-service}{USGS Bulk Metadata Service}. 57 | Please, be aware that only some images may have a preview. 58 | } 59 | \examples{ 60 | \dontrun{ 61 | # load a spatial polygon object of Navarre 62 | data(ex.navarre) 63 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 64 | # retrieve jpg images covering Navarre between 2011 and 2013 65 | sres <- ls7Search(startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 66 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 67 | extent = ex.navarre, 68 | precise = TRUE, 69 | browseAvaliable = "Y", 70 | AppRoot = wdir) 71 | lsPreview(sres, 1) 72 | # filter the images with less than 1\% pixels covered by clouds 73 | sres.cloud.free = subset(sres, sres$cloudCover < 1) 74 | lsPreview(sres.cloud.free, 1) 75 | lsPreview(sres.cloud.free, 2,add.Layer = TRUE) 76 | # plot all the images in one date 77 | lsPreview(sres.cloud.free,dates=as.Date("2013-09-04")) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /man/lsRemoveMetadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsRemoveMetadata.R 3 | \name{lsRemoveMetadata} 4 | \alias{lsRemoveMetadata} 5 | \title{Remove the Landsat-7 or Lansat-8 metadata from the environment} 6 | \usage{ 7 | lsRemoveMetadata() 8 | } 9 | \description{ 10 | \code{lsRemoveMetadata} removes Landsat-7 and/or Landsat-8 (\code{.LS7MD}/ 11 | \code{.LS8MD}) metadata from the environment in `R'. 12 | } 13 | \details{ 14 | The metadata file is loaded in `R' with \code{\link{ls7Search}}, 15 | \code{\link{ls8Search}} and \code{\link{lsDownSearch}}. \code{lsRemoveMetadata} 16 | removes the metadata and frees up valuable RAM. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | # creates a MetaData folder and downloads the csv file 21 | # in the current working directory 22 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 23 | print(wdir) 24 | ls8LoadMetadata(AppRoot = wdir) 25 | lsRemoveMetadata() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/lsSearch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsSearch.R 3 | \name{lsSearch} 4 | \alias{lsSearch} 5 | \title{Search Landsat 7-8 images using EarthExplorer API} 6 | \usage{ 7 | lsSearch( 8 | product, 9 | startDate, 10 | endDate, 11 | region, 12 | username, 13 | password, 14 | dates, 15 | logout = TRUE, 16 | verbose = FALSE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{product}{the name of the dataset. Avaliable names saved in `RGISTools' 22 | (\code{getRGISToolsOpt("EE.DataSets")}).} 23 | 24 | \item{startDate}{a \code{Date} class object with the starting date of the 25 | study period. This argument is mandatory if 26 | \code{dates} is not defined.} 27 | 28 | \item{endDate}{a \code{Date} class object with the ending date of the 29 | study period. This argument is mandatory if 30 | \code{dates} is not defined.} 31 | 32 | \item{region}{a \code{Spatial*}, projected \code{raster*}, o 33 | r \code{sf} class object defining the area of interest. This argument is 34 | mandatory if \code{pathrow}, \code{extent}, or \code{lonlat} are not defined.} 35 | 36 | \item{username}{NASA’s `EarthData' username.} 37 | 38 | \item{password}{NASA’s `EarthData' password.} 39 | 40 | \item{dates}{a vector with the capturing dates being searched. This 41 | argument is mandatory if \code{startDate} and \code{endDate} are not defined.} 42 | 43 | \item{logout}{logical argument. If \code{TRUE}, logges out from EarthExplorer 44 | API} 45 | 46 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 47 | running steps and warnings.} 48 | 49 | \item{...}{arguments for nested functions: 50 | \itemize{ 51 | \item \code{pathrow} a list of vectors with the path and row numbers of 52 | the tiles concerning the region of interest. This argument is mandatory 53 | if \code{region}, \code{extent} or \code{lonlat} are not provided. Ex. 54 | \code{list(c(200,31),c(200,30))}. 55 | \item \code{lonlat} a vector with the longitude/latitude (EPSG:4326) 56 | coordinates of the point of interest. Ex. \code{c(-1.64323,42.81687)}. 57 | This argument is mandatory if \code{region}, \code{pathrow}, or \code{lonlat} 58 | are not defined. 59 | \item \code{extent} an \code{extent}, \code{Raster*}, or 60 | \code{Spatial*} object representing the region of interest with 61 | longitude/latitude (EPSG:4326) coordinates. This argument is mandatory if 62 | \code{region}, \code{pathrow} or \code{lonlat} are not defined. 63 | 64 | }} 65 | } 66 | \value{ 67 | a \code{data.frame} with the name of the images and their metadata. 68 | } 69 | \description{ 70 | \code{lsSearch} searches Landsat 7-8 images in the EarthExplorer API concerning 71 | a particular location and date interval. The function returns a 72 | \code{data.frame} with the names of the images and their metadata. 73 | } 74 | \examples{ 75 | \dontrun{ 76 | # search by path and row numbers of a tile 77 | getRGISToolsOpt("EE.DataSets") 78 | sres <- lsSearch(product = "LANDSAT_8_C1", 79 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 80 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 81 | username = "username", 82 | password = "password", 83 | region = ex.navarre, 84 | pathrow = list(c(200,31),c(200,30))) 85 | 86 | sres <- lsSearch(product = "LANDSAT_8_C1", 87 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 88 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 89 | username = "username", 90 | password = "password", 91 | lonlat = c(-1.64323,42.81687)) 92 | 93 | 94 | # search by extent (long/lat coordinates) 95 | # load a spatial polygon object of Navarre 96 | data(ex.navarre) 97 | sres <- lsSearch(product = "LANDSAT_8_C1", 98 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 99 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 100 | username = "username", 101 | password = "password", 102 | extent = ex.navarre) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /man/lsUpdateEEDataSets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lsUpdateEEDataSets.R 3 | \name{lsUpdateEEDataSets} 4 | \alias{lsUpdateEEDataSets} 5 | \title{Update EarthExplorer dataset names} 6 | \usage{ 7 | lsUpdateEEDataSets(username, password, logout = TRUE, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{username}{USGS's `EarthExplorer' username.} 11 | 12 | \item{password}{USGS's `EarthExplorer' password.} 13 | 14 | \item{logout}{logical argument. If \code{TRUE}, logges out from EarthExplorer 15 | API} 16 | 17 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 18 | running steps and warnings.} 19 | } 20 | \value{ 21 | the dataset names in EarthExplorer API 22 | } 23 | \description{ 24 | The `EE.DataSets' option of 'RGISTools' contains all the dataset names 25 | supported by EarthExplorer API. If these names changes, \code{\link{lsUpdateEEDataSets}} 26 | updates these data. 27 | } 28 | \examples{ 29 | \dontrun{ 30 | setRGISToolsOpt("EE.DataSets",NULL) 31 | getRGISToolsOpt("EE.DataSets") 32 | datasetNames<-lsUpdateEEDataSets(username = "username", 33 | password = "password") 34 | 35 | getRGISToolsOpt("EE.DataSets") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/modCloudMask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modCloudMask.R 3 | \name{modCloudMask} 4 | \alias{modCloudMask} 5 | \title{Create cloud masks for MODIS images} 6 | \usage{ 7 | modCloudMask(src, AppRoot, out.name, overwrite = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{src}{the path to the folder with the MODIS with \code{state_1km} images.} 11 | 12 | \item{AppRoot}{the directory where cloud masks are saved.} 13 | 14 | \item{out.name}{the name of the folder that stores the outputs. 15 | If the arguemnt is not defined the folder will be named as "CloudMask".} 16 | 17 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 18 | images with the same name.} 19 | 20 | \item{...}{arguments for nested functions. 21 | \itemize{ 22 | \item \code{dates} a vector of dates being considered 23 | for creating cloud masks. This argument is optional. 24 | }} 25 | } 26 | \value{ 27 | this function does not return anything. It saves the cloud masks (CLD) 28 | as GTiff files in the \code{AppRoot} directory. 29 | } 30 | \description{ 31 | \code{modCloudMask} creates cloud masks derived from the State Quality 32 | Assurance (State QA) band. 33 | } 34 | \details{ 35 | This function, interprets the State Quality Assurance (State QA) band to 36 | create cloud masks. The \code{NA} and \code{1} values of the mask represent 37 | cloudy and clear-sky pixels pixels respectively. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | # load a spatial polygon object of Navarre 42 | data(ex.navarre) 43 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 44 | print(wdir) 45 | 46 | # search and download images from MODIS between 47 | # 01-01-2018 and 03-01-2018 for the region of Navarre 48 | modDownSearch(product = "MOD09GA", 49 | startDate = as.Date("01-01-2017", "\%d-\%m-\%Y"), 50 | endDate = as.Date("03-01-2017", "\%d-\%m-\%Y"), 51 | username = "username", 52 | password = "password", 53 | AppRoot = wdir, 54 | extract.tif = TRUE, 55 | collection = 6, 56 | extent = ex.navarre) 57 | 58 | # assign src1 as the output folder for modMosaic 59 | wdir.mod <- file.path(wdir, "Modis") 60 | wdir.mod.tiles <- file.path(wdir.mod, "MOD09GA") 61 | wdir.mod.tif <- file.path(wdir.mod.tiles, "tif") 62 | # mosaic the MODIS images 63 | modMosaic(wdir.mod.tif, # the input folder 64 | AppRoot = wdir.mod.tiles, # the output folder 65 | out.name = "Navarre", # creates Navarre folder in AppRoot 66 | gutils = TRUE, 67 | extent = ex.navarre) 68 | 69 | 70 | wdir.mod.navarre <- file.path(wdir.mod.tiles, "Navarre") 71 | # generate the cloud masks 72 | modCloudMask(src = wdir.mod.navarre, 73 | AppRoot = wdir.mod.tiles, 74 | overwrite = TRUE) 75 | 76 | files.mod.cld <- file.path(wdir.mod.tiles,"CloudMask") 77 | img.mod.cld <- stack(list.files(files.mod.cld, full.names=TRUE, pattern="CLD")) 78 | 79 | # select b01 80 | img.mod.navarre <- stack(list.files(wdir.mod.navarre, 81 | full.names=TRUE, 82 | recursive = TRUE, 83 | pattern="b01_1")) 84 | 85 | # project to 500m 86 | img.mod.cld.500 <- projectRaster(img.mod.cld,img.mod.navarre) 87 | 88 | # plot the cloud free b01 layer 89 | spplot(img.mod.navarre*img.mod.cld.500) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /man/modDownload.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modDownload.R 3 | \name{modDownload} 4 | \alias{modDownload} 5 | \title{Download MODIS images from a search list} 6 | \usage{ 7 | modDownload( 8 | searchres, 9 | AppRoot, 10 | username = NULL, 11 | password = NULL, 12 | nattempts = 5, 13 | verbose = FALSE, 14 | extract.tif = FALSE, 15 | overwrite = FALSE, 16 | raw.rm = FALSE, 17 | ... 18 | ) 19 | } 20 | \arguments{ 21 | \item{searchres}{the output from the \code{\link{modSearch}} function.} 22 | 23 | \item{AppRoot}{the directory where the images will be saved.} 24 | 25 | \item{username}{NASA’s `EarthData' username.} 26 | 27 | \item{password}{NASA’s `EarthData' password.} 28 | 29 | \item{nattempts}{the number of attempts to download an image in case it 30 | becomes corrupted.} 31 | 32 | \item{verbose}{logical argument. If \code{TRUE}, the function prints running stages and warnings.} 33 | 34 | \item{extract.tif}{logical argument. If \code{TRUE}, extracts all the layers 35 | from hdf files and saves them as GTiff.} 36 | 37 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 38 | images with the same name.} 39 | 40 | \item{raw.rm}{logical argument. If \code{TRUE}, removes the raw images.} 41 | 42 | \item{...}{argument for nested functions: 43 | \itemize{ 44 | \item \code{dates} a vector with the capturing dates being considered 45 | for downloading. 46 | \item \code{bFilter} a vector with the bands to be extracted when \code{extract.tif=TRUE}. If not 47 | supplied, all bands are extracted. 48 | }} 49 | } 50 | \value{ 51 | this function does not return anything. It saves the imagery as 52 | `hdf’ (and GTiff files) in a folder called `raw’ (`tif’) in the 53 | \code{AppRoot} directory. 54 | } 55 | \description{ 56 | \code{modDownload} downloads the images from a list of uniform resource 57 | locators (URLs) generated by the \code{\link{modSearch}} function from NASA’s 58 | `EartData' plataform. The images are saved as GTiff files in the 59 | \code{AppRoot} directory. 60 | } 61 | \details{ 62 | \code{modDownload} is able to download MODIS Terra and Aqua products. 63 | These products are published in the 64 | \href{https://earthdata.nasa.gov}{`EarthData' Platform}. 65 | The platform is supported by the Earth Observing System Data and Information 66 | System (EODIS) and managed NASA’s Earth Science Data Systems (ESDS). 67 | \code{modDownload} requires credentianls from an `EarthData' account to 68 | access the NASA’s web data service, which can be obtained 69 | \href{https://urs.earthdata.nasa.gov/users/new}{here}. 70 | 71 | When \code{extract.tif = TRUE}, the function decompresses the imagery. If 72 | only a subset of bands is required, band names can be provided through the 73 | \code{bFilter} argument. The band names are specified by “B” and the two-digit 74 | band number (e.g., “B01”). Image decompression duplicates the information due 75 | to the presence of both, compressed and decompressed images. Set 76 | \code{raw.rm = TRUE} to remove former ones. 77 | } 78 | \examples{ 79 | \dontrun{ 80 | # load a spatial polygon object of Navarre 81 | data(ex.navarre) 82 | sres <- modSearch(product = "MYD13A2", 83 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 84 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 85 | collection = 6, 86 | extent = ex.navarre) 87 | head(sres) 88 | # download the first image in sres 89 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 90 | print(wdir) 91 | wdir.mod <- file.path(wdir,"Modis","MYD13A2") 92 | wdir.mod.hdf <- file.path(wdir.mod,"hdf") 93 | modDownload(mList[1], 94 | username = "username", 95 | password = "password", 96 | AppRoot = wdir.mod.hdf) 97 | # download all images in mList 98 | modDownload(sres, 99 | username = "username", 100 | password = "password", 101 | AppRoot = wdir.mod.hdf) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /man/modExtractHDF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modExtractHDF.R 3 | \name{modExtractHDF} 4 | \alias{modExtractHDF} 5 | \title{Convert an HDF file into a set of GTiff files} 6 | \usage{ 7 | modExtractHDF( 8 | filesHDF, 9 | AppRoot, 10 | overwrite = FALSE, 11 | bFilter = NULL, 12 | rm.band = NULL, 13 | region = NULL, 14 | verbose = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{filesHDF}{the full path where the HDF files are located.} 20 | 21 | \item{AppRoot}{the directory where the extracted images are saved.} 22 | 23 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 24 | images with the same name.} 25 | 26 | \item{bFilter}{a vector containing the names of the bands to extract.} 27 | 28 | \item{rm.band}{a vector containing the names of the bands excluded from the 29 | extraction.} 30 | 31 | \item{region}{a \code{Spatial*}, projected \code{raster*}, or \code{sf*} class object 32 | defining the area of interest for image masking.} 33 | 34 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 35 | running steps and warnings.} 36 | 37 | \item{...}{arguments for nested functions. 38 | \itemize{ 39 | \item \code{dates} a vector with the capturing dates being considered 40 | for downloading. 41 | }} 42 | } 43 | \description{ 44 | \code{modExtractHDF} converts the original format of MODIS images (hierarchical 45 | data format or HDF) into GTiffs (one file for each layer). 46 | } 47 | \details{ 48 | HDF files cannot be directly loaded into `R', so they must be converted into 49 | GTiffs. To acomplish this task, the function \code{modExtractHDF} 50 | borrows the \code{gdalwarp} and \code{gdal_translate} functions from the 51 | `\code{gdalUtils}' package. Further details about these functions can be found 52 | in the corresponding package manual. `GDAL' and `\code{gdalUtils}' must be 53 | properly installed to use \code{modExtractHDF}. GTiffs can be loaded in `R' 54 | using the `\code{raster}' package. 55 | } 56 | \examples{ 57 | \dontrun{ 58 | # load a spatial polygon object of Navarre 59 | data(ex.navarre) 60 | 61 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 62 | print(wdir) 63 | wdir.mod <- file.path(wdir, "Modis","MOD11A1") 64 | sres <- modSearch(product = "MOD11A1", 65 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 66 | endDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 67 | collection = 6, 68 | extent = ex.navarre) 69 | 70 | # download the images of the list 71 | wdir.mod <- file.path(wdir, "Modis", "MOD11A1") 72 | modDownload(searchres = sres, 73 | username = "username", 74 | password = "password", 75 | AppRoot = wdir.mod) 76 | 77 | wdir.mod.tif<-file.path(wdir.mod,"tif") 78 | wdir.mod.hdf <- file.path(wdir.mod, "hdf") 79 | 80 | # extract the first image 81 | files.mod.hdf <- list.files(wdir.mod.hdf, 82 | full.names = TRUE, 83 | pattern = "\\\\.hdf$") 84 | files.mod.hdf.1 <- files.mod.hdf[1] 85 | modExtractHDF(filesHDF = files.mod.hdf.1, 86 | AppRoot = wdir.mod.tif) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /man/modFolderToVar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modFolderToVar.R 3 | \name{modFolderToVar} 4 | \alias{modFolderToVar} 5 | \title{Compute a remote sensing index from a time series of MODIS multispectral 6 | images} 7 | \usage{ 8 | modFolderToVar( 9 | src, 10 | AppRoot, 11 | fun, 12 | getStack = FALSE, 13 | overwrite = FALSE, 14 | verbose = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{src}{path to the folder with the MODIS multispectral images.} 20 | 21 | \item{AppRoot}{the directory of the outcoming time series.} 22 | 23 | \item{fun}{a \code{function} that computes the remote sensing index.} 24 | 25 | \item{getStack}{logical argument. If \code{TRUE}, returns the time series of 26 | images as a \code{RasterStack}, otherwise the images are saved in the Hard 27 | Drive Device (HDD).} 28 | 29 | \item{overwrite}{logical argument. If \code{TRUE}, it overwrites the existing 30 | images with the same name.} 31 | 32 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 33 | running steps and warnings.} 34 | 35 | \item{...}{arguments for nested functions. 36 | \itemize{ 37 | \item \code{dates} a vector with the capturing dates being considered 38 | for mosaicking. If not supplied, all dates are mosaicked. 39 | }} 40 | } 41 | \value{ 42 | this function does not return anything, unless \code{getStack = TRUE} 43 | which then returns a \code{RasterStack} with the time series of with the 44 | index. 45 | } 46 | \description{ 47 | \code{modFolderToVar} computes a remote sensing index from the spectral bands 48 | of a time series of MODIS images. The images are specified by the path to 49 | the folder that stores the imagery (resulting from the \code{\link{modMosaic}} 50 | function). The function returns a \code{RasterStack} with a time series of 51 | images of the remote sensing index. 52 | } 53 | \details{ 54 | The function requires the definition of the \code{src} and \code{fun} 55 | arguments. The \code{src} is usually the path resulting from 56 | \code{\link{modMosaic}}. The \code{fun} argument can be any function from 57 | this package beginning with “var” (\code{\link{varNDVI}}, \code{\link{varEVI}}, 58 | etc.). Custom functions can also be implemented. If \code{fun = varRGB}, then 59 | the argument \code{getStack} must be equal to \code{FALSE} and the 60 | red-gree-blue (RGB) images must be imported afterwards. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | # load a spatial polygon object of Navarre 65 | data(ex.navarre) 66 | # main output directory 67 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 68 | print(wdir) 69 | # download MOD09 images 70 | modDownSearch(product = "MOD09GA", 71 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 72 | endDate = as.Date("03-01-2018", "\%d-\%m-\%Y"), 73 | username = "username", 74 | password = "password", 75 | AppRoot = wdir, # output folder for tif images 76 | extract.tif = TRUE, 77 | collection = 6, 78 | extent = ex.navarre) 79 | # assign wdir.mod as the output folder from modMosaic 80 | wdir.mod <- file.path(wdir, "Modis", "MOD09GA") # output directory 81 | wdir.mod.tif <- file.path(wdir.mod, "tif") # input directory 82 | # mosaic the MODIS images 83 | modMosaic(wdir.mod.tif, 84 | AppRoot = wdir.mod, 85 | out.name = "Navarre") 86 | # path to the folder with the mosaicked images 87 | wdir.mod.navarre <- file.path(wdir.mod, "Navarre") 88 | # generate NDVI images of Navarre 89 | wdir.mod.var <- file.path(wdir.mod, "Variables") 90 | dir.create(wdir.mod.var) 91 | modFolderToVar(src = wdir.mod.navarre, 92 | fun = varEVI, 93 | scfun = getRGISToolsOpt("MOD09SCL"), 94 | AppRoot = wdir.mod.var, 95 | overwrite = TRUE) 96 | # import mosaicked images (.tif) to the environment in `R' 97 | files.mod.evi <- list.files(file.path(wdir.mod.var,"EVI"), 98 | pattern = "\\\\.tif$", 99 | full.names = TRUE, 100 | recursive = TRUE) 101 | 102 | img.mod.evi <- lapply(files.mod.evi,raster) 103 | spplot(img.mod.evi[[1]],at=seq(-1,2.5)) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /man/modGetDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genMissionGetDates.R 3 | \name{modGetDates} 4 | \alias{modGetDates} 5 | \title{Return the capturing dates of MODIS images} 6 | \usage{ 7 | modGetDates(str, ...) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of MODIS 11 | images from which the capturing date is retrieved.} 12 | 13 | \item{...}{arguments for nested functions: 14 | \itemize{ 15 | \item \code{format} the format of the date being returned. 16 | }} 17 | } 18 | \value{ 19 | a \code{Date} class object with the date of the MODIS image or \code{character} class, 20 | if \code{format} argument is used. 21 | } 22 | \description{ 23 | \code{modGetDates} reads the official name of MODIS images and returns its 24 | capturing date, as \code{Date} class object. 25 | } 26 | \details{ 27 | The function works with file names (or their paths) regardless of their 28 | extension. The function accepts more than on file path, which can be passed 29 | as a \code{list} of \code{characters}. Dates are returned as 30 | `\code{YYYY-mm-dd}' by default. If another format is required, it can be 31 | modified through the argument \code{format}. 32 | } 33 | \examples{ 34 | # getting the capturing date from the name of a MODIS image 35 | file.mod <- 'MYD13A2.A2016361.h17v04.006.2017285133407.hdf' 36 | modGetDates(file.mod) 37 | 38 | # a list of the full file paths of MODIS images, mixing .hdf and .tif files 39 | file.mod<-list('MYD13A2.A2013297.h17v04.006.2015269230726.hdf', 40 | 'MYD13A2.A2013313.h17v04.006.2015271071143.tif') 41 | modGetDates(file.mod, format = "\%Y\%j") 42 | } 43 | -------------------------------------------------------------------------------- /man/modGetPathRow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modGetPathRow.R 3 | \name{modGetPathRow} 4 | \alias{modGetPathRow} 5 | \title{Return the pathrow of a tile of MODIS images} 6 | \usage{ 7 | modGetPathRow(str) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the MODIS images from 11 | which the tile's path and row numbers are retrieved.} 12 | } 13 | \value{ 14 | a string with the path and row in "\code{hXXvYY}" format. 15 | } 16 | \description{ 17 | \code{modGetPathRow} reads the official name of a MODIS image and returns the 18 | tile's path and row number, in 'hXXvYY' format (MODIS naming convention). 19 | } 20 | \examples{ 21 | # getting the path and row number of the tile of a Landsat-8 image 22 | files.mod <- "MYD09GA.A2003136.h17v04.005.2008324054225" 23 | pr.mod <- modGetPathRow(files.mod) 24 | print(pr.mod) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /man/modMosaic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modMosaic.R 3 | \name{modMosaic} 4 | \alias{modMosaic} 5 | \title{Mosaic a set of MODIS images} 6 | \usage{ 7 | modMosaic( 8 | src, 9 | AppRoot, 10 | region = NULL, 11 | out.name = "outfile", 12 | verbose = FALSE, 13 | gutils = TRUE, 14 | overwrite = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{src}{the path of the folder with the MODIS images in GTiff format.} 20 | 21 | \item{AppRoot}{the directory where the mosaicked images are saved.} 22 | 23 | \item{region}{a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 24 | defining the area of interest.} 25 | 26 | \item{out.name}{the name of the folder that stores the outputs. By default, 27 | “outfile” is assigned.} 28 | 29 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 30 | running steps and warnings.} 31 | 32 | \item{gutils}{logical argument. If \code{TRUE}, the function uses `GDAL' 33 | utilities for mosaicking.} 34 | 35 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 36 | images with the same name.} 37 | 38 | \item{...}{arguments for nested functions: 39 | \itemize{ 40 | \item \code{pathrow} a \code{vector} of \code{character} with the 41 | path and row numbers of the tiles concerning the region of interest in 42 | 'hXXvYY' format. This argument is mandatory if \code{region} is not provided. 43 | \item \code{bFilter} a vector with the bands to be mosaicked. If not 44 | supplied, all bands are mosaicked. 45 | \item \code{dates} a vector with the capturing dates being considered 46 | for mosaicking. If not supplied, all dates are mosaicked. 47 | }} 48 | } 49 | \description{ 50 | \code{modMosaic} merges the MODIS imagery that covers a 51 | region of interest on the same dates. 52 | } 53 | \details{ 54 | The function mosaics the imagery in the \code{src} folder. The folder can 55 | hold GTiff images from several tiles, dates and bands. When only a subset 56 | dates has to be mosaicked, the dates should be provided through the argument 57 | \code{dates}. The dates must be provided as a \code{Date} class objects. For 58 | further details about the \code{bFilter} argument, go to the 59 | \code{\link{modDownload}} function. Once mosaicked, the images can be cropped 60 | to fit the \code{region} (optional). The \code{region} can be defined in any 61 | coordinate reference system, since \code{modMosaic} automatically reproject 62 | the extent to match the projection of the image. The outputs will be placed 63 | in the \code{AppRoot} directory, under the folder named as \code{out.name}. 64 | If no name is provided, the folder is named “outfile”. 65 | } 66 | \examples{ 67 | \dontrun{ 68 | # load a spatial polygon object of Navarre 69 | data(ex.navarre) 70 | # main output directory 71 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 72 | print(wdir) 73 | # download MODIS images 74 | modDownSearch(product = "MOD09GA", 75 | startDate = as.Date("01-01-2018", "\%d-\%m-\%Y"), 76 | endDate = as.Date("03-01-2018", "\%d-\%m-\%Y"), 77 | username = "username", 78 | password = "password", 79 | AppRoot = wdir, 80 | extract.tif = TRUE, 81 | collection = 6, 82 | extent = ex.navarre) 83 | # folder with the MODIS images extracted 84 | wdir.mod <- file.path(wdir, "Modis", "MOD09GA") 85 | wdir.mod.tif <- file.path(wdir.mod, "tif") 86 | # mosaic the MODIS images 87 | modMosaic(wdir.mod.tif, 88 | AppRoot = wdir.mod, 89 | out.name = "Navarre", 90 | gutils = TRUE, 91 | overwrite = TRUE, 92 | region = ex.navarre) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /man/modPreview.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modPreview.R 3 | \name{modPreview} 4 | \alias{modPreview} 5 | \title{Preview MODIS satellite images} 6 | \usage{ 7 | modPreview( 8 | searchres, 9 | n, 10 | dates, 11 | lpos = c(3, 2, 1), 12 | add.Layer = FALSE, 13 | verbose = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{searchres}{a vector with the results from \code{\link{modSearch}}.} 19 | 20 | \item{n}{a \code{numeric} argument identifying the location of the image in 21 | \code{searchres}.} 22 | 23 | \item{dates}{a vector with the dates being considered 24 | for previewing. This argument is mandatory if 25 | \code{n} is not defined.} 26 | 27 | \item{lpos}{vector argument. Defines the position of the red-green-blue 28 | layers to enable false color visualization.} 29 | 30 | \item{add.Layer}{logical argument. If \code{TRUE}, the function plots the 31 | image on an existing map. Allows combinations of images on a map using 32 | \code{\link{lsPreview}} and \code{\link{senPreview}} functions.} 33 | 34 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 35 | running steps and warnings.} 36 | 37 | \item{...}{arguments for nested functions: 38 | \itemize{ 39 | \item arguments allowed by the \code{viewRGB} function from \code{mapview} 40 | packages are valid arguments. 41 | }} 42 | } 43 | \value{ 44 | this function does not return anything. It displays a preview of one 45 | of the search results. 46 | } 47 | \description{ 48 | \code{modPreview} shows a preview of the \code{n}-th image from a set of 49 | search results on an interactive map. 50 | } 51 | \details{ 52 | The function shows a preview of the \code{n}-th output image from a search 53 | in the MODIS archives (\code{\link{modSearch}}, with 54 | \code{resType = "browseurl"}). The preview is downloaded from the 55 | \href{https://earthdata.nasa.gov}{`EarthData' Platform}. 56 | Please, be aware that only some images may have a preview. 57 | } 58 | \examples{ 59 | \dontrun{ 60 | # load a spatial polygon object of Navarre 61 | data(ex.navarre) 62 | # retrieve jpg images covering Navarre region between 2011 and 2013 63 | sres <- modSearch(product = "MOD09GA", 64 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 65 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 66 | collection = 6, 67 | extent = ex.navarre) 68 | 69 | modPreview(sres,n=1) 70 | modPreview(sres,2,add.Layer=T) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /man/modSearch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/modSearch.R 3 | \name{modSearch} 4 | \alias{modSearch} 5 | \title{Search MODIS images} 6 | \usage{ 7 | modSearch(product, collection = 6, verbose = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{product}{the short name of the MODIS product.} 11 | 12 | \item{collection}{MODIS collection. By default, 6.} 13 | 14 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 15 | running steps and warnings.} 16 | 17 | \item{...}{arguments for nested functions: 18 | \itemize{ 19 | \item \code{dates} a vector with the capturing dates being searched. This 20 | argument is mandatory if \code{startDate} and \code{endDate} are not defined. 21 | \item \code{startDate} a \code{Date} class object with the starting date 22 | of the study period. This argument is mandatory if \code{dates} is not defined. 23 | \item \code{endDate} a \code{Date} class object with the ending date of the 24 | study period. This argument is mandatory if 25 | \code{dates} is not defined. 26 | \item \code{region} a \code{Spatial*}, projected \code{raster*}, or \code{sf} 27 | class object defining the area of interest. This argument is mandatory if 28 | \code{extent} or \code{lonlat} are not defined. 29 | \item \code{lonlat} a vector with the longitude/latitude 30 | coordinates of the point of interest. This argument is mandatory if 31 | \code{region} or \code{extent} are not defined. 32 | \item \code{extent} an \code{extent}, \code{Raster*}, or 33 | \code{Spatial*} object representing the region of interest with 34 | longitude/latitude coordinates. This argument is mandatory if 35 | \code{region} or \code{lonlat} are not defined. 36 | }} 37 | } 38 | \value{ 39 | a \code{vector} with the url for image downloading. 40 | } 41 | \description{ 42 | \code{modSearch} searches MODIS images in the 43 | \href{https://lpdaacsvc.cr.usgs.gov/services/inventory}{NASA Common Metadata Repository} 44 | (CMR) concerning a particular location and date interval. The function returns a 45 | \code{character} vector with the names of the images and their uniform resource 46 | locators (URLs) 47 | } 48 | \details{ 49 | \code{modSearch} uses the 50 | \href{https://lpdaacsvc.cr.usgs.gov/services/inventory}{NASA Common Metadata 51 | Repository} (CMR) powered API. The catalogue of MODIS products can be found 52 | \href{https://modis.gsfc.nasa.gov/data/dataprod/}{here}. 53 | The catalogue shows the product short names and provides detailed information 54 | about the product. By the time `RGISTools' is released, NASA carries out the 55 | maintenance of its website on Wednesdays, which may cause an error when 56 | connecting to their server. You can get your `EarthData' credentials 57 | \href{https://urs.earthdata.nasa.gov/users/new}{here}. 58 | 59 | The function can be used to retrieve the web address of the preview 60 | (\code{resType = "browseurl"}) or the actual image (\code{resType = "url"}). 61 | By default, the URL points towards the actual image. 62 | } 63 | \examples{ 64 | \dontrun{ 65 | # load a spatial polygon object of Navarre with longitude/latitude coordinates 66 | data(ex.navarre) 67 | # searching MODIS MYD13A2 images between 2011 and 2013 by longitude/latitude 68 | # using a polygon class variable 69 | sres <- modSearch(product = "MYD13A2", 70 | startDate = as.Date("01-01-2011", "\%d-\%m-\%Y"), 71 | endDate = as.Date("31-12-2013", "\%d-\%m-\%Y"), 72 | collection = 6, 73 | extent = ex.navarre) 74 | # region of interest: defined based on longitude/latitude extent 75 | # searching MODIS MYD13A2 images in 2010 by longitude/latitude 76 | # using a extent class variable defined by the user 77 | aoi = extent(c(-2.49, -0.72, 41.91, 43.31)) 78 | sres <- modSearch(product = "MYD13A2", 79 | startDate = as.Date("01-01-2010", "\%d-\%m-\%Y"), 80 | endDate = as.Date("31-12-2010", "\%d-\%m-\%Y"), 81 | collection = 6, 82 | extent = aoi) 83 | head(sres) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /man/senCloudMask.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senCloudMask.R 3 | \name{senCloudMask} 4 | \alias{senCloudMask} 5 | \title{Create cloud masks for Sentinel-2 images} 6 | \usage{ 7 | senCloudMask( 8 | src, 9 | AppRoot, 10 | out.name, 11 | resbands, 12 | sensitivity = 50, 13 | overwrite = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{src}{the path to the folder with the "\code{S2MSI2A}" images.} 19 | 20 | \item{AppRoot}{the directory where the cloud masks are saved.} 21 | 22 | \item{out.name}{the name of the folder that stores the outputs. 23 | If the arguemnt is not defined the folder will be named as "CloudMask".} 24 | 25 | \item{resbands}{a \code{character} vector argument. Defines the band resolution 26 | used to create the cloud mask. Ex "20m" or "60m".} 27 | 28 | \item{sensitivity}{a \code{numeric} argument. Defines the sensitivity of the 29 | cloud detection method.} 30 | 31 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 32 | images with the same name.} 33 | 34 | \item{...}{arguments for nested functions. 35 | \itemize{ 36 | \item \code{dates} a vector with the capturing dates being considered 37 | for mosaicking. If not supplied, all dates are mosaicked. 38 | }} 39 | } 40 | \value{ 41 | this function does not return anything. It saves the cloud masks (CLD) 42 | as GTiff files in the \code{AppRoot} directory. 43 | } 44 | \description{ 45 | \code{senCloudMask} creates cloud masks derived from the cloud probability 46 | band (\code{CLDPRB}) band from the "\code{S2MSI2A}" product. 47 | } 48 | \details{ 49 | The valid threshold range for \code{sensitivity} is 0-100. By default, 50 | the argument is set to 50. 51 | } 52 | \examples{ 53 | \dontrun{ 54 | # load a spatial polygon object of Navarre 55 | data(ex.navarre) 56 | # Download S2MSI1C products sensed by Sentinel-2 57 | # between the julian days 210 and 218, 2018 58 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 59 | print(wdir) 60 | senDownSearch(startDate = as.Date("2018210", "\%Y\%j"), 61 | endDate = as.Date("2018218", "\%Y\%j"), 62 | platform = "Sentinel-2", 63 | extent = ex.navarre, 64 | product = "S2MSI2A", 65 | pathrow = c("R094"), 66 | username = "username", 67 | password = "password", 68 | AppRoot = wdir) 69 | # define the paths to the Sentinle-2 images and the 70 | # folder with the unzipped images 71 | wdir.sen <- file.path(wdir, "Sentinel-2") 72 | wdir.sen.unzip <- file.path(wdir.sen, "unzip") 73 | # mosaic the Sentinel-2 images 74 | senMosaic(wdir.sen.unzip, 75 | AppRoot = wdir.sen, 76 | gutils = TRUE, 77 | out.name = "Navarre") 78 | 79 | # calculate the cloud mask 80 | wdir.sen.navarre <- file.path(wdir.sen, "Navarre") 81 | senCloudMask(src = wdir.sen.navarre, 82 | resbands = "60m", 83 | overwrite = TRUE, 84 | sensitivity = 98, 85 | AppRoot = wdir.sen) 86 | 87 | # define the path for the Sentinel-2 cloud mask 88 | wdir.sen.cloud <- file.path(wdir.sen, "CloudMask") 89 | 90 | # select B02 images of 60 meters 91 | tiles.sen.navarre <- list.files(wdir.sen.navarre, 92 | full.names = TRUE, 93 | recursive = TRUE, 94 | pattern = "\\\\.tif$") 95 | tiles.sen.navarre.b2 <- tiles.sen.navarre[grepl("B02",tiles.sen.navarre)] 96 | tiles.sen.navarre.b2 <- tiles.sen.navarre.b2[grepl("60m",tiles.sen.navarre.b2)] 97 | 98 | # generate a 60-meter resolution cloud mask 99 | tiles.sen.cloud <- list.files(wdir.sen.cloud, 100 | full.names = TRUE, 101 | pattern = "\\\\.tif$") 102 | tiles.sen.cloud.60 <- tiles.sen.cloud[grepl("60m",tiles.sen.cloud)] 103 | 104 | # remove the cloud mask from b02 tiles 105 | img.sen.navarre.b2 <- stack(tiles.sen.navarre.b2) 106 | img.sen.cloud.60 <- stack(tiles.sen.cloud.60) 107 | img.sen.navarre.b2.cloud.free <- img.sen.navarre.b2*img.sen.cloud.60 108 | # plot b2 cloud free layers 109 | spplot(img.sen.navarre.b2.cloud.free) 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /man/senDownSearch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senDownSearch.R 3 | \name{senDownSearch} 4 | \alias{senDownSearch} 5 | \title{Search and download Sentinel images} 6 | \usage{ 7 | senDownSearch(username, password, AppRoot, verbose = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{username}{ESA’s `SciHub' username.} 11 | 12 | \item{password}{ESA’s `SciHub' password.} 13 | 14 | \item{AppRoot}{the directory where the images are saved.} 15 | 16 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 17 | running steps and warnings.} 18 | 19 | \item{...}{arguments for nested functions: 20 | \itemize{ 21 | \item \code{product} the type of Sentinel product. Ex. "S2MSI1C", 22 | "S2MSI2A", "S2MSI2Ap", ... 23 | \item \code{startDate} a \code{Date} class object with the starting date of the 24 | study period. This argument is mandatory if 25 | \code{dates} is not defined. 26 | \item \code{endDate} a \code{Date} class object with the ending date of the 27 | study period. This argument is mandatory if 28 | \code{dates} is not defined. 29 | \item \code{dates} a vector with the capturing dates being considered 30 | for searching. This argument is mandatory if 31 | \code{startDate} and \code{endDate} are not defined. 32 | \item \code{region} a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 33 | defining the area of interest. 34 | \item \code{extent} an \code{extent}, \code{Raster*}, or \code{Spatial*} 35 | object representing the region of interest with longitude/latitude 36 | coordinates. This argument is mandatroy when \code{region} is not defined. 37 | \item \code{platform} the name of the Sentinel mission ("Sentinel-1", 38 | "Sentinel-2", ...). 39 | \item \code{nattempts} the number of attempts to download an image in case 40 | it becomes corrupted. 41 | \item \code{unzip} logical argument. If \code{TRUE}, unzips the images. 42 | \item \code{verbose} logical argument. If \code{TRUE}, the function prints 43 | the running steps and warnings. 44 | }} 45 | } 46 | \value{ 47 | this function does not return anything. It saves the imagery as 48 | `zip’ (and JP2 files) in a folder called `raw’ (`unzip’) in the 49 | \code{AppRoot} directory. 50 | } 51 | \description{ 52 | \code{senDownSearch} searches and downloads Sentinel images concerning a 53 | particular location and time interval from `SciHub's' repository. 54 | } 55 | \details{ 56 | \code{senDownSearch} is a wrapper function of \code{\link{senSearch}} and 57 | \code{\link{senDownload}} to search and download images in a single step. 58 | The function requires ESA’s `SciHub' credentials, which can be obtained 59 | \href{https://scihub.copernicus.eu/dhus/#/self-registration}{here}. 60 | } 61 | \examples{ 62 | \dontrun{ 63 | # load a spatial polygon object of Navarre 64 | data(ex.navarre) 65 | # Download S2MSI1C products sensed by Sentinel-2 66 | # between the julian dates 210 and 218, 2018 67 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 68 | print(wdir) 69 | senDownSearch(startDate = as.Date("2018210", "\%Y\%j"), 70 | endDate = as.Date("2018218", "\%Y\%j"), 71 | platform = "Sentinel-2", 72 | extent = ex.navarre, 73 | product = "S2MSI1C", 74 | pathrow = c("R094"), 75 | username = "username", 76 | password = "password", 77 | AppRoot = wdir) 78 | 79 | wdir.sen <- file.path(wdir, "Sentinel-2") 80 | wdir.sen.unzip <- file.path(wdir.sen, "unzip") 81 | 82 | files.sen.unzip <- list.files(wdir.sen.unzip, 83 | pattern = "\\\\TCI.jp2$", 84 | full.names = TRUE, 85 | recursive = TRUE) 86 | img.sen.rgb <- stack(files.sen.unzip[1]) 87 | plotRGB(img.sen.rgb) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /man/senGetDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genMissionGetDates.R 3 | \name{senGetDates} 4 | \alias{senGetDates} 5 | \title{Return the capturing dates of Sentinel-2 images} 6 | \usage{ 7 | senGetDates(str, ...) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the Sentinel 11 | images from which the capturing date is retrieved.} 12 | 13 | \item{...}{arguments for nested functions: 14 | \itemize{ 15 | \item \code{format} the format of the date being returned. 16 | }} 17 | } 18 | \value{ 19 | a \code{Date} class object with the date of the Sentinel image or \code{character} class, 20 | if the \code{format} argument is used. 21 | } 22 | \description{ 23 | \code{senGetDates} reads the official name of a Sentinel-2 image and returns 24 | the capturing date, as a \code{Date} class object. 25 | } 26 | \details{ 27 | The function works with file names (or their paths) regardless of their 28 | extension. The function accepts more than on file path, which can be passed 29 | as a vector of \code{character}s. Dates are returned as `\code{YYYY-mm-dd}' by 30 | default. If another format is required, it can be modified through the 31 | argument \code{format}. 32 | } 33 | \examples{ 34 | # getting the capturing date from the name of Sentinel-2 images 35 | file.sen <- c("S2A_MSIL1C_20170102T111442_N0204_R137_T30TWN_20170102T111441.SAFE", 36 | "S2A_OPER_PRD_MSIL1C_PDMC_20160308T090616_R094_V20160305T110109_20160305T110109") 37 | date.sen <- senGetDates(file.sen) 38 | print(date.sen) 39 | print(format(date.sen,"\%Y\%j")) 40 | senGetDates(file.sen, format = "\%Y\%j") 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/senGetOrbit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senGetPathRow.R 3 | \name{senGetOrbit} 4 | \alias{senGetOrbit} 5 | \title{Return the relative orbit of the Sentinel-2 satellite} 6 | \usage{ 7 | senGetOrbit(str) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the Sentinel images from 11 | which the orbits are retrieved.} 12 | } 13 | \value{ 14 | an string with the relative orbit of the image in "\code{NXXXX_RYYY}" 15 | or "\code{RYYY}" format, depending on the version of name convention. 16 | } 17 | \description{ 18 | \code{senGetOrbit} reads the official name of a Sentinel image and returns 19 | relative orbit, in "\code{NXXXX_RYYY}" or "\code{RYYY}" format (Sentinel 20 | namig convention). 21 | } 22 | \details{ 23 | Get information about the relative orbits 24 | \href{https://sentinel.esa.int/web/sentinel/missions/sentinel-2/satellite-description/orbit}{here}. 25 | } 26 | \examples{ 27 | #example of getting date from Sentinel2 image name 28 | files.sen <- c("S2A_MSIL1C_20170102T111442_N0204_R137_T30TWN_20170102T111441.SAFE", 29 | "S2A_OPER_PRD_MSIL1C_PDMC_20160308T090616_R094_V20160305T110109_20160305T110109") 30 | tile.sen <- senGetOrbit(files.sen) 31 | print(tile.sen) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/senGetTile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senGetPathRow.R 3 | \name{senGetTile} 4 | \alias{senGetTile} 5 | \title{Return the pathrow of a tile from Sentinel-2 images} 6 | \usage{ 7 | senGetTile(str) 8 | } 9 | \arguments{ 10 | \item{str}{the full path(s) or official name(s) of the Sentinel-2 images from 11 | which the tile's path and row numbers are retrieved.} 12 | } 13 | \value{ 14 | a string with the path and row in "\code{TTTSSS}" format. 15 | } 16 | \description{ 17 | \code{senGetTile} reads the official name of a Sentinel-2 image and returns 18 | the tile's path and row number, in "\code{TTTSSS}" format (Sentinel naming 19 | convention). 20 | } 21 | \details{ 22 | Find more details about the Sentinel tiling system 23 | \href{https://sentinel.esa.int/web/sentinel/missions/sentinel-2/news/-/asset_publisher/Ac0d/content/sentinel-2-level-1c-product-tiling-grid-released}{here}. 24 | } 25 | \examples{ 26 | # getting path and row numbers from a couple of Sentinel-2 images 27 | files.sen <- c("S2A_MSIL1C_20170102T111442_N0204_R137_T30TWN_20170102T111441.SAFE", 28 | "S2A_OPER_PRD_MSIL1C_PDMC_20160308T090616_R094_V20160305T110109_20160305T110109") 29 | pr.sen <- senGetTile(files.sen) 30 | print(pr.sen) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/senMosaic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senMosaic.R 3 | \name{senMosaic} 4 | \alias{senMosaic} 5 | \title{Mosaic a set of Sentinel-2 images} 6 | \usage{ 7 | senMosaic( 8 | src, 9 | AppRoot, 10 | region = NULL, 11 | out.name = "outfile", 12 | verbose = FALSE, 13 | gutils = TRUE, 14 | overwrite = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{src}{the path of the folder with the Sentinel images in GTiff format.} 20 | 21 | \item{AppRoot}{the directory to save the mosaicked images.} 22 | 23 | \item{region}{a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 24 | defining the area of interest.} 25 | 26 | \item{out.name}{the name of the folder that stores the outputs. By default, 27 | “outfile” is assigned.} 28 | 29 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 30 | running steps and warnings.} 31 | 32 | \item{gutils}{logical argument. If \code{TRUE}, the function uses `GDAL' 33 | utilities for mosaicking.} 34 | 35 | \item{overwrite}{logical argument. If \code{TRUE}, overwrites the existing 36 | images with the same name.} 37 | 38 | \item{...}{arguments for nested functions: 39 | \itemize{ 40 | \item \code{pathrow} a \code{list} of vectors with the path and row numbers 41 | of the tiles concerning the region of interest. This argument is mandatory 42 | if \code{region} is not defined. 43 | \item \code{bFilter} a vector with the bands to be mosaicked. If not 44 | supplied, all bands are mosaicked. 45 | \item \code{dates} a vector with the capturing dates being considered 46 | for mosaicking. If not supplied, all dates are mosaicked. 47 | }} 48 | } 49 | \value{ 50 | this function does not return anything. It saves the imagery in the 51 | \code{AppRoot} directory. 52 | } 53 | \description{ 54 | \code{senMosaic} merges the Sentinel-2 imagery that covers a region of interest 55 | on the same dates. 56 | } 57 | \details{ 58 | The function mosaics the imagery in the \code{src} folder. The folder can 59 | hold GTiff images from several tiles, dates and bands. When only a subset 60 | dates has to be mosaicked, the dates should be provided through the argument 61 | \code{dates}. The dates must be provided as a \code{Date} class object.For 62 | further details about the \code{bFilter} argument, go to the 63 | \code{\link{senDownload}} function. Once mosaicked, the images can be cropped 64 | to fit the \code{region} (optional). The \code{region} can be defined in any 65 | coordinate reference system, since \code{senMosaic} automatically reproject 66 | the extent to match the projection of the image. The outputs will be placed 67 | in the \code{AppRoot} directory, under the folder named as \code{out.name}. 68 | If no name is provided, the folder is named “outfile”. 69 | } 70 | \examples{ 71 | \dontrun{ 72 | # load a spatial polygon object of Navarre 73 | data(ex.navarre) 74 | # main output directory 75 | wdir <- file.path(tempdir(),"Path_for_downloading_folder") 76 | print(wdir) 77 | # download Sentinel-2 images 78 | senDownSearch(startDate = as.Date("2018210", "\%Y\%j"), 79 | endDate = as.Date("2018218", "\%Y\%j"), 80 | platform = "Sentinel-2", 81 | extent = ex.navarre, 82 | product = "S2MSI1C", 83 | pathrow = c("R094"), 84 | username = "username", 85 | password = "password", 86 | AppRoot = wdir) 87 | # folder with the unzipped images 88 | wdir.sen <- file.path(wdir, "Sentinel-2") 89 | wdir.sen.unzip <- file.path(wdir.sen, "unzip") 90 | # mosaic the Sentinel-2 images 91 | senMosaic(wdir.sen.unzip, 92 | AppRoot = wdir.sen, 93 | gutils = TRUE, 94 | out.name = "Navarre") 95 | 96 | wdir.sen <- file.path(wdir.sen,"Navarre") 97 | # load and plot a Sentinel-2 image 98 | files.sen <- list.files(wdir.sen, pattern = "\\\\.tif$", full.names = TRUE ,recursive = TRUE) 99 | # print Sentinel-2 bands 100 | getRGISToolsOpt("SEN2BANDS") 101 | file.sen.rgb <- stack(files.sen[grepl("TCI",files.sen)][1]) 102 | plotRGB(file.sen.rgb) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /man/senPreview.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senPreview.R 3 | \name{senPreview} 4 | \alias{senPreview} 5 | \title{Preview Sentinel-2 satellite images} 6 | \usage{ 7 | senPreview( 8 | searchres, 9 | username, 10 | password, 11 | n, 12 | dates, 13 | lpos = c(3, 2, 1), 14 | add.Layer = FALSE, 15 | verbose = FALSE, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{searchres}{a vector with the results from \code{\link{senSearch}}.} 21 | 22 | \item{username}{ESA’s `SciHub' username.} 23 | 24 | \item{password}{ESA’s `SciHub' password.} 25 | 26 | \item{n}{a \code{numeric} argument identifying the row of the image in 27 | \code{searchres}.} 28 | 29 | \item{dates}{a vector with the dates being considered 30 | for previewing. This argument is mandatory if 31 | \code{n} is not defined.} 32 | 33 | \item{lpos}{vector argument. Defines the position of the red-green-blue 34 | layers to enable false color visualization.} 35 | 36 | \item{add.Layer}{logical argument. If \code{TRUE}, the function plots the 37 | image on an existing map. Allows combinations of images on a map using 38 | \code{\link{lsPreview}} and \code{\link{modPreview}} functions.} 39 | 40 | \item{verbose}{logical argument. If \code{TRUE}, the function prints the 41 | running steps and warnings.} 42 | 43 | \item{...}{arguments for nested functions: 44 | \itemize{ 45 | \item arguments allowed by the \code{viewRGB} function from \code{mapview} 46 | packages are valid arguments 47 | }} 48 | } 49 | \value{ 50 | this function does not return anything. It displays a preview of one 51 | of the search results. 52 | } 53 | \description{ 54 | \code{senPreview} shows a preview of the \code{n}-th image from a set of 55 | search results on an interactive map. 56 | } 57 | \details{ 58 | The function shows a preview of the \code{n}-th output image from a search 59 | in Sentinel archives (\code{\link{modSearch}}). The preview is downloaded from 60 | `SciHub's' website. Please, be aware that only some images may have a preview. 61 | Credentials from an ESA’s `SciHub' account are needed, which can be obtained 62 | \href{https://scihub.copernicus.eu/dhus/#/self-registration}{here}. 63 | } 64 | \examples{ 65 | \dontrun{ 66 | # load a spatial polygon object of Navarre 67 | data(ex.navarre) 68 | # perform the search query 69 | sres <- senSearch(startDate = as.Date("2018210","\%Y\%j"), 70 | endDate = as.Date("2018218","\%Y\%j"), 71 | platform = "Sentinel-2", 72 | extent = ex.navarre, 73 | product = "S2MSI1C", 74 | username = "username", 75 | password = "password") 76 | # preview some images 77 | senPreview(sres, username = "username", password = "password",n=1) 78 | senPreview(sres, username = "username", password = "password",n=3, add.Layer =TRUE) 79 | 80 | # show the dates in julian days 81 | senGetDates(names(sres),format="\%Y\%j") 82 | 83 | senPreview(sres, 84 | username = "username", 85 | password = "password", 86 | dates = senGetDates(names(sres[3]))) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /man/senSearch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/senSearch.R 3 | \name{senSearch} 4 | \alias{senSearch} 5 | \title{Search Sentinel images} 6 | \usage{ 7 | senSearch(username, password, ...) 8 | } 9 | \arguments{ 10 | \item{username}{ESA’s `SciHub' username.} 11 | 12 | \item{password}{ESA’s `SciHub' password.} 13 | 14 | \item{...}{arguments for nested functions: 15 | \itemize{ 16 | \item \code{product} the type of Sentinel product. Ex. "S2MSI1C", 17 | "S2MSI2A", "S2MSI2Ap", ... 18 | \item \code{dates} a vector with the capturing dates being searched. This 19 | argument is mandatory if \code{startDate} and \code{endDate} are not defined. 20 | \item \code{startDate} a \code{Date} class object with the starting date of the 21 | study period. This argument is mandatory if 22 | \code{dates} is not defined. 23 | \item \code{endDate} a \code{Date} class object with the ending date of the 24 | study period. This argument is mandatory if 25 | \code{dates} is not defined. 26 | \item \code{region} a \code{Spatial*}, projected \code{raster*}, or 27 | \code{sf} class object defining the area of interest. This argument is 28 | mandatory if \code{extent} or \code{lonlat} are not defined. 29 | \item \code{extent} an \code{extent}, \code{Raster*}, or \code{Spatial*} 30 | object representing the region of interest with longitude/latitude 31 | coordinates. This argument is mandatory if \code{region} or \code{lonlat} 32 | are not defined. 33 | \item \code{lonlat} a vector with the longitude/latitude 34 | coordinates of the point of interest. This argument is mandatory if 35 | \code{region} or \code{extent} are not defined. 36 | \item \code{platform} the name of the Sentinel mission ("Sentinel-1", 37 | "Sentinel-2", ...). 38 | \item \code{qformat} the format of the response. 39 | \item \code{verbose} logical argument. If \code{TRUE}, the function prints 40 | the running steps and warnings. 41 | }} 42 | } 43 | \description{ 44 | \code{senSearch} searches Sentinel images through ESA's powered application 45 | programming interface (API), called 46 | \href{http://scihub.copernicus.eu}{`SciHub'}, that concern a particular 47 | location and date interval. The function returns a \code{data.frame} with 48 | the names of the images and their uniform resource locators (URLs). 49 | } 50 | \details{ 51 | \code{senSearch} uses the 52 | \href{http://scihub.copernicus.eu}{ESA's powered API} (`SciHub').The catalogue 53 | of Sentinel-2 products can be found 54 | \href{https://sentinel.esa.int/web/sentinel/missions/sentinel-2/data-products}{here}. 55 | The function explores the images available for a specific location and 56 | time-span. Dates must be provided as \code{Date} class objects. Credentials 57 | from ESA’s `SciHub' are needed and they can be obtained 58 | \href{https://scihub.copernicus.eu/dhus/#/self-registration}{here}. 59 | } 60 | \examples{ 61 | \dontrun{ 62 | # load a spatial polygon object of Navarre 63 | data(ex.navarre) 64 | # perform the search query 65 | sres <- senSearch(startDate = as.Date("2018210", "\%Y\%j"), 66 | endDate = as.Date("2018218", "\%Y\%j"), 67 | platform = "Sentinel-2", 68 | region = ex.navarre, 69 | product = "S2MSI1C", 70 | username = "username", 71 | password = "password") 72 | head(sres) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /man/setRGISToolsOpt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RGISToolsOpts.R 3 | \name{setRGISToolsOpt} 4 | \alias{setRGISToolsOpt} 5 | \title{Change the default value of an RGISTools option} 6 | \usage{ 7 | setRGISToolsOpt(opt, value, env = optEnv) 8 | } 9 | \arguments{ 10 | \item{opt}{a \code{character} with the name of the option.} 11 | 12 | \item{value}{the new value of the selected option.} 13 | 14 | \item{env}{the environment where the `\code{RGISTools}' option is saved.} 15 | } 16 | \value{ 17 | this function does not return anything. 18 | } 19 | \description{ 20 | \code{setRGISToolsOpt} changes the default value of an `\code{RGISTools}' 21 | configuration variable. This function can be jointly used with 22 | \code{\link{showRGISToolsOpt}} and \code{\link{getRGISToolsOpt}}. 23 | } 24 | \examples{ 25 | # list avaliable options names 26 | showRGISToolsOpt() 27 | # list the URL where the Landsat-7 metadata is located 28 | getRGISToolsOpt("LS7META.dir") 29 | # change the URL where the Landsat-7 metadata is located 30 | setRGISToolsOpt("LS7META.dir", "NewMTDir") 31 | # list the URL where the Landsat-7 metadata is located 32 | getRGISToolsOpt("LS7META.dir") 33 | } 34 | -------------------------------------------------------------------------------- /man/showRGISToolsOpt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RGISToolsOpts.R 3 | \name{showRGISToolsOpt} 4 | \alias{showRGISToolsOpt} 5 | \title{Print the name of all RGISTools configuration variables} 6 | \usage{ 7 | showRGISToolsOpt(env = optEnv) 8 | } 9 | \arguments{ 10 | \item{env}{the environment where the `\code{RGISTools}' option are saved.} 11 | } 12 | \value{ 13 | a \code{character} vector with the names of the configuration variables. 14 | } 15 | \description{ 16 | \code{showRGISToolsOpt} prints the name of all options in the `\code{RGISTools}' package. 17 | This function can be jointly used with \code{\link{setRGISToolsOpt}} and 18 | \code{\link{getRGISToolsOpt}}. 19 | } 20 | \examples{ 21 | showRGISToolsOpt() 22 | } 23 | -------------------------------------------------------------------------------- /man/varEVI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varEVI.R 3 | \name{varEVI} 4 | \alias{varEVI} 5 | \title{Calculate the enhanced vegetation index (EVI)} 6 | \usage{ 7 | varEVI(blue, red, nir, scfun = function(r) { 8 | r 9 | }) 10 | } 11 | \arguments{ 12 | \item{blue}{a \code{raster} with the blue band of the capture.} 13 | 14 | \item{red}{a \code{raster} with the red band of the capture.} 15 | 16 | \item{nir}{a \code{raster} with the NIR band of the capture.} 17 | 18 | \item{scfun}{a function to re-scale the original pixel values into 19 | reflectance (0-1).} 20 | } 21 | \value{ 22 | An EVI image in \code{raster} format. 23 | } 24 | \description{ 25 | \code{varEVI} computes the enhanced vegetation index (EVI) from the 26 | blue, near-infrared (NIR) and red bands. 27 | } 28 | \details{ 29 | The enhanced vegetation index (EVI) is a vegetation indicator that improves 30 | the sensitivity towards high biomass densities compared to NDVI 31 | \insertCite{huete2002overview}{RGISTools} (See \code{\link{varNDVI}}). This 32 | function is used within \code{\link{ls7FolderToVar}}, 33 | \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 34 | \code{\link{senFolderToVar}}. 35 | } 36 | \examples{ 37 | # path to the cropped and cutted MODIS images for the region of Navarre 38 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 39 | # list all the tif files 40 | files.mod <- list.files(wdir, pattern = "\\\\.tif$", recursive = TRUE, full.names = TRUE) 41 | # print the MOD09 bands 42 | getRGISToolsOpt("MOD09BANDS") 43 | scale.factor <- 0.0001 44 | 45 | # select the red, blue and nir bands 46 | img.mod.red <- raster(files.mod[1]) * scale.factor 47 | img.mod.blue <- raster(files.mod[3]) * scale.factor 48 | img.mod.nir <- raster(files.mod[2]) * scale.factor 49 | # calculate the EVI without scale 50 | img.mod.evi <- varEVI(img.mod.blue, img.mod.red, img.mod.nir) 51 | # calculate the EVI scaling 0-1 52 | img.mod.evi.2 <- varEVI(img.mod.blue, img.mod.red, img.mod.nir,scfun=getRGISToolsOpt("MOD09SCL")) 53 | img.mod.evi.12 <- stack(img.mod.evi,img.mod.evi.2) 54 | # plot the image 55 | spplot(img.mod.evi.12,col.regions=rev(terrain.colors(20)),at = c(seq(0,1,0.05))) 56 | } 57 | \references{ 58 | \insertRef{huete2002overview}{RGISTools} 59 | } 60 | -------------------------------------------------------------------------------- /man/varMSAVI2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varMSAVI2.R 3 | \name{varMSAVI2} 4 | \alias{varMSAVI2} 5 | \title{Calculate the modified soil-adjusted vegetation index (MSAVI2)} 6 | \usage{ 7 | varMSAVI2(red, nir) 8 | } 9 | \arguments{ 10 | \item{red}{a \code{raster} with the red band of the capture.} 11 | 12 | \item{nir}{a \code{raster} with the NIR band of the capture.} 13 | } 14 | \value{ 15 | A MSAVI2 image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varMSAVI2} computes the modified soil-adjusted vegetation index 2 19 | (MSAVI2) from the near-infrared (NIR) and red bands. 20 | } 21 | \details{ 22 | The modified soil adjusted vegetation index 2 (MSAVI2) is a vegetation 23 | indicator that removes the effect from background variations 24 | \insertCite{qi1994modified}{RGISTools}. This function is used within 25 | \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 26 | \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 27 | } 28 | \examples{ 29 | # path to the cropped and cutted MODIS images for the region of Navarre 30 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 31 | # list all the tif files 32 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 33 | # print the MOD09 bands 34 | getRGISToolsOpt("MOD09BANDS") 35 | # select the red and NIR bands 36 | img.mod.red <- raster(files.mod[1]) 37 | img.mod.nir <- raster(files.mod[2]) 38 | # calculate the MSAVI2 image 39 | img.mod.msavi2 <- varMSAVI2(img.mod.red, img.mod.nir) 40 | # plot the image 41 | spplot(img.mod.msavi2,col.regions=rev(topo.colors(20))) 42 | } 43 | \references{ 44 | \insertRef{qi1994modified}{RGISTools} 45 | } 46 | -------------------------------------------------------------------------------- /man/varNBR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varNBR.R 3 | \name{varNBR} 4 | \alias{varNBR} 5 | \title{Calculate the normalized burn ratio (NBR)} 6 | \usage{ 7 | varNBR(nir, swir2) 8 | } 9 | \arguments{ 10 | \item{nir}{a \code{raster} with the NIR band of the capture.} 11 | 12 | \item{swir2}{a \code{raster} with the SWIR2 band of the capture.} 13 | } 14 | \value{ 15 | A NBR image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varNBR} computes the normalized burn ratio (NBR) from the 19 | near-infrared (NIR) and shortwave-infrared 2 (SWIR2) bands. 20 | } 21 | \details{ 22 | The normalized burn ratio (NBR) is an index that identifies burned areas by 23 | comparing its value before and after the fire event. It is calculated using the 24 | NIR and SWIR2 bands \insertCite{garcia1991mapping}{RGISTools}.This function 25 | is used within \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 26 | \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 27 | } 28 | \examples{ 29 | # path to the cropped and cutted MODIS images for the region of Navarre 30 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 31 | # list all the tif files 32 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 33 | # print the MOD09 bands 34 | getRGISToolsOpt("MOD09BANDS") 35 | 36 | # select the NIR and SWIR2 bands 37 | files.mod.nir <- raster(files.mod[2]) 38 | files.mod.swir2 <- raster(files.mod[7]) 39 | # calculate the NBR image 40 | files.mod.nbr <- varNBR(files.mod.nir, files.mod.swir2) 41 | # plot the image 42 | spplot(files.mod.nbr,col.regions=rev(heat.colors(20))) 43 | } 44 | \references{ 45 | \insertRef{garcia1991mapping}{RGISTools} 46 | } 47 | -------------------------------------------------------------------------------- /man/varNBR2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varNBR2.R 3 | \name{varNBR2} 4 | \alias{varNBR2} 5 | \title{Calculate the normalized burn ratio 2 (NBR2)} 6 | \usage{ 7 | varNBR2(swir1, swir2) 8 | } 9 | \arguments{ 10 | \item{swir1}{a \code{raster} with the the SWIR1 band of the capture.} 11 | 12 | \item{swir2}{a \code{raster} with the the SWIR2 band of the capture.} 13 | } 14 | \value{ 15 | A NBR2 image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varNBR2} computes the NBR2 index from the shortwave infrared 1 (SWIR1) 19 | and shortwave infrared 2 (SWIR2). 20 | } 21 | \details{ 22 | The normalized burn ratio 2 (NRB2) is an index to identify burned areas. 23 | In contrast to NBR, NRB2 highlights the sensitivity to water in vegetation 24 | \insertCite{lutes2006firemon}{RGISTools}. This function is used within 25 | \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 26 | \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 27 | } 28 | \examples{ 29 | # path to the cropped and cutted MODIS images for the region of Navarre 30 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 31 | # list all the tif files 32 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 33 | # print the MOD09 bands 34 | getRGISToolsOpt("MOD09BANDS") 35 | 36 | # select the SWIR1 and SWIR2 bands 37 | img.mod.swir1 <- raster(files.mod[6]) 38 | img.mod.swir2 <- raster(files.mod[7]) 39 | # calculate the NBR2 image 40 | img.mod.nbr2 <- varNBR2(img.mod.swir1,img.mod.swir2) 41 | # plot the image 42 | spplot(img.mod.nbr2,col.regions=rev(heat.colors(20))) 43 | } 44 | \references{ 45 | \insertRef{lutes2006firemon}{RGISTools} 46 | } 47 | -------------------------------------------------------------------------------- /man/varNDMI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varNDMI.R 3 | \name{varNDMI} 4 | \alias{varNDMI} 5 | \title{Calculate the normalized difference moisture (water) index (NDMI)} 6 | \usage{ 7 | varNDMI(nir, swir1) 8 | } 9 | \arguments{ 10 | \item{nir}{a \code{raster} with the nir band of the capture.} 11 | 12 | \item{swir1}{a \code{raster} with the swir1 band of the capture.} 13 | } 14 | \value{ 15 | A NDMI image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varNDMI} computes the normalized difference moisture index (NDMI) from 19 | the near-infrared (NIR) and shortwave-infrared 1 (SWIR1) bands. 20 | } 21 | \details{ 22 | The normalized difference moisture index (NDMI) is an index that represents 23 | the water stress levels of the canopy, using the NIR and SWIR 24 | \insertCite{gao1995normalized}{RGISTools}. 25 | This function is used within \code{\link{ls7FolderToVar}}, 26 | \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 27 | \code{\link{senFolderToVar}}. 28 | } 29 | \examples{ 30 | # path to the cropped and cutted MODIS images for the region of Navarre 31 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 32 | # list all the tif files 33 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 34 | # print the MOD09 bands 35 | getRGISToolsOpt("MOD09BANDS") 36 | 37 | # select the NIR and SWIR1 bands 38 | img.mod.nir <- raster(files.mod[2]) 39 | img.mod.swir1 <- raster(files.mod[6]) 40 | # calculate the NDMI image 41 | img.mod.ndmi <- varNDMI(img.mod.nir,img.mod.swir1) 42 | # plot the image 43 | spplot(img.mod.ndmi) 44 | } 45 | \references{ 46 | \insertRef{gao1995normalized}{RGISTools} 47 | } 48 | -------------------------------------------------------------------------------- /man/varNDVI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varNDVI.R 3 | \name{varNDVI} 4 | \alias{varNDVI} 5 | \title{Calculate the normalized difference vegetation index (NDVI)} 6 | \usage{ 7 | varNDVI(red, nir) 8 | } 9 | \arguments{ 10 | \item{red}{a \code{raster} with the red band of the capture.} 11 | 12 | \item{nir}{a \code{raster} with the NIR band of the capture.} 13 | } 14 | \value{ 15 | A NDVI image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varNDVI} computes the normalized difference vegetation index (NDVI) 19 | from the red an near-infrared (NIR) bands. 20 | } 21 | \details{ 22 | The normalized difference vegetation index (NDVI) is the most widely used 23 | index for monitoring vegetation dynamics. The NDVI reflects the vegetation vigour 24 | and it is closely related to the amount of photosynthetically active radiation 25 | absorbed \insertCite{rouse1972monitoring}{RGISTools}. This function is used 26 | within \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 27 | \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 28 | } 29 | \examples{ 30 | # path to the cropped and cutted MODIS images for the region of Navarre 31 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 32 | # list all the tif files 33 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 34 | # print the MOD09 bands 35 | getRGISToolsOpt("MOD09BANDS") 36 | 37 | # select the red and NIR bands 38 | img.mod.red <- raster(files.mod[1]) 39 | img.mod.nir <- raster(files.mod[2]) 40 | # calculate the NDVI image 41 | img.mod.ndvi <- varNDVI(img.mod.red,img.mod.nir) 42 | # plot the image 43 | spplot(img.mod.ndvi,col.regions=rev(terrain.colors(20))) 44 | } 45 | \references{ 46 | \insertRef{rouse1972monitoring}{RGISTools} 47 | } 48 | -------------------------------------------------------------------------------- /man/varNDWI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varNDWI.R 3 | \name{varNDWI} 4 | \alias{varNDWI} 5 | \title{Calculates the normalized difference water index (NDWI)} 6 | \usage{ 7 | varNDWI(green, nir) 8 | } 9 | \arguments{ 10 | \item{green}{a \code{raster} with the green band of the capture.} 11 | 12 | \item{nir}{a \code{raster} with the NIR band of the capture.} 13 | } 14 | \value{ 15 | A NDWI image in \code{raster} format. 16 | } 17 | \description{ 18 | \code{varNDWI} Calculate the normalized difference water index (NDWI) from 19 | the green and near-infrared (NIR) bands. 20 | } 21 | \details{ 22 | The normalized difference water index (NDWI) is a ratio between the green 23 | and near-infrared bands of the spectrum that was developed to detect open 24 | water areas and minimize the influence of the soil and vegetation variations 25 | \insertCite{mcfeeters1996use}{RGISTools}. This function is used within 26 | \code{\link{ls7FolderToVar}}, \code{\link{ls8FolderToVar}}, 27 | \code{\link{modFolderToVar}} and \code{\link{senFolderToVar}}. 28 | } 29 | \examples{ 30 | # path to the cropped and cutted MODIS images for the region of Navarre 31 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 32 | # list all the tif files 33 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 34 | # print the MOD09 bands 35 | getRGISToolsOpt("MOD09BANDS") 36 | 37 | # select the green and NIR bands 38 | img.mod.green <- raster(files.mod[4]) 39 | img.mod.nir <- raster(files.mod[2]) 40 | # calculate the NDWI image 41 | img.mod.ndwi <- varNDWI(img.mod.green,img.mod.nir) 42 | # plot the image 43 | spplot(img.mod.ndwi,col.regions=rev(rainbow(20))) 44 | } 45 | \references{ 46 | \insertRef{mcfeeters1996use}{RGISTools} 47 | } 48 | -------------------------------------------------------------------------------- /man/varRGB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varRGB.R 3 | \name{varRGB} 4 | \alias{varRGB} 5 | \title{Generate an RGB image from 3 spectral bands} 6 | \usage{ 7 | varRGB(red, green, blue, q.range = c(), rPath = NULL, region = NULL) 8 | } 9 | \arguments{ 10 | \item{red}{a \code{raster} with the red band of the capture.} 11 | 12 | \item{green}{a \code{raster} with the green band of the capture.} 13 | 14 | \item{blue}{a \code{raster} with the blue band of the capture.} 15 | 16 | \item{q.range}{a vector with the minimum and maximum reflectance quantiles 17 | being considered.} 18 | 19 | \item{rPath}{the file path where the resulting RGB image is saved.} 20 | 21 | \item{region}{a \code{Spatial*}, projected \code{raster*}, or \code{sf} class object 22 | defining the area of interest for image masking.} 23 | } 24 | \description{ 25 | \code{varRGB} creates red-green-blue (RGB) images as a \code{RasterStack} by 26 | scaling the pixel values to 0-255 color range. 27 | } 28 | \details{ 29 | The function rescales the original reflectance values to a range of 0-255. 30 | The function re-arranges the RGB bands to create a stack ready to visualize 31 | with plotRGB. Bands may contain outliers which cause the image to look dark. 32 | Use the \code{q.range} argument to remove the outliers and get a 33 | better-looking image. 34 | } 35 | \examples{ 36 | # path to the cropped and cutted MODIS images for the region of Navarre 37 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 38 | # list all the tif files 39 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 40 | # print the MOD09 bands 41 | getRGISToolsOpt("MOD09BANDS") 42 | 43 | # select the red, blue and NIR bands 44 | img.mod.red <- raster(files.mod[1]) 45 | img.mod.blue <- raster(files.mod[3]) 46 | img.mod.green <- raster(files.mod[4]) 47 | 48 | q.range=c(0.001,0.999) 49 | img.mod.rgb<-varRGB(img.mod.red,img.mod.green,img.mod.blue,q.range) 50 | print(plotRGB(img.mod.rgb)) 51 | } 52 | -------------------------------------------------------------------------------- /man/varSAVI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/varSAVI.R 3 | \name{varSAVI} 4 | \alias{varSAVI} 5 | \title{Calculates the soil-adjusted vegetation index (SAVI)} 6 | \usage{ 7 | varSAVI(red, nir, L = 0.5, scfun = function(r) { 8 | r 9 | }) 10 | } 11 | \arguments{ 12 | \item{red}{a \code{raster} with the red band of the capture.} 13 | 14 | \item{nir}{a \code{raster} with the NIR band of the capture.} 15 | 16 | \item{L}{a constant to remove soil background effect. A value of 0.5 is 17 | recommended in the literature.} 18 | 19 | \item{scfun}{a function to re-scale the original pixel values into 20 | reflectance (0-1).} 21 | } 22 | \value{ 23 | A SAVI image in \code{raster} format. 24 | } 25 | \description{ 26 | \code{varSAVI} Calculate the soil-adjusted vegetation index (SAVI) from the 27 | red and near-infrared (NIR) bands. 28 | } 29 | \details{ 30 | The soil adjusted vegetation index (SAVI) is an indicator engineered to remove 31 | the influence of the soil background effect \insertCite{huete1988soil}{RGISTools}. 32 | This function is used within \code{\link{ls7FolderToVar}}, 33 | \code{\link{ls8FolderToVar}}, \code{\link{modFolderToVar}} and 34 | \code{\link{senFolderToVar}}. 35 | } 36 | \examples{ 37 | # path to the cropped and cutted MODIS images for the region of Navarre 38 | wdir <- system.file("ExNavarreVar", package = "RGISTools") 39 | # list all the tif files 40 | files.mod <- list.files(wdir, pattern="\\\\.tif$", recursive = TRUE, full.names = TRUE) 41 | # print the MOD09 bands 42 | getRGISToolsOpt("MOD09BANDS") 43 | 44 | # select the red and NIR bands 45 | img.mod.red <- raster(files.mod[1]) 46 | img.mod.nir <- raster(files.mod[2]) 47 | # calculate the SAVI image 48 | img.mod.savi <- varSAVI(img.mod.red,img.mod.nir,scfun=getRGISToolsOpt("MOD09SCL")) 49 | # plot the image 50 | spplot(img.mod.savi,col.regions=rev(topo.colors(20))) 51 | } 52 | \references{ 53 | \insertRef{huete1988soil}{RGISTools} 54 | } 55 | --------------------------------------------------------------------------------