我想计算每个admin_level 6(部门)的便利设施(酒吧和酒馆)。
我通过天桥Turbo成功制作了一个csv文件:
[out:csv(id, total )];
//All French départements (level 6) from FR-01 to FR-95 plus FR-2A and FR-2B
area[admin_level=6]["ISO3166-2"~"^FR-[0-9]|[1-8][0-9]|9[0-5]|2[A-B]"];
// Counts bars and pubs in each dpt (level 6)
foreach->.dpt(
// search for bars and pubs
(
way(area.dpt)[amenity=pub];
way(area.dpt)[amenity=bar];
node(area.dpt)[amenity=pub];
node(area.dpt)[amenity=bar];
);
make count id = dpt.set(t["ref"]),
total = count(ways) + count(nodes);
out;
);
但是由于我知道overpy不能处理csv文件,所以我想获取一张夫妻名单(区域参考,酒吧和酒馆的数量)。
此:
import overpy
api = overpy.Overpass()
dpts = api.query("""
// All french departements (level 6)
area[admin_level=6]["ISO3166-2"~"^FR-[0-9]|[1-8][0-9]|9[0-5]|2[A-B]"];
// Find bars and pubs in each dpt
foreach->.dpt(
// looks for bars and pubs
(
way(area.dpt)[amenity=pub];
way(area.dpt)[amenity=bar];
node(area.dpt)[amenity=pub];
node(area.dpt)[amenity=bar];
);
out;
);
""")
为我提供了所有节点和方式,但未按area.dept排序。
我有所有的酒吧和酒馆:
In [102]: len(dpts.ways + dpts.nodes)
Out[102]: 3895
如何获取[(area ref, number of pubs and bars)]
类型的列表?
答案 0 :(得分:0)
好吧,我想使用Python进行循环很容易:
Bars = []
api = overpy.Overpass()
for d in range(21,96):
dpt = api.query("""
area[admin_level=6]["ISO3166-2" = "FR-{}"];
(way(area)[amenity=bar];
node(area)[amenity=bar];);
(._;>;);
out;""".format(d))
Bars.append((d, len(dpt.ways + dpt.nodes)))
Bars
但这每次都会创建一个查询。它比在查询内部循环效率低吗?