Mechatrnk
Mechatrnk

Reputation: 111

How to turn OSMNx graph to Box2D

I am trying to implement OSMNx into Box2D world and I would like to set blocks as static bodies. I managed to get coordinates of nodes (their latitudes and longitudes) But I do not know how to filter nodes of blocks and thus set them as static bodies.

In this example you can see my graph of Monaco City (Manhattan island would be maybe more appropriate to see what my goal is but it is much more complex map than I need)

import osmnx as ox
print("I am Working")
G = ox.graph_from_place('Monaco City', network_type='drive')
lons = []
lats = []
for node in G.nodes:
   lons.append(G.nodes[node]['x']) #lon
   lats.append(G.nodes[node]['y']) #lat

print(lons)
ox.plot_graph(G)

enter image description here

I would like to set all the white parts encircled by those gray roads (the city blocks) to Box2D static bodies (using polygons), but I do not have a clue how to do that

Any help appreciated

Upvotes: 1

Views: 122

Answers (1)

gboeing
gboeing

Reputation: 6422

I would like to convert all those gray parts into a set of static bodies and to do so I need coordinates of corners.

If by "corners" you mean network nodes (i.e., intersections and dead-ends), then you would simply extract the coordinates of the network nodes. This is basic OSMnx/NetworkX functionality, so I'd suggest initially familiarizing yourself with their documentation and exploring the OSMnx examples.

Upvotes: 1

Related Questions