Network Preparation
The following examples illustrate how to create cityseer compatible networkx graphs from various data sources, including OpenStreetMap (OSM) data and geopandas GeoDataFrames. These workflows automatically prepare the network for you and should be sufficient for the great majority of cases.
New to geopandas or coordinate reference systems? See the GeoPandas chapter of the Python 101 section for background. For definitions of terms like “primal graph” and “dual graph”, see the Glossary.
If you wish to prepare the network manually, note the following requirements:
- The network must be a
networkxMultiGraphobject. This is the default forcityseer, but if you are using another package such asosmnx, you may need to convert the graph to aMultiGraphfirst. cityseeris focused on pedestrian networks, which do not ordinarily have directionality. If adding transportation networks, this is done at a later step in a way that retains directionality for those networks.- The network must have a coordinate reference system (CRS) associated with it. When converting from
osmnxorgeopandas, this is handled automatically. Otherwise, set acrsparameter on the graph to a valid CRS code, e.g.G.graph['crs'] = 27700.
Network nodes require x and y attributes storing the coordinates in a projected coordinate system. Two optional attributes are also supported:
live: indicates whether to compute metrics for a given node (live=True) or skip calculations (live=False). Set nodes tolive=Falsein buffered regions of the network to prevent edge rolloff effects (see the Edge Rolloff section).weight: indicates the weight of the node.cityseerdefaults toweight=1when calculating centrality metrics. Advanced users may use this to indicate the relative importance of a node.
For edges, cityseer stores a geom attribute containing a shapely LineString geometry. This is used to calculate properties such as street lengths and angular deviations. For best results, the topology of the graph should reflect the real-world topology of the street network and should not be conflated with the geometric representation. Curvatures and turns within a street segment should be represented within the same LineString geometry rather than as additional nodes and segments, which would distort centrality measures.
The first several examples use the osm_graph_from_poly function available from the cityseer package’s io module. This is a versatile function for generating networks from OSM data.
OSM network from a bounding box
Use a bounding box to create a networkx graph from OpenStreetMap data. See this example for some use cases including how to use specific Coordinate Reference Systems.
OSM network from a buffered coordinate
Use a buffered point to create a networkx graph from OSM.
OSM network from a boundary file
Use a custom boundary file to create a networkx graph from OSM.
OSM network from a relation id
Use an OSM relation id to create a networkx graph from OSM.
Custom network from a streets dataset
Use geopandas to open a street network file and convert it to a networkx graph.
Convert a network from osmnx
Convert a network from osmnx to a cityseer compatible networkx graph.
Convert a network from momepy
Convert a network from momepy to a cityseer compatible networkx graph.
Saving a network to a file
Save a networkx graph to a file.
Dual graph from a primal graph
Create a dual graph representation from a primal graph.
Custom network simplification
For purposes of network analysis, good sources of street network data, such as the Ordnance Survey’s OS Open Roads, typically have two distinguishing characteristics:
- The network has been simplified to its essential structure: i.e. unnecessarily complex representations of intersections, on-ramps, divided roadways, etc., have been reduced to a simpler representation concurring more readily with the core topological structure of street networks.
- The topology of the network is kept distinct from the geometry of the streets. Often-times, as can be seen with Open Street Map, additional nodes are added to streets to represent geometric twists and turns along a roadway. These additional nodes cause topological distortions that impact network centrality measures.
When a high-quality source is available, it may be best not to attempt additional clean-up unless there is a particular rationale for doing so. On the other hand, cleaning and simplification is recommended when working with Open Street Map data. cityseer has an automated cleaning routine for OSM data, but it is also possible to manually configure network simplification steps and parameters as shown in the following notebook.