简体   繁体   English

如何将 OSMNx 图形转换为 Box2D

[英]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.我正在尝试将 OSMNx 实现到 Box2D 世界中,并且我想将块设置为 static 主体。 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.我设法获得了节点的坐标(它们的纬度和经度)但我不知道如何过滤块的节点,从而将它们设置为 static 主体。

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)在此示例中,您可以看到我的摩纳哥市图表(曼哈顿岛可能更适合查看我的目标,但它比我需要的要复杂得多 map)

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我想将那些灰色道路(城市街区)包围的所有白色部分设置为 Box2D static 主体(使用多边形),但我不知道该怎么做

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.我想将所有这些灰色部分转换为一组 static 主体,为此我需要角坐标。

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 .这是基本的OSMnx / NetworkX功能,所以我建议您首先熟悉他们的文档并探索OSMnx 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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