简体   繁体   中英

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)

在此处输入图像描述

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

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 (ie, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM