Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data prep #14

Merged
merged 5 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
Package: enquete.gflowiz
Title: Survey analysis on the needs and expectations of a geoweb application for (geo)visualization of origin-destination flow data
Package: arabesqueFOSS4G2021
Title: Article prepared for the FOSS4G 2021 comparing Arabesque to other flow map applications in the geoweb
Version: 0.0.0.9000
Authors@R: c(
person("Nicolas", "Roelandt", email = "nicolas.roelandt@univ-eiffel.fr", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9698-4275")),
person(given = "gflowiz", role = "cph")
)
Description: Contains the analysis of the online survey conducted in 2018 to collect the possible needs and expectations of a geoweb application for the analysis and the (geo)visualization of origin-destination flow data. </br>This survey made prior Arabesque app development.
Description: Contains the article source plus data and code
License: {{ License }}
LazyData: true
Encoding: UTF-8
VignetteBuilder: knitr
Suggests:
knitr,
rmarkdown
32 changes: 32 additions & 0 deletions R/prepare_nodes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' prepare_nodes
#'
#' Prepare nodes data
#'
#' @note Does not work using the formula notation involving \code{~} defined in \link[stats]{aggregate}.
#'
#' @param x object of class \link{sf}
#' @param vars variables to group by
#' @details
#' @examples
#' pl1 = sf::st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,0)))) * 3
#' pl2 = sf::st_polygon(list(rbind(c(0,0),c(1,1),c(0,1),c(0,0)))) * 3
#' pl3 = sf::st_polygon(list(rbind(c(1,0),c(2,0),c(2,1),c(1,0)))) * 3
#' pl4 = sf::st_polygon(list(rbind(c(1,0),c(1,1),c(2,1),c(1,0)))) * 3
#' s = sf::st_sf(group = c("a","a","b","b"), geom = sf::st_sfc(pl1, pl2, pl3,pl4))
#' prepare_nodes(s)
prepare_nodes <- function(x, vars) {
require(sf)
require(dplyr)

pt_centroid <- x %>%
dplyr::group_by({{vars}})%>%
dplyr::summarise() %>%
sf::st_centroid()

pts <- sf::st_coordinates(pt_centroid)

nodes <- cbind(pts, pt_centroid)

return(nodes)
}

31 changes: 31 additions & 0 deletions data-raw/arabesque_data_preparation.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

library(dplyr)
library(readr)
library(dplyr)
library(sf)
library(vroom)
library(here)
#remotes::install_github("jimhester/archive")
Expand Down Expand Up @@ -57,3 +59,32 @@ filtered_data %>%
count = n()) %>%
readr::write_csv(file = here::here("data", "OD_weighted_data.csv"))

# Read Weighted data
OD_weighted_data <- readr::read_csv(
file = here::here("data", "OD_weighted_data.csv"),
col_types = readr::cols(.default = "c", flow = "d",count = "d"))

# Departement flows Weighted data
OD_weighted_data %>%
dplyr::mutate(
CODE_DEP = substr(COMMUNE, 1,2),
DEP_ETUD = substr(DCETUF, 1,2)) %>%
dplyr::group_by(CODE_DEP, DEP_ETUD, CSM, SEXE, REGION, REGETUD, METRODOM, ILETUD) %>%
dplyr::summarise(flow=sum(flow), count = sum(count)) %>%
readr::write_csv(file = here::here("data", "OD_departements_weighted_data.csv"))

# EPCI flows Weighted data
## get EPCI code for each commune
communes <- sf::read_sf(
here::here("data-raw/COMMUNE_CARTO.shp")) %>%
sf::st_drop_geometry() %>%
dplyr::select(INSEE_COM, CODE_EPCI)

OD_weighted_data %>% dplyr::left_join(communes, by = c("COMMUNE" = "INSEE_COM")) %>%
dplyr::rename(EPCI_ORIGIN = CODE_EPCI) %>%
dplyr::left_join(communes, by = c("DCETUF" = "INSEE_COM")) %>%
dplyr::rename(EPCI_DEST = CODE_EPCI) %>%
dplyr::group_by(EPCI_ORIGIN, EPCI_DEST, CSM, SEXE, REGION, REGETUD, METRODOM, ILETUD) %>%
dplyr::summarise(flow=sum(flow), count = sum(count)) %>%
readr::write_csv(file = here::here("data", "OD_epci_weighted_data.csv"))

25 changes: 25 additions & 0 deletions data-raw/geodata_preparation.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,28 @@ nodes %>%
# Export to geojson
nodes %>%
sf::st_write(here::here("data", "nodes_coordinates.geojson"))


## Prepare geodata for Departements scale
dep <- arabesqueFOSS4G2021::prepare_nodes(communes, INSEE_DEP)

# Export to CSV
dep %>%
sf::st_drop_geometry() %>%
readr::write_csv(file = here::here("data", "departements_nodes_coordinates.csv"))

# Export to geojson
dep %>%
sf::st_write(here::here("data", "departements_nodes_coordinates.geojson"))

## Prepare geodata for EPCI scale
epci <- arabesqueFOSS4G2021::prepare_nodes(communes, CODE_EPCI)

# Export to CSV
epci %>%
sf::st_drop_geometry() %>%
readr::write_csv(file = here::here("data", "epci_nodes_coordinates.csv"))

# Export to geojson
epci %>%
sf::st_write(here::here("data", "epci_nodes_coordinates.geojson"))
Loading