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

City graph seems to lose some edges #41

Closed
plopezmp opened this issue Mar 19, 2017 · 4 comments
Closed

City graph seems to lose some edges #41

plopezmp opened this issue Mar 19, 2017 · 4 comments

Comments

@plopezmp
Copy link

Problem description

City graph and building footprint do not match if put together in a two layer picture

Mac OSX 10.11.6 (El Capitan), Python 2.7.10, OSMnx 0.4.

Complete list of your environment's packages and their versions:

zsh-% pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
appdirs (1.4.3)
appnope (0.1.0)
backports-abc (0.5)
backports.shutil-get-terminal-size (1.0.0)
bleach (2.0.0)
certifi (2017.1.23)
click (6.7)
click-plugins (1.0.3)
cligj (0.4.0)
configparser (3.5.0)
cycler (0.10.0)
decorator (4.0.11)
descartes (1.1.0)
entrypoints (0.2.2)
enum34 (1.1.6)
Fiona (1.7.4)
functools32 (3.2.3.post2)
geopandas (0.2.1)
html5lib (0.999999999)
ipykernel (4.5.2)
ipython (5.3.0)
ipython-genutils (0.2.0)
ipywidgets (6.0.0)
Jinja2 (2.9.5)
jsonschema (2.6.0)
jupyter (1.0.0)
jupyter-client (5.0.0)
jupyter-console (5.1.0)
jupyter-core (4.3.0)
MarkupSafe (1.0)
matplotlib (2.0.0)
mistune (0.7.4)
munch (2.1.0)
nbconvert (5.1.1)
nbformat (4.3.0)
networkx (1.11)
notebook (4.4.1)
numpy (1.12.1)
osmnx (0.4)
packaging (16.8)
pandas (0.19.2)
pandocfilters (1.4.1)
pathlib2 (2.2.1)
pexpect (4.2.1)
pickleshare (0.7.4)
pip (9.0.1)
prompt-toolkit (1.0.13)
ptyprocess (0.5.1)
Pygments (2.2.0)
pyparsing (2.2.0)
pyproj (1.9.5.1)
python-dateutil (2.6.0)
pytz (2016.10)
pyzmq (16.0.2)
qtconsole (4.2.1)
requests (2.13.0)
Rtree (0.8.3)
scandir (1.5)
setuptools (34.3.2)
Shapely (1.5.17.post1)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
subprocess32 (3.2.7)
terminado (0.6)
testpath (0.3)
tornado (4.4.2)
traitlets (4.3.2)
wcwidth (0.1.7)
webencodings (0.5)
wheel (0.29.0)
widgetsnbextension (2.0.0)
zsh-%

Code that reproduces the issue

import osmnx as ox
from IPython.display import Image
%matplotlib inline
ox.config(log_console=True, use_cache=True)

def make_plot(place, point, network_type='drive', bldg_color='orange', dpi=90,
              dist=805, default_width=4, street_widths=None):
    gdf = ox.buildings_from_point(point=point, distance=dist)
    gdf_proj = ox.project_gdf(gdf)
    fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width,
                                    street_widths=street_widths, save=False, show=False, close=True)
    fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=bldg_color, set_bounds=False,
                                save=True, show=False, close=True, filename=place, dpi=dpi)

place = 'gante'
point = (51.05660,3.721500)
make_plot(place, point, network_type='walk', default_width=3, street_widths={'primary':3}, dist=525)
Image('{}/{}.{}'.format(img_folder, place, extension), height=size, width=size)

location_point = (51.05660,3.721500)

# create network from point, inside bounding box 
G2 = ox.graph_from_point(location_point, distance=525, distance_type='bbox', network_type='walk')
#                        simplify='True',retain_all='False', truncate_by_edge = 'False')
G2 = ox.project_graph(G2)
fig, ax = ox.plot_graph(G2, node_size=2, node_color='#66cc66')

10-building-footprints&Gante.ipynb.zip

@gboeing
Copy link
Owner

gboeing commented Mar 19, 2017

It isn't losing any edges. The plot_figure_ground function handles graph construction and plotting in a very specific way to maintain a precise equal-aspect perspective, bounding box, and plotting figure. If you want to overlay another image on top of it, you need to make sure they're created the same way so that they match up, pixel-for-pixel.

First, create your figure-ground diagrams and save to a png file:

import osmnx as ox
from IPython.display import Image
%matplotlib inline
ox.config(log_console=True, use_cache=True)

location_point = (51.05660,3.721500)
dist = 525
network_type = 'walk'

img_folder = 'images'
extension = 'png'
size = 300

def make_plot(place, point, network_type='drive', bldg_color='orange', dpi=90,
              dist=805, default_width=4, street_widths=None):
    gdf = ox.buildings_from_point(point=point, distance=dist)
    gdf_proj = ox.project_gdf(gdf)
    fig, ax = ox.plot_figure_ground(point=point, dist=dist, network_type=network_type, default_width=default_width,
                                    street_widths=street_widths, save=False, show=False, close=True)
    fig, ax = ox.plot_buildings(gdf_proj, fig=fig, ax=ax, color=bldg_color, set_bounds=False,
                                save=True, show=False, close=True, filename=place, dpi=dpi)
    
place = 'gante'
make_plot(place, location_point, network_type=network_type, default_width=3, street_widths={'primary':3}, dist=dist)
Image('{}/{}.{}'.format(img_folder, place, extension), height=size, width=size)

Then, create a new graph around the same area and plot it the exact same way that plot_figure_ground would:

G = ox.graph_from_point(location_point, distance=dist*1.2, distance_type='bbox', network_type=network_type,
                        simplify=False, truncate_by_edge=True)
G = ox.simplify_graph(G, strict=False)
G = ox.project_graph(G)
bbox_proj = ox.bbox_from_point(location_point, dist, project_utm=True)
fig, ax = ox.plot_graph(G, bbox=bbox_proj, fig_height=8, margin=0, axis_off=True, equal_aspect=True, bgcolor='w', 
                        node_size=30, node_color='g', node_zorder=2, edge_linewidth=3, edge_color='m', 
                        show=False, save=True, close=True, filename='new', file_format='png', dpi=90)

You now have two png files saved. Now if you overlay the second image file on top of the first, they will match up, pixel-for-pixel:

@plopezmp
Copy link
Author

Thank you very much.

It is possible to save G (the graph of roads) as a shapefile and still match the building footprint?
I have tried with

G = ox.graph_from_point(location_point, distance=dist*1.2, distance_type='bbox', network_type=network_type, simplify=False, truncate_by_edge=True)
G1 = ox.simplify_graph(G, strict=False)
ox.save_graph_shapefile(G1, filename='false') 

but the result is different that the footprint image.
I would need the roads in shp format.

Thank you for your time and help.
Regards

@gboeing
Copy link
Owner

gboeing commented Mar 20, 2017

The png file format is a raster data format, but shapefiles are a vector data format. Overlaying them and getting them to line up will entirely be up to the software with which you overlay them (i.e., not an OSMnx issue). In general, it's probably easiest to match things up if they're both raster or both vector (though this certainly isn't a hard and fast rule). If you want to do everything as (vector) shapefiles, you can download the building footprints then save as a shapefile -- for an example, see cell 4 in this notebook. Then download the graph of roads and save as a shapefile. If you then open these two shapefiles as layers in a GIS (or whatever software that can handle them), they will line up properly.

@plopezmp
Copy link
Author

Thank you very much

@gboeing gboeing changed the title City graph seems to loose some edges City graph seems to lose some edges Apr 19, 2017
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