0

I would like to create a map of isolines for a given country.

I fetched road map using OSMNX:

cf = '["highway"~"motorway|motorway_link|trunk|primary|secondary"]'
G = ox.graph_from_place('Venezuela', network_type='drive', custom_filter=cf)
# project the graph to UTM
G_projected = ox.project_graph(G)

Then I created a subgraph of all nodes within given radius from starting point (lat, long):

node = ox.get_nearest_node(G, (8.284904228184445, -62.72239713960212))
subgraph = nx.ego_graph(G_projected, node, radius=10000, distance="length")

Resulting subgraph contains only 1 node (no matter what radius is used)

list(subgraph.nodes())
[5098062996]

List of neighbours is empty:

list(G_projected.neighbors(5098062996))

But for graph G (before projection was conducted):

list(G.neighbors(5098062996))
[5098062995]

The CRS of the starting point is EPSG:4326, WGS 84, project_graph projects it to UTM zone in which the graph’s centroid lies. But what is the resulting CRS, I guess that in this case, it is also WGS 84 because there is no difference in terms of geometry between results for G and G_projected. Is it necessary to project G to UTM each time, and what about the disconnected nodes, is it the result of projection operation?

Following methods turned out to be not very helpful in identifying the problem:

list(nx.isolates(G_projected))
list(nx.isolates(G))

Both return empty list. Which mean that every node has neighbours (is connected?)

Given node is also in the list of connected components of a graph:

5098062996 in list(nx.connected_components(G_projected.to_undirected()))[0]
True

We have contradicted information, the node is connected but has no neighbours and resulting subgraph contains only the starting point.

I have to emphasise that for different nodes everything work fine, I encountered issues only with that particular node. For G without projection it works. I only used the projection because I saw it in notebook examples at OSMNX github page.

I should simply do not use the projection or I should use it and there is some other issue with the graph connectivity?

Any advice would be appreciated.

kedar
  • 45
  • 7

1 Answers1

0

I cannot reproduce your exact query because getting the graph for all of Venezuela requires over 700 downloads. But I can reproduce your area of interest around that point, and everything appears to be working correctly:

import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)

pt = 8.28490, -62.72240
cf = '["highway"~"motorway|motorway_link|trunk|primary|secondary"]'
G = ox.graph_from_point(pt, dist=5000, network_type='drive', custom_filter=cf)
G_projected = ox.project_graph(G)

node = ox.get_nearest_node(G, pt)
print(list(G.neighbors(node))) #[]
print(list(G_projected.neighbors(node))) #[]
print(list(G.predecessors(node))) #[5098062995]
print(list(G_projected.predecessors(node))) #[5098062995]

x = G.nodes[node]['x']
y = G.nodes[node]['y']
bbox = ox.utils_geo.bbox_from_point((y, x), dist=200, project_utm=True)
nc = ['r' if n==node else 'w' for n in G.nodes()]
fig, ax = ox.plot_graph(G_projected, node_color=nc, node_size=50, bbox=bbox)

enter image description here

The node in question is this one, which given the network types in your custom filter, has no successor nodes in your graph. For a MultiDiGraph, neighbors is equivalent to successors and thus in both the unprojected and projected graphs, you get an empty list (and an empty subgraph when induced on this node). This node does however have one predecessor in your graph, which you can see printed in the code snippet using the predecessors method.

gboeing
  • 5,691
  • 2
  • 15
  • 41