Creating Graphs

Creating Graphs

This section explains the basic built-in functionalities pertaining to urban graph analysis.

The two principal elements of an urban graph are vertices and edges. Generally, a vertex corresponds to the intersection of mutiple edges. In Urban Planning, vertices correspond to intersection points, and edges correspond to linear road data.

There is an extensive collection of scholarly articles pertaining to graph theory with concrete GIS applications:

  • J.K.Tinkler (1977) [1]
  • A.G.Bunn, D.L.Urban & T.H.Keitt (2000) [2]
  • E.Dobrzyńska & M.Dobrzyński (2016) [3]

Downloading Data

A real urban graph is derived from road data. It follows the existing street pattern to fit with the physical reality of the terrain.
This type of data is usually found online, in open access from official sources or from open-source.

T4QG relies on metric Cartesian coordinates for a few of its functionalities. Open the .proj file connected to your data and check in what type it is currently projected.

If your original data is in lat/lon, you can find the metric alternative on

Open your data a first time, and save it under the correct metric projection (SCR). Check your new .proj file to confirm changes.

>>> roads = QgsVectorLayer('~/roads.shp', 'roads', 'ogr')

>>> QgsMapLayerRegistry.instance().addMapLayer(roads)

You may find more information concerning Loading Vectorial Datasets in Qgis at the official documentation page.

Extracting Nodes

To extract intersection nodes from lineStrings:

Parameters: layer (QgsVectorLayer) – a LineString vector layer.
Returns: A Vector Layer wherein points are created at each intersection of more than two LineStrings of the input layer.

An alternative method for creating an urban graph may also be built using the surrounding urban morphology.
This process, called skeletonization, requires a layer of polygons representing the built form.
To learn how to build the skeleton of the built environment, head to the page on Creating Geometries.

The lineString layer returned by STSkeletonizeTheVoid() needs to be joined using STToRoadsSections() to extract the intersections correctly.

To clean the linestring data before processing :

Parameters: layer (QgsVectorLayer) – a LineString vector layer.
Returns: A Vector Layer wherein the input linestrings are joined when they intersect a single other linestring, and split at the intersection of more than two linestrings.
>>> roads = STSkeletonizeTheVoid(buildings_ExtRing).execute()

>>> nodes = STToRoadsSectionsNodes(roads).execute()

>>> QgsMapLayerRegistry.instance().addMapLayer(nodes)

Because the lineStrings are not joined, intersections are found at each segment extremity.

>>> roads = STSkeletonizeTheVoid(buildings_ExtRing).execute()

>>> segmentNodes = STToRoadsSections(roads).execute()

>>> nodes = STToRoadsSectionsNodes(segmentNodes).execute()

>>> QgsMapLayerRegistry.instance().addMapLayer(nodes)

Joining lineString segments before intersection extraction


Vous aimerez aussi...

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.