I've been trying to build a graph from a projected (EPSG 27700) clean (no pseudo-nodes) street network. I followed the tutorial here presented employing the QGIS 3.0 functions; now the network analysis tutorial is included in the analysis module of PyQgis.
This is the code:
layer = qgis.utils.iface.mapCanvas().currentLayer() # undirected graph and distance strategy graphDirector = QgsVectorLayerDirector(layer, -1, '', '', '', 3) strategy = QgsNetworkDistanceStrategy() graphDirector.addStrategy(strategy) startPoint = QgsPointXY(531389.8,181641.4) builder = QgsGraphBuilder(lay.sourceCrs(), topologyTolerance = 0.0) tiedPoints = graphDirector.makeGraph(builder, [startPoint]) graph = builder.graph() graph.vertexCount() graph.edgeCount()
The graph is apparently composed by 15358 nodes, even though I was expecting 3799. The edgeCount results in 0 edges instead. I also tried to computed the shortest path and no path was existing between different nodes (as expected, due to the abscence of edges).
Essentially, my question is: what I am doing wrong? Moreover, is the part where I tie the points to the network crucial for creating the graph? I don't understand why that would be relevant for obtaining the graph representation.