I am confused by the fact that some European capitals do not return a graph when queried with osmnx
. It works perfectly for Lisbon, Berlin, Paris, etc., but when I try to run it with Brussels or Athens, I get a NetworkXPointlessConcept: Connectivity is undefined for the null graph.
error.
I don't think this is expected and would appreciate any help if someone knows how to solve this.
I already checked the docs and ensured that all packages are up to date (osmnx
is 1.1.1).
import osmnx as ox
# Does *NOT* work
ox.graph_from_place("Brussels, Belgium")
# Does *NOT* work
ox.graph_from_place("Athens, Greece")
# Works
ox.graph_from_place("Berlin, Germany")
# Works
ox.graph_from_place("Zurich, Switzerland")
I do not know the reason why it cannot be obtained. When I looked into it, I was able to get geopandas, and from there I was able to get the latitude and longitude information.
import osmnx as ox
%matplotlib inline
ox.config(log_console=True)
ox.__version__
gdf = ox.geocode_to_gdf("Brussels, Belgium")
gdf
geometry bbox_north bbox_south bbox_east bbox_west place_id osm_type osm_id lat lon display_name class type importance
0 POLYGON ((4.35895 50.84385, 4.35896 50.84385, ... 50.844296 50.843082 4.3605 4.358953 258572709 relation 3299877 50.843735 4.359779 Centre for Fine Arts, Brussels, 23, Rue Ravens... amenity arts_centre 0.634996
# lat, lon
G = ox.graph_from_point((50.84375, 4.359779), network_type='all_private')
fig, ax = ox.plot_graph(G)
gdf = ox.geocode_to_gdf("Athens, Greece")
G = ox.graph_from_point((37.992907, 23.720079), network_type='drive')
fig, ax = ox.plot_graph(G)
graph.graph_from_place
Create graph from OSM within the boundaries of some geocodable place(s).
The query must be geocodable and OSM must have polygon boundaries for the geocode result. If OSM does not have a polygon for this place, you can instead get its street network using the graph_from_address function, which geocodes the place name to a point and gets the network within some distance of that point.
If OSM does have polygon boundaries for this place but you’re not finding it, try to vary the query string, pass in a structured query dict, or vary the which_result argument to use a different geocode result. If you know the OSM ID of the place, you can retrieve its boundary polygon using the geocode_to_gdf function, then pass it to the graph_from_polygon function.