Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is PNG always referred to distance 802 m? #335

Closed
nemecsek69 opened this issue Oct 2, 2019 · 1 comment
Closed

Why is PNG always referred to distance 802 m? #335

nemecsek69 opened this issue Oct 2, 2019 · 1 comment

Comments

@nemecsek69
Copy link

nemecsek69 commented Oct 2, 2019

Linux 19.04, Python 3.7.3, OSMnx 0.10, JupyterLab 1.0.4

I requested info on Stackoverflow but got no answer.

I would like to save SVG and PNG based on the same graph. PNG should keep a different road size according to the type (that's why I am using plot_figure_ground), but the roads position and scale should be the same as in the SVG.
According to distance, SVG resizes correctly, while PNG is always 1 square mile. If distance is 1/2 mile, roads are slide to the left and cropped.

Am I doing something wrong here? Is it possible to resize PNG as it is for SVG?

import osmnx as ox
import os
from IPython.display import Image

%matplotlib inline
ox.config(log_file=False, log_console=False, use_cache=True)

PLACE = "aPlace"
NETWORK_TYPE = "drive"  

location_point = (50.6233696,12.3007474)
width = 2000;
filename = f"{PLACE}_{width}m_{NETWORK_TYPE}"

# if the graphml file already exists, don't load it again
if os.path.exists(f'data/{filename}.graphml'):
    G  = ox.load_graphml(filename=f'{filename}.graphml')
    GP = ox.load_graphml(filename=f'{filename}_projected.graphml')
    print("found saved graphhml")
else:
    print("graphml not found... loading new data")
    G = ox.graph_from_point(
        location_point, 
        distance=width / 2, # <=========================
        distance_type='bbox', 
        network_type=NETWORK_TYPE, 
        clean_periphery=False, 
        # infrastructure='way["highway"~"motorway"]'
    )
    GP = ox.project_graph(G)
    ox.save_graphml(G, filename=f'{filename}.graphml')
    ox.save_graphml(GP, filename=f'{filename}_projected.graphml')
    print("saved")
    
print(f"\nsaved {filename}.svg")
fig, ax = ox.plot_graph(GP, show=True, save=True, filename=filename, file_format='svg', node_size=0, edge_linewidth=0.3, edge_color="#000000")

print(f"\nsaved {filename}.png")
street_widths = {'footway' : 0.5, 'steps' : 0.5, 'pedestrian' : 0.5, 'path' : 0.5, 
                 'track' : 0.5, 'service' : 2, 'residential' : 3, 'primary' : 5, 'motorway' : 6}

fig, ax = ox.plot_figure_ground(G, street_widths=street_widths, show=True, smooth_joints=True, bgcolor="b", edge_color="w", dpi=10, 
                               filename=filename, file_format="png")
@nemecsek69 nemecsek69 changed the title Why is PNG always referred to distance 1605 m? Why is PNG always referred to distance 802 m? Oct 2, 2019
@gboeing
Copy link
Owner

gboeing commented Oct 2, 2019

This isn't an SVG vs PNG issue, but it comes down to the fact that you're using two different plotting functions with very different purposes (plot_graph vs plot_figure_ground). Just pass the dist argument into plot_figure_ground to override its 805-meter default parameterization. It's described in the documentation: https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.plot.plot_figure_ground

@gboeing gboeing closed this as completed Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants