Skip to content

Commit

Permalink
Start another zone-to-point example. #27
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 18, 2023
1 parent 28ec65a commit ab9a7a4
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ examples/*/output/*
!examples/york/input/destinations.geojson
!examples/york/input/zones.geojson
!examples/york/input/od.csv

!examples/liverpool/input/destinations.geojson
5 changes: 5 additions & 0 deletions aggregate_routes/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ impl Timer {

impl Drop for Timer {
fn drop(&mut self) {
if let Some(current) = self.stack.last() {
println!("WARNING: Dropping timer during block {}. Probably crashing.", current.name);
return;
}

assert!(self.stack.is_empty());
// TODO Formatted like a flamegraph? Emphasize the proportionally expensive sections
println!("\n\n\nSummary:");
Expand Down
20 changes: 20 additions & 0 deletions examples/liverpool/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"requests": {
"Generate": {
"pattern": {
"ZoneToPoint": {
"zones_path": "zones.geojson",
"destinations_path": "destinations.geojson",
"csv_path": "od.csv"
}
}
}
},
"routing": {
"FastPaths": {
"cost": "Distance"
}
},
"uptake": "Identity",
"lts": "BikeOttawa"
}
18 changes: 18 additions & 0 deletions examples/liverpool/input/destinations.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "hospital"
},
"geometry": {
"coordinates": [
-2.897064035677346,
53.41852905901993
],
"type": "Point"
}
}
]
}
79 changes: 79 additions & 0 deletions examples/liverpool/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import csv
import json
import sys

sys.path.append("..")

from utils import *

run(["mkdir", "-p", "input"])

download(
url="https://download.geofabrik.de/europe/great-britain/england/merseyside-latest.osm.pbf",
outputFilename="input/input.osm.pbf",
)

extractCentroids(pbfInput="input/input.osm.pbf", geojsonOutput="input/origins.geojson")

# You have to manually download the Geopackage from https://geoportal.statistics.gov.uk/datasets/ons::output-areas-dec-2011-boundaries-ew-bgc/explore and put Output_Areas_Dec_2011_Boundaries_EW_BGC_2022_7971430631129549274.gpkg in input/

# First convert the CRS
run(
[
"ogr2ogr" "-f",
"GeoJSON",
"input/all_oas.geojson",
"input/Output_Areas_Dec_2011_Boundaries_EW_BGC_2022_7971430631129549274.gpkg",
"-t_srs",
"EPSG:4326",
]
)
# Then clip (thanks to bboxfinder.com)
run(
[
"ogr2ogr",
"-f",
"GeoJSON",
"input/clipped_oas.geojson",
"-clipsrc",
"-3.290405",
"53.291900",
"-2.532349",
"53.512960",
"input/all_oas.geojson",
]
)

# Then manually fix properties
with open("input/clipped_oas.geojson") as f1:
gj = json.load(f1)
for f in gj["features"]:
props = {"name": f["properties"]["OA11CD"]}
f["properties"] = props

with open("input/zones.geojson", "w") as f2:
f2.write(json.dumps(gj))


# To figure out the WPZ containing Alder Hey Hospital, go to https://geoportal.statistics.gov.uk/datasets/ons::workplace-zones-december-2011-full-clipped-boundaries-in-england-and-wales-1/explore, find the hospital by zooming in or using search, then copy the wz11cd property.
target_wpz = "E33003019"

# You have to manually download WF01AEW_oa from https://wicid.ukdataservice.ac.uk/flowdata/cider/wicid/downloads.php, unzip, and put wf01aew_oa_v1.csv in input/
# TODO Or in-place
with open("input/wf01aew_oa_v1.csv") as f1:
with open("input/od.csv", "w") as f2:
writer = csv.DictWriter(f2, fieldnames=["from", "to", "count"])
writer.writeheader()

for row in csv.reader(f1):
if row[1] != target_wpz:
continue

writer.writerow(
{
"from": row[0],
"to": "hospital",
# This dataset doesn't break down by mode
"count": int(row[2]),
}
)

0 comments on commit ab9a7a4

Please sign in to comment.