import osmnx as ox
= ox.geocode_to_gdf(
bounds_gdf "R1536593", # OSM relation ID
=True,
by_osmid
)# optionally use to_crs() to project to a target CRS
# returns a geoDataFrame - union for the geom
= bounds_gdf.union_all()
bounds_geom bounds_geom
Networks for OSM Boundaries
If you want to download a street network for a specific OSM boundary then you can use osmnx
to download the boundary. The boundary can then be passed to cityseer
for generating a network.
Download Boundary
Download the boundary. Go to OSM and select the relation ID for the boundary that you’d like to download and pass it to ox.geocode_to_gdf()
.
Tip
You can optionally project to a required CRS by using geopandas
to_crs()
methodo before taking the union. This is generally recommended if you want to apply a buffer to the geometry (assuming a unit such as metres).
Buffer and Simplify
Buffer and simplify depending on preferences. Make sure your distances correspond to the unit of the current CRS!
# buffer if wanted
= bounds_geom.buffer(0.01) # WGS - 4326
bounds_geom # some simplification is recommended
# otherwise the request to the underlying API used by io.osm_graph_from_poly()
# might complain that the boundary description is too long
= bounds_geom.simplify(
bounds_geom 0.001 # WGS - 4326
# here the CRS unit is degrees hence the small number
) bounds_geom
Generate Network
Now you can pass the boundary to cityseer
to download and create the network.
from cityseer.tools import io, plot
= io.osm_graph_from_poly(
G_nx
bounds_geom,# 4326 by default - use projected CRS instead if you projected your GDF
=4326,
poly_crs_code=False, # set to True for automatic simplification
simplify
)=True) plot.plot_nx(G_nx, plot_geoms
INFO:cityseer.tools.io:Converting networkX graph from EPSG code 4326 to EPSG code 32631.
INFO:cityseer.tools.io:Processing node x, y coordinates.
0%| | 0/29883 [00:00<?, ?it/s]100%|██████████| 29883/29883 [00:00<00:00, 654204.50it/s]
INFO:cityseer.tools.io:Processing edge geom coordinates, if present.
0%| | 0/32725 [00:00<?, ?it/s]100%|██████████| 32725/32725 [00:00<00:00, 1254591.64it/s]
INFO:cityseer.tools.graphs:Generating interpolated edge geometries.
0%| | 0/32725 [00:00<?, ?it/s] 22%|██▏ | 7072/32725 [00:00<00:00, 70711.81it/s] 43%|████▎ | 14144/32725 [00:00<00:00, 69364.52it/s] 65%|██████▌ | 21279/32725 [00:00<00:00, 70259.37it/s] 87%|████████▋ | 28313/32725 [00:00<00:00, 70288.79it/s]100%|██████████| 32725/32725 [00:00<00:00, 70117.40it/s]
INFO:cityseer.tools.graphs:Removing filler nodes.
0%| | 0/29883 [00:00<?, ?it/s] 3%|▎ | 936/29883 [00:00<00:03, 9332.66it/s] 6%|▋ | 1870/29883 [00:00<00:04, 6707.82it/s] 9%|▉ | 2640/29883 [00:00<00:03, 7075.49it/s] 11%|█▏ | 3379/29883 [00:00<00:04, 6340.93it/s] 14%|█▎ | 4061/29883 [00:00<00:03, 6487.30it/s] 16%|█▌ | 4759/29883 [00:00<00:03, 6625.95it/s] 18%|█▊ | 5443/29883 [00:00<00:03, 6687.02it/s] 21%|██▏ | 6365/29883 [00:00<00:03, 7444.78it/s] 24%|██▍ | 7121/29883 [00:01<00:03, 6693.97it/s] 26%|██▌ | 7830/29883 [00:01<00:03, 6784.88it/s] 29%|██▉ | 8607/29883 [00:01<00:03, 7044.61it/s] 32%|███▏ | 9433/29883 [00:01<00:02, 7392.34it/s] 35%|███▍ | 10317/29883 [00:01<00:02, 7809.12it/s] 38%|███▊ | 11269/29883 [00:01<00:02, 8307.06it/s] 42%|████▏ | 12565/29883 [00:01<00:01, 9589.65it/s] 45%|████▌ | 13529/29883 [00:01<00:01, 9556.72it/s] 48%|████▊ | 14489/29883 [00:01<00:01, 9363.39it/s] 53%|█████▎ | 15959/29883 [00:01<00:01, 10896.25it/s] 57%|█████▋ | 17146/29883 [00:02<00:01, 11146.84it/s] 62%|██████▏ | 18448/29883 [00:02<00:00, 11685.58it/s] 67%|██████▋ | 19876/29883 [00:02<00:00, 12438.35it/s] 71%|███████ | 21189/29883 [00:02<00:00, 12603.84it/s] 75%|███████▌ | 22560/29883 [00:02<00:00, 12903.18it/s] 80%|███████▉ | 23853/29883 [00:02<00:00, 12665.15it/s] 85%|████████▍ | 25393/29883 [00:02<00:00, 13451.21it/s] 89%|████████▉ | 26741/29883 [00:02<00:00, 12934.16it/s] 94%|█████████▍| 28041/29883 [00:02<00:00, 12053.39it/s] 99%|█████████▉| 29577/29883 [00:03<00:00, 12962.33it/s]100%|██████████| 29883/29883 [00:03<00:00, 9819.00it/s]
INFO:cityseer.tools.plot:Preparing graph nodes
INFO:cityseer.tools.plot:Preparing graph edges
0%| | 0/11428 [00:00<?, ?it/s] 19%|█▊ | 2117/11428 [00:00<00:00, 21161.64it/s] 37%|███▋ | 4234/11428 [00:00<00:00, 15530.76it/s] 51%|█████▏ | 5876/11428 [00:00<00:00, 12076.55it/s] 63%|██████▎ | 7180/11428 [00:00<00:00, 10306.80it/s] 72%|███████▏ | 8276/11428 [00:00<00:00, 9002.74it/s] 81%|████████ | 9219/11428 [00:00<00:00, 7971.30it/s] 88%|████████▊ | 10043/11428 [00:01<00:00, 7227.47it/s] 94%|█████████▍| 10780/11428 [00:01<00:00, 6429.43it/s]100%|██████████| 11428/11428 [00:01<00:00, 8262.76it/s]