2

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

  • "it doesn't seem to work" is not a problem description. Why not? What happens? What should happen instead? – underscore_d Jul 02 '20 at 15:03
  • It is unclear what you're trying to do from your question. There are many usage examples on GitHub, as linked in the OSMnx documentation: https://github.com/gboeing/osmnx-examples/blob/v0.14.0/notebooks/08-custom-filters-infrastructure.ipynb – gboeing Jul 03 '20 at 06:51
  • thank you for your answer, i've completed a little my description then. In the doc, then I only see that you can pass : - `"['bus'~'yes']['psv'~'yes']" ` that gives me the roads where both can access, but does'nt include those where only one can access - `"['bus'!~'.*|no']"` that gives me the roads where the tag bus does'nt exist or where buses are'nt allowed. but I only can play withe the 'bus tag' ? – Vianney Morain Jul 03 '20 at 14:21

1 Answers1

2

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

gboeing
  • 5,691
  • 2
  • 15
  • 41