【发布时间】:2019-10-04 15:07:57
【问题描述】:
这个问题是关于包pyosmium 的。我只是想知道以下功能是否可行,如果不可行,如何实现。
我想流式传输/生成某些实例属性,而不是在内存中更新它们。
目前我们可以做到以下几点:
class Handler(osmium.SimpleHandler):
def __init__(self):
osmium.SimpleHandler.__init__(self)
self.edge_and_nodes = []
def way(self, w):
self.edge_and_nodes.append({'edge_id': w.id,
'nodes': [w.nodes[i].ref for i in range(len(w.nodes))]})
h = Handler()
h.apply_file("test.osm.pbf")
print("Edges and their connected nodes: {}".format(h.edge_and_nodes))
但是,在处理大区域时,这是不可扩展的。
我想要一种为每个 WayObject 生成包含 WayId 和相关 NodeId(以及标签等)的字典对象的方法。这可能吗?
我正在寻找这样的东西:
class StreamHandler(osmium.SimpleHandler):
def __init__(self):
osmium.SimpleHandler.__init__(self)
self.edge_and_nodes = []
def way(self, w):
yield {'edge_id': w.id,
'nodes': [w.nodes[i].ref for i in range(len(w.nodes))]}
h = StreamHandler()
h.apply_file("test.osm.pbf")
for row in h.way(w):
print(row)
但我不确定如何传递 w 参数 (WayObject),因为这似乎是在内部使用 apply_file() 方法处理的(而且我似乎找不到该方法的源代码)。
谢谢!
编辑:源码可以在here找到
【问题讨论】:
标签: python gis openstreetmap osmium pyosmium