-
Notifications
You must be signed in to change notification settings - Fork 1
/
OD_jour.Rmd
295 lines (232 loc) · 7.74 KB
/
OD_jour.Rmd
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
---
title: "Task1:OD pour un jour fixe"
output: html_document
date: "2023-02-24"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Description
Dans cette tache l'objectif est d'obtenir la matrice de dependance pour un jour choisit. Pour visualiser les differents flux survenu au cours de differentes heures de la journée :
- Selectionner un jour
- Creer la matrice de dépendance pour differents heures de la journée y compris l'heure de pointe
- Afficher la carte de flux pour les heures selectionnées
## 1. Load packages
```{r loadlib,}
library(dplyr)
library(sf)
library(leaflet)
library(lubridate)
library(mapsf)
library(tidyr)
```
## 2. Load data
```{r loadData}
heetchPoints <-readRDS("DATA/heetchmarchcrop.Rds")
casaNeib <-st_read("DATA/casaneib.geojson")
```
## 3. Projetion les objets spatiaux
```{r spaceProj}
casaNeibProj <-st_transform(casaNeib, crs=26191)
heetchPointsProj <-st_transform(heetchPoints, crs=26191)
```
## 4. Créer la section du 1er Mars
Ici on fixe le jour au 1er Mars
```{r heetchM1Proj}
heetchPointsProj$Day <-day(heetchPointsProj$location_at_local_time)
heetchPointsProj$Hour <-hour(heetchPointsProj$location_at_local_time)
heetchM1Proj <-heetchPointsProj %>%
filter(Day==1)
```
## 5. Intersection des points x et des quartiers y
```{r intersection}
casaNeibUnion <-st_union(casaNeibProj)
ptsInCasa <-st_contains(x=casaNeibUnion, y=heetchM1Proj)
selectPtsInCasa <-unlist(ptsInCasa)
heetchM1CropProj <-heetchM1Proj[selectPtsInCasa,]
ptsInNeib <-st_within(x=heetchM1Proj, y=casaNeibProj) %>%
unlist()
heetchM1CropProj$NEIB <-ptsInNeib
```
## 6. Grouper par heure/ par identifiant chauffeur et par quartier
```{r groupeBy}
nestedPts <-heetchM1CropProj %>%
st_drop_geometry() %>%
group_by(Hour,NEIB, driver_id) %>%
summarize(NBPTS=n())
```
## 7. Selectionner le quartier principal pour chaque chauffeur à chaque heure
```{r mainNeib}
mainNeib <-nestedPts %>%
group_by(driver_id, Hour) %>%
arrange(desc(NBPTS)) %>%
slice(1)
```
## 8. Construire la matrice OD (origine-destination) pour le 1er Mars entre 7H et 8H du matin avec le nombre de drivers
```{r OD78}
# mainNeibwide a comme colonne(driver_id, hours:00,01...)
mainNeibwide <-mainNeib %>%
select(driver_id,Hour,NEIB) %>%
pivot_wider(names_from=Hour,
values_from=NEIB,
names_prefix="H",
values_fill=NA)
OD78 <-mainNeibwide %>%
group_by(H7,H8) %>%
summarize(NB=n()) %>%
filter(!is.na(H7) & !is.na(H8))%>%
rename(ORI=H7, DES=H8)
OD78$ORINAME <-casaNeib$NAME_4[OD78$ORI]
OD78$DESNAME <-casaNeib$NAME_4[OD78$DES]
polCentroids <- st_centroid(casaNeibProj) # pour avoir les centroides
coordCentroids <-st_coordinates((polCentroids)) %>%as_data_frame()
# pour avoir les coordonnées des centroides
class(coordCentroids)
OD78$XORI <-coordCentroids$X[OD78$ORI]
OD78$XDES <-coordCentroids$X[OD78$DES]
OD78$YORI <-coordCentroids$Y[OD78$ORI]
OD78$YDES <-coordCentroids$Y[OD78$DES]
head(OD78)
```
- Afficher la carte
```{r OD78Map}
selecFlows <-OD78 %>% filter(NB>2)
plot(casaNeibProj$geometry, col="grey80", border ="grey30")
arrows(selecFlows$XORI,
selecFlows$YORI,
selecFlows$XDES,
selecFlows$YDES,
col="chocolate",
lwd=2,
length=0.1,
code=2)
```
## 9. Construire la matrice OD (origine-destination) pour le 1er Mars entre 12H et 13H du matin avec le nombre de drivers
```{r OD1213}
OD1213 <-mainNeibwide %>%
group_by(H12,H13) %>%
summarize(NB=n()) %>%
filter(!is.na(H12) & !is.na(H13))%>%
rename(ORI=H12, DES=H13)
OD1213$ORINAME <-casaNeib$NAME_4[OD1213$ORI]
OD1213$DESNAME <-casaNeib$NAME_4[OD1213$DES]
polCentroids <- st_centroid(casaNeibProj) # pour avoir les centroides
coordCentroids <-st_coordinates((polCentroids)) %>%as_data_frame()
# pour avoir les coordonnées des centroides
class(coordCentroids)
OD1213$XORI <-coordCentroids$X[OD1213$ORI]
OD1213$XDES <-coordCentroids$X[OD1213$DES]
OD1213$YORI <-coordCentroids$Y[OD1213$ORI]
OD1213$YDES <-coordCentroids$Y[OD1213$DES]
head(OD1213)
```
- Afficher la carte
```{r OD1213Map}
selecFlows <-OD1213 %>% filter(NB>2)
plot(casaNeibProj$geometry, col="grey80", border ="grey30")
arrows(selecFlows$XORI,
selecFlows$YORI,
selecFlows$XDES,
selecFlows$YDES,
col="chocolate",
lwd=2,
length=0.1,
code=2)
```
## 10. Construire la matrice OD (origine-destination) pour le 1er Mars entre 18H et 19H du matin avec le nombre de drivers
```{r OD1819}
OD1819 <-mainNeibwide %>%
group_by(H18,H19) %>%
summarize(NB=n()) %>%
filter(!is.na(H18) & !is.na(H19))%>%
rename(ORI=H18, DES=H19)
OD1819$ORINAME <-casaNeib$NAME_4[OD1819$ORI]
OD1819$DESNAME <-casaNeib$NAME_4[OD1819$DES]
polCentroids <- st_centroid(casaNeibProj) # pour avoir les centroides
coordCentroids <-st_coordinates((polCentroids)) %>%as_data_frame()
# pour avoir les coordonnées des centroides
class(coordCentroids)
OD1819$XORI <-coordCentroids$X[OD1819$ORI]
OD1819$XDES <-coordCentroids$X[OD1819$DES]
OD1819$YORI <-coordCentroids$Y[OD1819$ORI]
OD1819$YDES <-coordCentroids$Y[OD1819$DES]
head(OD1819)
```
- Afficher la carte
```{r OD1819Map}
selecFlows <-OD1819 %>% filter(NB>2)
plot(casaNeibProj$geometry, col="grey80", border ="grey30")
arrows(selecFlows$XORI,
selecFlows$YORI,
selecFlows$XDES,
selecFlows$YDES,
col="chocolate",
lwd=2,
length=0.1,
code=2)
```
# 11. Matrice OD (origine-destination) pour le 1er Mars entre 21H et 22H (heure de pointe) avec le nombre de drivers
```{r OD2122}
OD2122 <-mainNeibwide %>%
group_by(H21,H22) %>%
summarize(NB=n()) %>%
filter(!is.na(H21) & !is.na(H22))%>%
rename(ORI=H21, DES=H22)
OD2122$ORINAME <-casaNeib$NAME_4[OD2122$ORI]
OD2122$DESNAME <-casaNeib$NAME_4[OD2122$DES]
polCentroids <- st_centroid(casaNeibProj) # pour avoir les centroides
coordCentroids <-st_coordinates((polCentroids)) %>%as_data_frame()
# pour avoir les coordonnées des centroides
class(coordCentroids)
OD2122$XORI <-coordCentroids$X[OD2122$ORI]
OD2122$XDES <-coordCentroids$X[OD2122$DES]
OD2122$YORI <-coordCentroids$Y[OD2122$ORI]
OD2122$YDES <-coordCentroids$Y[OD2122$DES]
head(OD2122)
```
- Afficher la carte
```{r OD2122Map}
selecFlows <-OD2122 %>% filter(NB>2)
plot(casaNeibProj$geometry, col="grey80", border ="grey30")
arrows(selecFlows$XORI,
selecFlows$YORI,
selecFlows$XDES,
selecFlows$YDES,
col="chocolate",
lwd=2,
length=0.1,
code=2)
```
# 12. Matrice OD (origine-destination) pour le 1er Mars entre 22H et 23H (1h apres heure de pointe) avec le nombre de drivers
```{r OD2223}
OD2223 <-mainNeibwide %>%
group_by(H22,H23) %>%
summarize(NB=n()) %>%
filter(!is.na(H22) & !is.na(H23))%>%
rename(ORI=H22, DES=H23)
OD2223$ORINAME <-casaNeib$NAME_4[OD2223$ORI]
OD2223$DESNAME <-casaNeib$NAME_4[OD2223$DES]
polCentroids <- st_centroid(casaNeibProj) # pour avoir les centroides
coordCentroids <-st_coordinates((polCentroids)) %>%as_data_frame()
# pour avoir les coordonnées des centroides
class(coordCentroids)
OD2223$XORI <-coordCentroids$X[OD2223$ORI]
OD2223$XDES <-coordCentroids$X[OD2223$DES]
OD2223$YORI <-coordCentroids$Y[OD2223$ORI]
OD2223$YDES <-coordCentroids$Y[OD2223$DES]
head(OD2223)
```
- Afficher la carte
```{r OD2223Map}
selecFlows <-OD2223 %>% filter(NB>2)
plot(casaNeibProj$geometry, col="grey80", border ="grey30")
arrows(selecFlows$XORI,
selecFlows$YORI,
selecFlows$XDES,
selecFlows$YDES,
col="chocolate",
lwd=2,
length=0.1,
code=2)
```
Remarque: On constate à travers les differents graphique que le flux est plus important au tour de trois points comme on peut le voir sur le carte. Mais aussi que les flux deviennent de plus en plus important dans les heures du soir au alentour de 22H qui est donc veritablement l'heure de pointe.