使用OSMNX时未绘制街道数据
我正在尝试使用OSMNX绘制各个城市的街道地图。如教程中所示,我已经能够成功地绘制德国柏林,但任何其他城市似乎都空白(只出现背景色)。我已经检查了我的代码是否特定于位置,并且无法找到可能导致错误的任何东西。我尝试了2个美国,瓦伦西亚和柏林的城市,也尝试了唯一正确的绘制柏林的城市。
import osmnx as ox
import networkx as nx
from PIL import Image, ImageOps, ImageColor, ImageFont, ImageDraw
from matplotlib.lines import Line2D
import matplotlib.cm as cm
import matplotlib.colors as colors
import pandas as pd
place = ['Valencia, Spain']
G = ox.graph_from_place(place, retain_all = True, simplify = True, network_type = 'all')
u = []
v = []
key = []
data = []
for uu, vv, kkey, ddata in G.edges(keys = True, data = True):
u.append(uu)
v.append(vv)
key.append(kkey)
data.append(ddata)
roadColors = []
roadWidths = []
for item in data:
if 'highway' in item.keys():
if item['length'] <= 100:
linewidth = 0.1
color = '#454545'
elif item['length'] > 100 and item['length'] <= 200:
linewidth = 0.15
color = '#676767'
elif item['length'] > 200 and item['length'] <= 400:
linewidth = 0.25
color = '#a6a6a6'
elif item['length'] > 400 and item['length'] <= 800:
linewidth = 0.35
color = '#bdbdbd'
elif item['length'] > 800:
linewidth = 0.45
color = '#d5d5d5'
else:
linewidth = 0.1
color = '#a6a6a6'
if 'primary' in item['highway']:
linewidth = 0.5
color = '#ffff'
roadColors.append(color)
roadWidths.append(linewidth)
latitude = 39.4699
longitude = 0.3763
north = latitude + 0.15
south = latitude - 0.15
east = longitude + 0.15
west = longitude - 0.15
bgcolor = '#061529'
fig, ax = ox.plot_graph(G, node_size = 0, bbox = (north, south, east, west),
dpi = 300, bgcolor = bgcolor, save = False,
edge_color = roadColors, edge_linewidth = roadWidths,
edge_alpha = 1)
fig.tight_layout(pad = 0)
I am trying to plot street maps of various cities using OSMnx. I have been able to successfully plot Berlin, Germany as shown in a tutorial, but any other city appears blank (only the background color appears). I have examined my code for anything that is location specific and am not able to find anything that may be causing an error. I have tried 2 US cities, Valencia, and Berlin and the only one that plots correctly is Berlin.
import osmnx as ox
import networkx as nx
from PIL import Image, ImageOps, ImageColor, ImageFont, ImageDraw
from matplotlib.lines import Line2D
import matplotlib.cm as cm
import matplotlib.colors as colors
import pandas as pd
place = ['Valencia, Spain']
G = ox.graph_from_place(place, retain_all = True, simplify = True, network_type = 'all')
u = []
v = []
key = []
data = []
for uu, vv, kkey, ddata in G.edges(keys = True, data = True):
u.append(uu)
v.append(vv)
key.append(kkey)
data.append(ddata)
roadColors = []
roadWidths = []
for item in data:
if 'highway' in item.keys():
if item['length'] <= 100:
linewidth = 0.1
color = '#454545'
elif item['length'] > 100 and item['length'] <= 200:
linewidth = 0.15
color = '#676767'
elif item['length'] > 200 and item['length'] <= 400:
linewidth = 0.25
color = '#a6a6a6'
elif item['length'] > 400 and item['length'] <= 800:
linewidth = 0.35
color = '#bdbdbd'
elif item['length'] > 800:
linewidth = 0.45
color = '#d5d5d5'
else:
linewidth = 0.1
color = '#a6a6a6'
if 'primary' in item['highway']:
linewidth = 0.5
color = '#ffff'
roadColors.append(color)
roadWidths.append(linewidth)
latitude = 39.4699
longitude = 0.3763
north = latitude + 0.15
south = latitude - 0.15
east = longitude + 0.15
west = longitude - 0.15
bgcolor = '#061529'
fig, ax = ox.plot_graph(G, node_size = 0, bbox = (north, south, east, west),
dpi = 300, bgcolor = bgcolor, save = False,
edge_color = roadColors, edge_linewidth = roadWidths,
edge_alpha = 1)
fig.tight_layout(pad = 0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于Valencia,您写的:
最好使用通过格林威治。
在描述Prime子午线以西的位置时,
For Valencia you wrote:
Better to use
when describing a location West of the prime meridian running through Greenwich.