-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgif_xp.R
220 lines (156 loc) · 9.17 KB
/
gif_xp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
##.###################################################################################33
## Script rapide pour faire des gifs sur l'xp ====
##.#################################################################################33
# . -------------------------------------------------------------------------- =============
# I - Nettoyage / mise en forme ----------------------------------------------------------------- =============
# . -------------------------------------------------------------------------- =============
## 1 - load package =======
library(jsonlite) # pour les json
library(tidyverse) # envt pour des donnees de type tidy pas trop volumineuse
library(sf) # package spatial
library(lubridate)
library(tmap)
library(tmaptools)
library(ggmap)
library(gganimate)
library(dplyr)
## 2 - stream du json et ouverture d'autre données necessaire =======
zone.shp <- st_read("data/zone_se.shp") # ouverture du fichier de zone
zone.shp <- zone.shp[zone.shp$id ==1, ] # on ne garde qu'une zone
arbre_xp.shp <- st_read("data/arbres_se_final.geojson") # on prend les arbres que l'on connait
exp_brut <- stream_in(file("data/tracesBrutesStEtienne29_06_19.json")) #stream du json
# on recode activité
exp_brut$code_activ <- exp_brut$activity$index
exp_brut$code_activ <- exp_brut$code_activ+1
# il faut me virer (defuneste) car je n'ai pas participé, juste montré directement sur mon tel parfois
exp_brut <- exp_brut[exp_brut$username != "defuneste",]
# on ne garde que newObservation
newObservation <- exp_brut[exp_brut$event == "newObservation",]
newObservation.df <- newObservation[,c(5:6,9)] ## attention ici j'ai fait des selections par num de colonnes
#### c'est assez hideux mais je fais vite
newObservation$point <- NULL
for(i in 1:length(newObservation$event)) {
newObservation.df$point[i] <- st_sfc(st_point(newObservation$object[[i]]$location$coordinates))}
newObservation.df <- st_sf(newObservation.df, geom = newObservation.df$point) # la bonne colone pour le champs geom
newObservation.df <- newObservation.df[,-4] ## attention ici j'ai fait des selections par num de colonnes
st_crs(newObservation.df) = 4326 # le bon scr
# ici j'extrait de manière un peu plus propre des infos comme nom commun, espèces et genus
df_bota <- as.data.frame(t(sapply(newObservation[["object"]], `[`, c("authorName","common" , "specie", "genus"))))
names(df_bota) <- c("authorName", "common", "specie", "genus")
newObservation.df <- bind_cols(newObservation.df, df_bota) %>% select(-"authorName")
# on met la bonne tz
attr(newObservation.df$date, "tzone") <- "Europe/Paris"
## 3 - on coupe pour avoir une bonne zone =======
newObservation.df <- newObservation.df[zone.shp,] # les obs
arbre_xp_zone.shp <- arbre_xp.shp[zone.shp,] # les arbres attendus
# . -------------------------------------------------------------------------- =============
# II - une carte animée ----------------------------------------------------------------- =============
# . -------------------------------------------------------------------------- =============
## 1 - Fond de cartes =======
# ici je prend chez stamen, il faut une bbox bb() de sf
xp_st_e <- ggmap(get_stamenmap(bb(zone.shp, output = "matrix"),zoom = 16, maptype = "terrain-lines"))
# str(xp_st_e)
# bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat)
arbre_xp_zone.coord <-st_coordinates(arbre_xp_zone.shp)
arbre_xp_zone.coord <- as.data.frame(arbre_xp_zone.coord)
arbre_xp_zone.shp[bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat),]
obs_timing <- st_coordinates(newObservation.df)
obs_timing <- as.data.frame(obs_timing)
obs_timing$date <- newObservation.df$date
obs_timing$username <- newObservation.df$username
obs_timing$participant <- "Particpant 1"
obs_timing$participant[obs_timing$username == "tjoliveau"] <- "Particpant 2"
obs_timing$participant[obs_timing$username == "JitenshaNiko"] <- "Particpant 3"
obs_timing$participant[obs_timing$username == "MathDu"] <- "Particpant 4"
obs_timing$participant[obs_timing$username == "Yoann Duriaux"] <- "Particpant 5"
obs_timing$participant[obs_timing$username == "pofx"] <- "Particpant 6"
obs_timing$participant[obs_timing$username == "Catherine JHG"] <- "Particpant 7"
unique(obs_timing$username)
xp_st_e_anim <- xp_st_e +
geom_point(aes(x = 4.3860717, y = 45.4496287), size = 4, pch = "M") +# localisation mixeur
geom_point(data = arbre_xp_zone.coord, aes(x = X, y = Y), size = 0.75, col = "#208842", alpha = 0.5) +
#geom_point(data = obs_timing, aes(x = X, y = Y), size = 2.5) +
geom_point(data = obs_timing, aes(x = X, y = Y, colour = participant), size = 2.5) +
xlab("") + ylab("") +
ggtitle("Test d'Albiziapp",
subtitle = 'time:{frame_time}') +
transition_components(date) +
shadow_mark()
xp_st_e_anim
anim_save("xp_st_e_anim.gif" , animation = last_animation())
# . -------------------------------------------------------------------------- =============
# III - une carte animée du 16 - 09 ----------------------------------------------------------------- =============
# . -------------------------------------------------------------------------- =============
## 1 - Fond de cartes =======
# ici je prend chez stamen, il faut une bbox bb() de sf
xp_st_e <- ggmap(get_stamenmap(bb(zone.shp, output = "matrix"),zoom = 16, maptype = "terrain-lines"))
# str(xp_st_e)
# bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat)
arbre_xp_zone.coord <-st_coordinates(arbre_xp_zone.shp)
arbre_xp_zone.coord <- as.data.frame(arbre_xp_zone.coord)
arbre_xp_zone.shp[bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat),]
obs_timing <- st_coordinates(newObservation.shp)
obs_timing <- as.data.frame(obs_timing)
obs_timing$date <- newObservation.shp$date
obs_timing$username <- newObservation.shp$username
# obs_timing$participant <- "Particpant 1"
# obs_timing$participant[obs_timing$username == "tjoliveau"] <- "Particpant 2"
# obs_timing$participant[obs_timing$username == "JitenshaNiko"] <- "Particpant 3"
# obs_timing$participant[obs_timing$username == "MathDu"] <- "Particpant 4"
# obs_timing$participant[obs_timing$username == "Yoann Duriaux"] <- "Particpant 5"
# obs_timing$participant[obs_timing$username == "pofx"] <- "Particpant 6"
# obs_timing$participant[obs_timing$username == "Catherine JHG"] <- "Particpant 7"
unique(obs_timing$username)
# animation::ani.options(ani.width= 1000, ani.height=1000, ani.res = 1000)
# animation::ani.options()
xp_st_e_anim <- xp_st_e +
geom_point(aes(x = 4.3860717, y = 45.4496287), size = 4, pch = "M") +# localisation mixeur
geom_point(data = arbre_xp_zone.coord, aes(x = X, y = Y), size = 0.75, col = "#208842", alpha = 0.5) +
#geom_point(data = obs_timing, aes(x = X, y = Y), size = 2.5) +
geom_point(data = obs_timing, aes(x = X, y = Y, colour = username), size = 2.5) +
xlab("") + ylab("") +
ggtitle("Test d'Albiziapp",
subtitle = 'time:{frame_time}') +
transition_components(date) +
shadow_mark()
animate(xp_st_e_anim , height = 800, width =800)
anim_save("xp_st_e_16-09bigger.gif" , animation = last_animation())
unique(newObservation.shp$username)
# . -------------------------------------------------------------------------- =============
# III - une carte animée du 01 - 10 ----------------------------------------------------------------- =============
# . -------------------------------------------------------------------------- =============
## 1 - Fond de cartes =======
# ici je prend chez stamen, il faut une bbox bb() de sf
xp_st_e <- ggmap(get_stamenmap(bb(zone.shp, output = "matrix"),zoom = 16, maptype = "terrain-lines"))
# str(xp_st_e)
# bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat)
arbre_xp_zone.coord <-st_coordinates(arbre_xp_zone.shp)
arbre_xp_zone.coord <- as.data.frame(arbre_xp_zone.coord)
arbre_xp_zone.shp[bb(x = xp_st_e$data$lon, y = xp_st_e$data$lat),]
obs_timing <- st_coordinates(newObservation.shp)
obs_timing <- as.data.frame(obs_timing)
obs_timing$date <- newObservation.shp$date
obs_timing$username <- newObservation.shp$username
# obs_timing$participant <- "Particpant 1"
# obs_timing$participant[obs_timing$username == "tjoliveau"] <- "Particpant 2"
# obs_timing$participant[obs_timing$username == "JitenshaNiko"] <- "Particpant 3"
# obs_timing$participant[obs_timing$username == "MathDu"] <- "Particpant 4"
# obs_timing$participant[obs_timing$username == "Yoann Duriaux"] <- "Particpant 5"
# obs_timing$participant[obs_timing$username == "pofx"] <- "Particpant 6"
# obs_timing$participant[obs_timing$username == "Catherine JHG"] <- "Particpant 7"
unique(obs_timing$username)
# animation::ani.options(ani.width= 1000, ani.height=1000, ani.res = 1000)
# animation::ani.options()
xp_st_e_anim <- xp_st_e +
geom_point(aes(x = 4.3860717, y = 45.4496287), size = 4, pch = "M") +# localisation mixeur
geom_point(data = arbre_xp_zone.coord, aes(x = X, y = Y), size = 0.75, col = "#208842", alpha = 0.5) +
#geom_point(data = obs_timing, aes(x = X, y = Y), size = 2.5) +
geom_point(data = obs_timing, aes(x = X, y = Y, colour = username), size = 2.5) +
xlab("") + ylab("") +
ggtitle("Test d'Albiziapp",
subtitle = 'time:{frame_time}') +
transition_components(date) +
shadow_mark()
animate(xp_st_e_anim , height = 800, width =800)
anim_save("xp_st_e_01-10bigger.gif" , animation = last_animation())
unique(newObservation.shp$username)