英文:
Extracting a network of streets and rivers using OSMnx
问题
I'm looking to construct a network of both streets and rivers using OSMnx.
I was trying this:
country_graph = ox.graph_from_polygon(polygon=drc_boundary.geometry.iloc[0], simplify=True, retain_all=True, custom_filter='["waterway"~"river"]["highway"~"primary|trunk"]')
But this would give an error:
EmptyOverpassResponse: There are no data elements in the response JSON
Is there a way to do so using the custom filter, or should I get the street network and water network separately and then combine them together?
英文:
I'm looking to construct a network of both streets and rivers using OSMnx
I was trying this:
country_graph = ox.graph_from_polygon(polygon=drc_boundary.geometry.iloc[0], simplify=True, retain_all=True, custom_filter='["waterway"~"river"]["highway"~"primary|trunk"]')
But this would give an error:
EmptyOverpassResponse: There are no data elements in the response JSON
Is there a way to do so using the custom filter, or should I get the street network and water network separately and then combine them together?
答案1
得分: 1
你正在查询匹配两个条件的方法:水道=True 且 高速公路=primary|trunk。没有方法同时满足这两个条件。相反,你需要先获取水道,然后再获取高速公路:
import networkx as nx
import osmnx as ox
point = -3.399514, 17.402937
G1 = ox.graph_from_point(point, dist=20000, retain_all=True, truncate_by_edge=True,
custom_filter='["waterway"~"river"]')
G2 = ox.graph_from_point(point, dist=20000, retain_all=True, truncate_by_edge=True,
custom_filter='["highway"~"primary|trunk"]')
G = nx.compose(G1, G2)
print(len(G1), len(G2), len(G)) # 12 6 18
参见:
- https://stackoverflow.com/a/62239377/7321942
- https://stackoverflow.com/a/62883614/7321942
- https://stackoverflow.com/a/62720802/7321942
英文:
You are querying for ways that match both conditions: waterway=True and highway=primary|trunk. No ways match both those conditions. You instead need to get the waterways first, then the highways second:
import networkx as nx
import osmnx as ox
point = -3.399514, 17.402937
G1 = ox.graph_from_point(point, dist=20000, retain_all=True, truncate_by_edge=True,
custom_filter='["waterway"~"river"]')
G2 = ox.graph_from_point(point, dist=20000, retain_all=True, truncate_by_edge=True,
custom_filter='["highway"~"primary|trunk"]')
G = nx.compose(G1, G2)
print(len(G1), len(G2), len(G)) # 12 6 18
See also:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论