How can I add streets as nodes in a osmnx graph? - graph

If I understood well, the osmnx method graph_from_address generates a graph in which a node refers to the intersection of two or more streets, whereas edge refers to a single street connecting two (or more) intersections.
Following this figure, from reference[1], it seems osmnx method graph_from_address generates something like Fig 1 (b) (axial graph), rather than a connectivity graph as defined in Fig 1(c) of same reference, where streets are nodes instead of edges.
enter image description here
Is there a osmnx method to extract streets as nodes, rather than as edges?
[1] Bin Jiang (2009) Ranking spaces for predicting human movement in an urban
environment, International Journal of Geographical Information Science, 23:7, 823-837, DOI:
10.1080/13658810802022822
PS: I have not found anything equivalent in the doc

Related

How to extract street graph or network from OpenStreetMap?

How to extract street graph or network from OpenStreetMap ?
Solutions:
There are many solutions to achieve this goal, I listed some of them below.
- Overpass-api
Overpass-api & overpass-turbo let you use overpass query language to collect ways and nodes of type highway for a city :
[out:xml]; area[name = "Pantin"]; (way(area)[highway]; ); (._;>;); out;
Pantin is a city in France
- Geofabrik & Osmium
Geofabrik allows you to download various datasets from continents to cities.
Next, extract nodes and ways of type highway using Osmium tag-filters:
osmium tags-filter map.osm w/highway -o highways-ways.osm
NOTE: osmium tags-filter also works with .pbf files
- Ophois
Ophois is a CLI tool written in Rust, i created to:
Download a map from overpass-api
Process data from Overpass or Geofabrik to extract the street graph
Simplify the extracted graph with detailed heuristics
Discretize the extracted or simplified graph to a distance in meter
I also created a simple tool to display the generated graph on a Leaflet map to check the simplification process, cartographe.
Cartographe let you check the node id and the distance of links in meters using haversine formula.
Extracted
Simplified
Simplified and Discretized
NOTE: Simplified and discretized with 10 meters parameter
- OSMnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
NOTE: Pantin using OSMnx

Voronoi approach to making districts while also using a multilinestring

I have a spatial objects with multiple points (buildings) on a map. What I wanted to do is divide an area based on the nearest point. The calculated Voronoi looks quite promising, but has some strange aspects if you know the "real world". For example a small part of a district is also at the other side of a river because of the closeness (surprise).
What I want to do is combine this with a multi linestring which contains rivers, railroads. What I want to do either end the district at this line OR add a penalty for 'crossing' it. Is anyone able to shed light on the problem, or possible suggest an alternative voronoi method that works?

Find nearest neighbor in graph with multiple start nodes?

i have a weighted graph that represents cities(nodes) and thier distances(weights) on a map. I want to mark two or more cities and get the city that is most in the middle of both. There might be more than one city between this middle city and the marked city but it should be the shortest path for both marked cities. Kind of the nearest neighbor from two nodes.
I searched for graph algroithms like dijkstra and geodesic graphs but i don't know how i could use those to do this task. Am i missing an important algorithm for this?
(My graph contains some node-objects with a list of edge-object each. The edge contains a float as the weight)

Reduce openstreetmap graph size in networkx

I have a graph (transformed from OSMNX) of London's walk path, containing 667.588 edges, with different highway attributes (the street types in openstreetmap). Running a shortest_path algorithm is quite slow (4 seconds). To improve the speed, I want to largely reduce the number of edges in a systematic way without losing main connections/city structures, but not sure how to do it? Any suggestions? Is there a way to group some close nodes to a more important one, thus reduce the size?
You can extract edges with desired highway types from your main graph G:
highways_to_keep = ['motorway', 'trunk', 'primary']
H = nx.MultiDiGraph()
for u,v,attr in G.edges(data=True):
if attr['highway'] in highways_to_keep:
H.add_edge(u,v,attr_dict=attr)
H.node[u] = G.node[u]
H.node[v] = G.node[v]
Here, we first initialized an empty MultiDiGraph, which is a type of graph used by OSMnx, then populate it with data from the main graph G, if the 'highway' attribute is in our list of highways_to_keep. You can find more about highway types in this OpenStreetMap page.
Our graph is a valid NetworkX graph, but you need to do one more thing before you can take advantage of OSMnx functionalities as well. if you execute G.graph, you will see graph attributes which contains crs (coordinate reference system) and some other things. you should add this information into your newly create graph:
H.graph = G.graph
here is the plot of H , osmnx.plot_graph(H):
It depends what type of network you're working with (e.g., walk, bike, drive, drive_service, all, etc.). The drive network type would be the smallest and prioritize major routes, but at the expense of pedestrian paths and passageways.
OSMnx also provides the ability to simplify the graph's topology with a built-in function. This is worth doing if you haven't already as it can reduce graph size by 90% sometimes while correctly retaining all intersection and dead-end nodes, as well as edge geometries, faithfully.
The above solution does not work anymore since the networkx library has changed. Specifically
H.node[u] = G.node[u]
is not supported anymore.
The following solution relies on the osmnx.geo_utils.induce_subgraph and used a node list as an argument to this function.
highways_to_keep = ['motorway', 'trunk', 'primary', 'secondary', 'tertiary']
H = nx.MultiDiGraph() # new graph
Hlist = [] # node list
for u,v,attr in G.edges(data=True):
if "highway" in attr.keys():
if attr['highway'] in highways_to_keep :
Hlist.append(G.nodes[u]['osmid'])
H = ox.geo_utils.induce_subgraph(G, Hlist)
The osmnx simplification module worked for me in this case https://osmnx.readthedocs.io/en/stable/osmnx.html#module-osmnx.simplification:
osmnx.simplification module
Simplify, correct, and consolidate network topology.
osmnx.simplification.consolidate_intersections(G, tolerance=10, rebuild_graph=True, dead_ends=False, reconnect_edges=True)
Consolidate intersections comprising clusters of nearby nodes.
osmnx.simplification.simplify_graph(G, strict=True, remove_rings=True)
Simplify a graph’s topology by removing interstitial nodes.

How to detect "MINIMAL" cycles in a graph

I have a question regarding graphs.
I have a street network (imagine Manhattan, NY as an example, but it could be any street network) represented as a graph (where junctions are represented as nodes und the streets are links between the nodes).
The problem now is that I somehow have to get the "city blocks" (think of the blocks in Manhattan for instance), i.e. the set of arcs that define a city block. I thought of cycle detection algorithms but that obviously won't give me the real blocks only, but also all the other cycles that I don't really need. Of course I could filter those out probably quite easily but this can't be the real solution.
Do you have any (simple) idea how I can get the "real" city block from a graph?
Thanks in advance!

Resources