Skip to content

TypeError when using graph_from_bbox in OSMnx 2.0.0b1 #1209

@EwoutH

Description

@EwoutH

Contributing guidelines

  • I understand the contributing guidelines

Documentation

  • My problem is not addressed by the documentation or examples

Existing issues

  • My problem does not appear in an existing issue

What operating system and Python version are you using?

Windows 11, Python 3.12.5

What OSMnx version are you using?

2.0.0b1

Environment packages and versions

osmnx version: 2.0.0b1
shapely version: 2.0.5
Python 3.12.5

How did you install OSMnx?

Pip

Problem description

When attempting to use the graph_from_bbox function with a tuple as input, following the updated format (west, south, east, north) in OSMnx 2.0.0b1, a TypeError occurs. The error appears to stem from an internal handling of the bounding box during the polygon creation process, leading to an unsupported operation within the Shapely library. The coordinates provided are in EPSG:4326 format, and the issue persists despite ensuring correct tuple usage. This may indicate a deeper problem with how the bounding box is processed internally.e

Complete minimal reproducible example

import osmnx as ox
import shapely

# Print osmnx and shapely versions
print(f"osmnx version: {ox.__version__}\nshapely version: {shapely.__version__}")

# Bounding box coordinates for Bangalore
north, south, east, west = (
    12.976,
    12.961,
    77.599,
    77.579,
)  # Adjusted coordinates for Bangalore

# Update bounding box to follow the new order (left, bottom, right, top)
# GeoPandas >= 2.0 is required!
bbox = (77.579, 12.961, 77.599, 12.976)  # west, south, east, north

G = ox.graph_from_bbox(bbox, network_type="drive")

Traceback:

Traceback (most recent call last):
  File "C:\Users\Ewout\Documents\GitHub\mesa-examples\gis\test_osmnx.py", line 19, in <module>
    G = ox.graph_from_bbox(bbox, network_type="drive")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\graph.py", line 98, in graph_from_bbox
    G = graph_from_polygon(
        ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\graph.py", line 456, in graph_from_polygon
    G_buff = _create_graph(response_jsons, bidirectional)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\graph.py", line 584, in _create_graph
    for response_json in response_jsons:
                         ^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\_overpass.py", line 380, in _download_overpass_network
    polygon_coord_strs = _make_overpass_polygon_coord_strs(polygon)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\_overpass.py", line 265, in _make_overpass_polygon_coord_strs
    multi_poly_proj = utils_geo._consolidate_subdivide_geometry(poly_proj)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\osmnx\utils_geo.py", line 148, in _consolidate_subdivide_geometry
    geometry = MultiPolygon([geometry])
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\shapely\geometry\multipolygon.py", line 89, in __new__
    return shapely.multipolygons(subs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\shapely\decorators.py", line 77, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ewout\.virtualenvs\Py312\Lib\site-packages\shapely\creation.py", line 429, in multipolygons
    return lib.create_collection(geometries, typ, out=out, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ufunc 'create_collection' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions