3

I have extracted the road network from Haiti using osmnx

impor omsmnx as ox
place = ox.gdf_from_place('Haiti', which_result=2)
coords = place.geometry.total_bounds
G = ox.graph_from_bbox(coords[3], coords[1], coords[2], coords[0])

that's the result

enter image description here

Now I would like to get the road network only for a city, let's say Port-au-Prince

city = 'Port-au-Prince'
place = ox.gdf_from_place(city, which_result=2)
coords_city = place.geometry.total_bounds

Is it possible to select a subgraph of G inside coords_city?

emax
  • 6,965
  • 19
  • 74
  • 141
  • High level, turn the `multidigraph object` from OSMnx into a geopandas dataframe, Then you can subset the dataframe by a polygon of your choosing and convert back to a multidigraph. That being said, I can't think of a situation where it wouldn't be easier to just call `ox.gdf_from_place()` directly on the location desired. Unless the Nominatim API is unable to supply the correct boundary. – Hugh_Kelley Jul 03 '19 at 17:56
  • 1
    @Hugh_Kelley seems like they have it right, it'd make more sense just to get the graph for the city. However, I came across a way to subset a smaller graph (point-based query) by a larger graph (city boundary) using [truncate_graph_polygon](https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.core.truncate_graph_polygon) which might be useful, if that's what you're actually interested in. – Ben Feb 24 '20 at 21:54

0 Answers0