Skip to content

Instantly share code, notes, and snippets.

@ozjimbob
Created September 11, 2019 06:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozjimbob/fb832ee3fe9ecc8718c782fa4c0d3662 to your computer and use it in GitHub Desktop.
Save ozjimbob/fb832ee3fe9ecc8718c782fa4c0d3662 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(sf)
library(mapview)
library(furrr)
library(raster)
plan(multiprocess)
ex = extent(c(xmin=-112,xmax=155,ymin=-44,ymax=-10))
ds=seq(as.POSIXct("2018-01-01"),as.POSIXct("2019-05-31"),by=600)
dtf = format(ds,"%Y/%m/%d/%Y%m%d_%H%M")
url = paste0("https://www.eorc.jaxa.jp/ptree/map/himawari/L2_WLF/",dtf,".kml")
df = tibble(date=ds,url=url)
fn = function(date,url){
o=try(read_sf(url))
if("try-error" %in% class(o)){return(NA)}else{
o=st_crop(o,ex)
if(nrow(o)==0){return(NA)}
coords=st_coordinates(o)
colnames(coords)=c("X","Y")
coords=as_tibble(coords)
coords$date = date
return(coords)
}
}
out = future_pmap(df,fn,.progress=TRUE)
list.condition <- sapply(out, function(x) is.data.frame(x))
output.list <- out[list.condition]
out2 = bind_rows(output.list)
out2 = st_as_sf(out2,coords=c("X","Y"),crs=4326,remove=FALSE)
library(lubridate)
out2$year = year(out2$date)
out2$month = month(out2$date)
out2$day = day(out2$date)
out2$hour = hour(out2$date)
write_sf(out2,"hhs_2017_2018b.gpkg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment