简体   繁体   中英

Street data is not being plotted when using OSMnx

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)

For Valencia you wrote:

longitude = 0.3763

Better to use

longitude = -0.3763

when describing a location West of the prime meridian running through Greenwich.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM