marceloprates / prettymaps

A small set of Python functions to draw pretty maps from OpenStreetMap data. Based on osmnx, matplotlib and shapely libraries.
GNU Affero General Public License v3.0
11.04k stars 516 forks source link

Fix "Multi-part geometries do not themselves provide the array interface" when using non dict width #55

Closed JonFreer closed 2 years ago

JonFreer commented 2 years ago

Issue: When using a non dict width for streets, waterways and railways, such as 'streets': {'width': 2}, code errors out with:

Traceback (most recent call last):
  File "c:\Users\GuildTV\Desktop\pretty maps\index.py", line 12, in <module>
    backup = plot(
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\prettymaps\draw.py", line 191, in plot
    layers = {
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\prettymaps\draw.py", line 192, in <dictcomp>
    layer: get_layer(
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\prettymaps\fetch.py", line 250, in get_layer
    return get_streets(**kwargs, layer=layer)
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\prettymaps\fetch.py", line 224, in get_streets
    streets = MultiLineString(streets.geometry.tolist()).buffer(width)
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\shapely\geometry\multilinestring.py", line 53, in __init__
    self._geom, self._ndim = geos_multilinestring_from_py(lines)
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\shapely\geometry\multilinestring.py", line 135, in geos_multilinestring_from_py
    geom, ndims = linestring.geos_linestring_from_py(obs[l])
  File "shapely\speedups\_speedups.pyx", line 88, in shapely.speedups._speedups.geos_linestring_from_py
  File "C:\Users\GuildTV\AppData\Local\Programs\Python\Python39\lib\site-packages\shapely\geometry\base.py", line 854, in __array_interface__
    raise NotImplementedError("Multi-part geometries do not themselves "
NotImplementedError: Multi-part geometries do not themselves provide the array interface

Fix: handle MultiLineStrings the same way they are handled when a width dict is used, through reducing.