Network Preparation
The below examples illustrate how to create cityseer compatible networkx graphs from various data sources, including OpenStreetMap (OSM) data and geopandas GeoDataFrames. These workflows will automatically prepare the network for you, and this should be sufficient for the great majority of cases.
If you specifically wish to prepare the network manually:
- 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 associated. Note that if adding transportation networks, this is done at a later step in way that retains directionality for transportation networks.- The network must have a coordinate reference system (CRS) associated with it. If you are converting from
osmnxorgeopandas, then this is done automatically. Otherwise, you can define this by setting acrsparameter on the graph to a valid CRS code; for exampleG.graph['crs'] = 27700.
The network nodes require x and y attributes storing the coordinates of the node in a projected coordinate system. You can also optionally add the following two attributes:
- An optional
liveattribute indicating whether to compute metrics for a given node (live=True) else whether to skip calculations (live=False). The latter case is for when you wish to include a buffered region of the network to prevent edge roll-off effects. - An optional
weightattribute indicating the weight of the node.cityseerwill by default assumeweight=1when calculating centrality metrics. Advanced users may in some cases wish to use theweightattribute to indicate the relative importance of a node in the network.
For edges, cityseer network representations contain a geom attribute which stores a shapely LineString geometry of the edge. cityseer will use the geom attribute to calculate properties of the network such as the lengths of streets and their angular deviations. For the best to 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 of the streets. Curvatures and turns within a street segment should be represented within the same LineString geometry rather than adding additional nodes and segments, which would otherwise distort the outcomes of 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.