diff --git a/R/aggregate.R b/R/aggregate.R index ec5c5fa..fa7b57d 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -121,6 +121,8 @@ od_disaggregate = function(od, #' od_aggregated = od_data_df[1:2, ] #' aggzones = od::od_data_zones_min #' subzones = od_data_zones_small +#' plot(aggzones$geometry) +#' plot(subzones$geometry, add = TRUE) #' od = od_disaggregate(od_aggregated, aggzones, subzones) #' od_agg = od_aggregate(od, aggzones) #' names(od_agg)[1:(ncol(od_agg) - 1)] = names(od_aggregated) diff --git a/data-raw/od_data_leeds.R b/data-raw/od_data_leeds.R index 8e90ceb..25b9b84 100644 --- a/data-raw/od_data_leeds.R +++ b/data-raw/od_data_leeds.R @@ -6,28 +6,47 @@ library(stplanr) od = pct::get_od() centroids_ew_all = pct::get_centroids_ew() # todo: add centroids dataset based on this +zones_leeds = ukboundaries::msoa2011_lds +centroids_leeds = centroids_ew_all %>% + filter(msoa11cd %in% zones_leeds$geo_code) od_data_df_medium = od %>% - filter(geo_code1 %in% od_data_zones$msoa11cd) %>% - filter(geo_code2 %in% od_data_zones$msoa11cd) %>% - filter(geo_code1 != geo_code2) %>% + filter(geo_code1 %in% centroids_leeds$msoa11cd) %>% + filter(geo_code2 %in% centroids_leeds$msoa11cd) %>% + # filter(geo_code1 != geo_code2) %>% select(geo_code1, geo_code2, all, train, bus, taxi, car_driver, car_passenger, bicycle, foot) od_data_df_medium class(od_data_df_medium) -class(od_data_df_medium) = "data.frame" +od_data_df_medium = as.data.frame(od_data_df_medium) class(od_data_df_medium) -usethis::use_data(od_data_df_medium) +file.size("data/od_data_df_medium.rda") / 1e6 +usethis::use_data(od_data_df_medium, overwrite = TRUE) +file.size("data/od_data_df_medium.rda") / 1e6 od_data_df = od_data_df_medium %>% select(geo_code1, geo_code2, all, train, bus, taxi, car_driver, car_passenger, bicycle, foot) %>% - top_n(n = 6, bicycle) %>% + top_n(n = 4, foot) %>% + as.data.frame(stringsAsFactors = FALSE) + + +od_data_df2 = od_data_df_medium %>% + filter(geo_code2 != "E02006875") %>% + filter(geo_code2 != geo_code1) %>% + select(geo_code1, geo_code2, all, train, bus, taxi, car_driver, car_passenger, bicycle, foot) %>% + top_n(n = 2, foot) %>% as.data.frame(stringsAsFactors = FALSE) +od_data_df3 = od_data_df_medium %>% + filter(geo_code1 == "E02002392" & geo_code2 == "E02006875") %>% + select(geo_code1, geo_code2, all, train, bus, taxi, car_driver, car_passenger, bicycle, foot) %>% + as.data.frame(stringsAsFactors = FALSE) + +od_data_df = rbind(od_data_df, od_data_df2, od_data_df3) od_data_df -usethis::use_data(od_data_df) +usethis::use_data(od_data_df, overwrite = TRUE) zones_leeds = ukboundaries::msoa2011_lds class(zones_leeds) @@ -99,16 +118,17 @@ plot(od_agg) # get network for leeds --------------------------------------------------- library(geofabrik) -route_network_west_yorkshire = get_geofabrik("west yorkshire") +route_network_west_yorkshire = osmextract::oe_get("west yorkshire") route_network_leeds = route_network_west_yorkshire[od_data_zones, ] summary(as.factor(route_network_leeds$highway)) # could save this at some point: od_data_zones_min = od_data_zones %>% filter(geo_code %in% c(od_data_df$geo_code1, od_data_df$geo_code2)) +mapview::mapview(od_data_zones_min) -od_data_region_1km = stplanr::geo_buffer(od_data_zones_min, dist = 500) -route_network_min = route_network_west_yorkshire[od_data_region_1km, ] +od_data_region_buffer = stplanr::geo_buffer(od_data_zones_min, dist = 100) +route_network_min = route_network_west_yorkshire[od_data_region_buffer, , op = sf::st_within] mapview::mapview(route_network_min) od_data_network = route_network_min %>% filter(str_detect(highway, "cycleway|primary|second|tert|trunk")) @@ -116,8 +136,8 @@ od_data_network = route_network_min %>% mapview::mapview(od_data_network) + mapview::mapview(od_data_zones_min) -usethis::use_data(od_data_network) -usethis::use_data(od_data_zones_min) +usethis::use_data(od_data_network, overwrite = TRUE) +usethis::use_data(od_data_zones_min, overwrite = TRUE) # get od_aggregate working ------------------------------------------------ @@ -131,8 +151,7 @@ od_data_zones_small = zones_lsoa_leeds %>% filter(geo_code %in% centroids_in_zones_min$geo_code) %>% select(geo_code, all, foot, bicycle) mapview::mapview(od_data_zones_small) -usethis::use_data(od_data_zones_small) - +usethis::use_data(od_data_zones_small, overwrite = TRUE) # get buildings for Leeds ------------------------------------------------- diff --git a/data/od_data_buildings.rda b/data/od_data_buildings.rda index f6ab92e..009feda 100644 Binary files a/data/od_data_buildings.rda and b/data/od_data_buildings.rda differ diff --git a/data/od_data_df.rda b/data/od_data_df.rda index 24d2d79..27439a4 100644 Binary files a/data/od_data_df.rda and b/data/od_data_df.rda differ diff --git a/data/od_data_df_medium.rda b/data/od_data_df_medium.rda index 7864263..7c7024b 100644 Binary files a/data/od_data_df_medium.rda and b/data/od_data_df_medium.rda differ diff --git a/data/od_data_network.rda b/data/od_data_network.rda index e208768..2d2788b 100644 Binary files a/data/od_data_network.rda and b/data/od_data_network.rda differ diff --git a/data/od_data_zones_min.rda b/data/od_data_zones_min.rda index a15b93d..6b9bbd5 100644 Binary files a/data/od_data_zones_min.rda and b/data/od_data_zones_min.rda differ diff --git a/data/od_data_zones_small.rda b/data/od_data_zones_small.rda index 09e852a..e041080 100644 Binary files a/data/od_data_zones_small.rda and b/data/od_data_zones_small.rda differ diff --git a/man/od_aggregate.Rd b/man/od_aggregate.Rd index 65870e9..ab485b9 100644 --- a/man/od_aggregate.Rd +++ b/man/od_aggregate.Rd @@ -28,6 +28,8 @@ An alias for the function is \code{od_group()}. od_aggregated = od_data_df[1:2, ] aggzones = od::od_data_zones_min subzones = od_data_zones_small +plot(aggzones$geometry) +plot(subzones$geometry, add = TRUE) od = od_disaggregate(od_aggregated, aggzones, subzones) od_agg = od_aggregate(od, aggzones) names(od_agg)[1:(ncol(od_agg) - 1)] = names(od_aggregated)