Giter Club home page Giter Club logo

Comments (4)

gboeing avatar gboeing commented on May 14, 2024

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:

from osmnx.

plopezmp avatar plopezmp commented on May 14, 2024

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

from osmnx.

gboeing avatar gboeing commented on May 14, 2024

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.

from osmnx.

plopezmp avatar plopezmp commented on May 14, 2024

Thank you very much

from osmnx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.