Comments (4)
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.
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.
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.
Thank you very much
from osmnx.
Related Issues (20)
- Add function to merge parallel roads HOT 4
- Publish v2 pre-releases HOT 1
- Issues with plotting and basic stats when using DiGraphs HOT 1
- AttributeError: module 'osmnx' has no attribute 'convert' HOT 1
- InsufficientResponseError while HOT 1
- FutureWarning: The 'unary_union' attribute is deprecated HOT 4
- Issue with graph_from_bbox on Visual Studio code. HOT 5
- plot_graph raises an MPL error while running in a remote Linux machine HOT 1
- Change bounding box coordinates' order for v2.0.0? HOT 2
- Graph route animations HOT 3
- `consolidate_intersections` crashes with dictionary for tolerances HOT 4
- Bounding Box doesn't work in ox.features_from_bbox(bbox, tags) HOT 1
- We need a fucntion that can generate gdf_nodes and gdf_edges from locallly downloaded road network loaded using geopandas as gdf HOT 3
- No Modules 1.9.3 HOT 1
- Unions filter HOT 5
- Optimize _remove_polygon_holes function for improved performance with complex geometries HOT 9
- Response Error for some network types/cities HOT 1
- Feature request: truncate_by_nearest_edge while generating graph from point HOT 1
- TypeError when using graph_from_bbox in OSMnx 2.0.0b1 HOT 9
- Incompatible with the version of numpy 2.1.0.rc1 when using 2.0.0b1 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from osmnx.