使用OSMnx提取街道和河流的网络

huangapple go评论54阅读模式
英文:

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

参见:

英文:

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:

huangapple
  • 本文由 发表于 2023年5月22日 21:15:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76306587.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定