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.

Tip

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:

Network nodes require x and y attributes storing the coordinates in a projected coordinate system. Two optional attributes are also supported:

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.

Notebook

OSM network from a buffered coordinate

Use a buffered point to create a networkx graph from OSM.

Notebook

OSM network from a boundary file

Use a custom boundary file to create a networkx graph from OSM.

Notebook

OSM network from a relation id

Use an OSM relation id to create a networkx graph from OSM.

Notebook

Custom network from a streets dataset

Use geopandas to open a street network file and convert it to a networkx graph.

Notebook

Convert a network from osmnx

Convert a network from osmnx to a cityseer compatible networkx graph.

Notebook

Convert a network from momepy

Convert a network from momepy to a cityseer compatible networkx graph.

Notebook

Saving a network to a file

Save a networkx graph to a file.

Notebook

Dual graph from a primal graph

Create a dual graph representation from a primal graph.

Notebook

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.

Notebook