Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Λήψη δορυφορικών εικόνων στην R μέσω του GIBS API
library(gdalUtils)
rGIBS<-function(date=Sys.Date(), EPSGCODE,PRODUCT,projwin, outputdir=file.path(Sys.getenv("HOME"),"gibs_downloads"),...){
dir.create(outputdir, showWarnings = FALSE)
setwd(outputdir)
#generate xml
makeXML <- function(date, EPSGCODE,PRODUCT){
myxml<- sprintf('<GDAL_WMS><Service name="TiledWMS"><ServerUrl>https://gibs.earthdata.nasa.gov/twms/epsg%s/best/twms.cgi?</ServerUrl><TiledGroupName>%s tileset</TiledGroupName><Change key="${time}">%s</Change></Service></GDAL_WMS>',EPSGCODE, PRODUCT, date)
tmp <- tempfile(fileext=".xml")
fileConn<-file(tmp)
writeLines(myxml, fileConn)
close(fileConn)
return(tmp)
}
infile<-makeXML(date,EPSGCODE,PRODUCT)
outfile<-gsub(" ","_",(sprintf('%s_%s_EPSG%s.tif',PRODUCT,date,EPSGCODE)))
gdal_translate(
infile,
outfile,
projwin=projwin,
verbose = T,
...
)
#delete temp file
unlink(infile)
message(sprintf("Image %s was saved in %s", outfile, outputdir))
return (file.path(outputdir,outfile))
}
PRODUCT<-'VIIRS SNPP DayNightBand ENCC'
EPSGCODE<-4326
date<-'2017-08-15'
projwin <- c(19.07, 42.16, 28.39, 34.5)
image<-rGIBS(date=date,EPSGCODE=EPSGCODE,PRODUCT=PRODUCT, projwin=projwin, of = "GTiff")
plotRGB(stack(image))
dates<-seq(as.Date("2017/11/08"), as.Date("2017/11/09"), "days")
myresults<-lapply(
dates,
rGIBS,
EPSGCODE=EPSGCODE,
PRODUCT=PRODUCT,
projwin=projwin,
of = "GTiff"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment