OSMnx : how to provide more complex feature into the custom_filter parameter

假装没事ソ 提交于 2020-11-29 18:59:48

问题


I would like to pass some overpass request into ox.graph_from_place, but I don't really understand how it works with the doc.

I would like to create a graph with 2 types of roads (where the buses can pass and where the psv can pass too)

Am'i obliged to join my 2 graphs ? Or Is there a more direct method ?

G1 = ox.graph_from_place('Marseille, France', retain_all=True, custom_filter='["bus"="yes"]')

G2 = ox.graph_from_place('Marseille, France', retain_all=True, custom_filter='["psv"="yes"]')

Gtot = nx.disjoint_union(G1,G2)

Does someone know the answer?

Have a good day


回答1:


As OSMnx does not include a customizable union operator for multiple keys in its querying apparatus, your best bet is indeed to make two queries then combine them. But you should use the compose function to do so:

import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)

place = 'Marseille, France'
G1 = ox.graph_from_place(place, network_type='drive', retain_all=True, custom_filter='["bus"="yes"]')
G2 = ox.graph_from_place(place, network_type='drive', retain_all=True, custom_filter='["psv"="yes"]')
G = nx.compose(G1, G2)
print(len(G1), len(G2), len(G)) #784 141 855

See also https://stackoverflow.com/a/62239377/7321942 and https://stackoverflow.com/a/62883614/7321942



来源:https://stackoverflow.com/questions/62699216/osmnx-how-to-provide-more-complex-feature-into-the-custom-filter-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!