Created
November 20, 2021 18:40
-
-
Save idshklein/40dd2890840ee084ede7bde98dc1732b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(sf) | |
library(lubridate) | |
library(gganimate) | |
library(ggspatial) | |
day <- st_read("D:/Downloads/history-2021-11-08.kml") | |
OlsonNames() | |
PERIODS <- 10 | |
all <- day %>% | |
st_transform(2039) %>% | |
# filter(st_geometry_type(geometry) == "LINESTRING") %>% | |
st_zm() %>% | |
separate(Description,c("tmp", "times"),"from ") %>% | |
select(-tmp) %>% | |
separate(times,c("times", "tmp"),". Distance") %>% | |
select(-tmp) %>% | |
separate(times,c("start", "end")," to ") %>% | |
mutate(start = as_datetime(start,tz = "Israel"), | |
end = as_datetime(end,tz = "Israel"), | |
diff = as.numeric(end - start), | |
period = diff/ PERIODS, | |
periods = PERIODS) %>% | |
uncount(periods) %>% | |
group_by(diff) %>% | |
mutate(rn = row_number()) %>% | |
ungroup() %>% | |
mutate(time = 60*rn*period + start) | |
points <-all %>% | |
filter(st_geometry_type(geometry) == "POINT") | |
lines <- all %>% | |
filter(st_geometry_type(geometry) == "LINESTRING") %>% | |
mutate(geometry =st_sfc(map2(geometry,rn,~st_line_sample(.x,PERIODS) %>% | |
st_cast("POINT") %>% | |
st_sf() %>% | |
slice(.y) %>% | |
pull(geometry) %>% | |
unlist() %>% | |
st_point()))) | |
# st_set_geometry("point") | |
prin <- bind_rows(points,lines) %>% | |
arrange(time) %>% | |
mutate(rn = row_number()) | |
plot1 <- prin %>% | |
ggplot(aes(label = Name)) + | |
annotation_map_tile()+ | |
geom_sf_label() + | |
transition_states(rn,transition_length = 0) + | |
ggtitle("{prin %>% filter(rn == closest_state) %>% pull(time)}") | |
plot1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment