That the notebook is being run from a cloned cityseer-api repository.
That the above dataset has been downloaded to temp/os_open_roads/oproad_gb.gpkg as a relative path. If running this notebook directly from within a clone of the cityseer-api repo, then this equates to the cityseer-api/temp/os_open_roads/oproad_gb.gpkg path. Please edit the paths and path setup in this cell if you are using different directories.
from __future__ import annotationsfrom pathlib import Pathrepo_path = Path.cwd()ifstr(repo_path).endswith("continuity"): repo_path = Path.cwd() /"../.."ifnotstr(repo_path.resolve()).endswith("cityseer-examples"):raiseValueError("Please check your notebook working directory relative to your project and data paths." )open_roads_path = Path(repo_path /"temp/os_open_roads/oproad_gb.gpkg")print("data path:", open_roads_path)print("path exists:", open_roads_path.exists())
data path: /Users/gareth/dev/benchmark-urbanism/cityseer-examples/examples/continuity/../../temp/os_open_roads/oproad_gb.gpkg
path exists: True
Extents
Instead of loading the entire dataset, we’ll use a bounding box to only load an area of interest.
from pyproj import Transformerfrom shapely import geometryfrom cityseer.tools import io# create graph - only UK locations will work for OS Open Roads data# stratford-upon-avon# lng, lat, buffer_dist, plot_buffer = -1.7063649924889566, 52.19277374082795, 2500, 2000# londonlng, lat, buffer_dist, plot_buffer = (-0.13039709427587876,51.516434828344366,6000,5000,)# transform from WGS to BNGtransformer = Transformer.from_crs("EPSG:4326", "EPSG:27700")easting, northing = transformer.transform(lat, lng)# calculate bbox relative to centroidcentroid = geometry.Point(easting, northing)target_bbox: tuple[float, float, float, float] = centroid.buffer(buffer_dist).bounds # type: ignoreplot_bbox: tuple[float, float, float, float] = centroid.buffer(plot_buffer).bounds # type: ignore
Load
We can now load the OS Open Roads dataset
# load OS Open Roads data from downloaded geopackageG_open = io.nx_from_open_roads(open_roads_path, target_bbox=target_bbox)
INFO:cityseer.tools.io:Nodes: 24778
INFO:cityseer.tools.io:Edges: 32723
INFO:cityseer.tools.io:Dropped 463 edges where not both start and end nodes were present.
INFO:cityseer.tools.io:Running basic graph cleaning
INFO:cityseer.tools.graphs:Removing filler nodes.
100%|██████████| 24778/24778 [00:00<00:00, 33240.53it/s]
INFO:cityseer.tools.graphs:Merging parallel edges within buffer of 10.
100%|██████████| 30681/30681 [00:00<00:00, 50838.55it/s]
Observe continuity metrics
This step runs the continuity analysis using the specified heuristic.
import matplotlib.pyplot as pltfrom cityseer.tools import io, plotfrom cityseer.metrics import observe# methods can be "names", "routes", "highways"print("Continuity by street names")G_cont, NamesContReport = observe.street_continuity(G_open, method="names")NamesContReport.report_by_count(n_items=5)NamesContReport.report_by_length(n_items=5)print("Continuity by route numbers")G_cont, RoutesContReport = observe.street_continuity(G_cont, method="routes")RoutesContReport.report_by_count(n_items=5)RoutesContReport.report_by_length(n_items=5)print("Continuity by highway types")G_cont, HwyContReport = observe.street_continuity(G_cont, method="highways")HwyContReport.report_by_count(n_items=5)HwyContReport.report_by_length(n_items=5)print("Continuity by overlapping routes and names types")G_cont, HybridContReport = observe.hybrid_street_continuity(G_cont)HybridContReport.report_by_count(n_items=5)HybridContReport.report_by_length(n_items=5)
Continuity by street names
INFO:cityseer.metrics.observe:Calculating metrics for names.
100%|██████████| 30609/30609 [00:00<00:00, 31274.62it/s]
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street counts.
INFO:cityseer.metrics.observe:Count: 82 - finchley road
INFO:cityseer.metrics.observe:Count: 62 - harrow road
INFO:cityseer.metrics.observe:Count: 58 - old kent road
INFO:cityseer.metrics.observe:Count: 57 - king's road
INFO:cityseer.metrics.observe:Count: 46 - clapham road
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street lengths.
INFO:cityseer.metrics.observe:Length: 5.4km - harrow road
INFO:cityseer.metrics.observe:Length: 5.34km - finchley road
INFO:cityseer.metrics.observe:Length: 4.48km - outer circle
INFO:cityseer.metrics.observe:Length: 3.7km - westway
INFO:cityseer.metrics.observe:Length: 3.28km - old kent road
Continuity by route numbers
INFO:cityseer.metrics.observe:Calculating metrics for routes.
100%|██████████| 30609/30609 [00:00<00:00, 109845.11it/s]
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street counts.
INFO:cityseer.metrics.observe:Count: 142 - a1
INFO:cityseer.metrics.observe:Count: 135 - a10
INFO:cityseer.metrics.observe:Count: 129 - a41
INFO:cityseer.metrics.observe:Count: 128 - a107
INFO:cityseer.metrics.observe:Count: 116 - a5
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street lengths.
INFO:cityseer.metrics.observe:Length: 9.1km - a41
INFO:cityseer.metrics.observe:Length: 8.1km - a1
INFO:cityseer.metrics.observe:Length: 7.96km - a10
INFO:cityseer.metrics.observe:Length: 7.76km - a3220
INFO:cityseer.metrics.observe:Length: 7.12km - a107
Continuity by highway types
INFO:cityseer.metrics.observe:Calculating metrics for highways.
100%|██████████| 30609/30609 [00:00<00:00, 156124.61it/s]
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street counts.
INFO:cityseer.metrics.observe:Count: 5056 - a road
INFO:cityseer.metrics.observe:Count: 2510 - minor road
INFO:cityseer.metrics.observe:Count: 1711 - primary road
INFO:cityseer.metrics.observe:Count: 1487 - b road
INFO:cityseer.metrics.observe:Count: 463 - secondary access road
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street lengths.
INFO:cityseer.metrics.observe:Length: 336.17km - a road
INFO:cityseer.metrics.observe:Length: 181.0km - minor road
INFO:cityseer.metrics.observe:Length: 116.88km - primary road
INFO:cityseer.metrics.observe:Length: 105.99km - b road
INFO:cityseer.metrics.observe:Length: 33.74km - secondary access road
Continuity by overlapping routes and names types
INFO:cityseer.metrics.observe:Calculating metrics for routes.
100%|██████████| 30609/30609 [00:00<00:00, 118874.56it/s]
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street counts.
INFO:cityseer.metrics.observe:Count: 230 - a1
INFO:cityseer.metrics.observe:Count: 204 - a41
INFO:cityseer.metrics.observe:Count: 162 - a40
INFO:cityseer.metrics.observe:Count: 162 - a10
INFO:cityseer.metrics.observe:Count: 154 - a107
INFO:cityseer.metrics.observe:Reporting top 5 continuity observations by street lengths.
INFO:cityseer.metrics.observe:Length: 14.76km - a41
INFO:cityseer.metrics.observe:Length: 13.1km - a1
INFO:cityseer.metrics.observe:Length: 12.38km - a40
INFO:cityseer.metrics.observe:Length: 10.98km - a3220
INFO:cityseer.metrics.observe:Length: 9.46km - a10