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.02k stars 516 forks source link

ValueError: OSM did not return any polygonal geometries for query #82

Open kamilkosek opened 2 years ago

kamilkosek commented 2 years ago

Hi all, I just wanted to plot my 'hood' and some adjacent districts, so i basically took the example from the notebook and ran it.

from shapely.ops import unary_union
from shapely.affinity import *
from shapely.geometry import *
from descartes import PolygonPatch
from matplotlib import pyplot as plt
import matplotlib.font_manager as fm
import osmnx as ox
from prettymaps import *
import sys
from datetime import datetime
import re

sys.path.append('../')
fig, ax = plt.subplots(figsize = (15, 12), constrained_layout = True)
fig.patch.set_facecolor('#F9F8F8')

places = {
    'Wiesenau, Hannover, Deutschland': ['#49392C', '#77625C', '#B2B1CF', '#E1F2FE', '#98D2EB'],
    'Brink-Hafen, Hannover, Deutschland': ['#EEE4E1', '#E7D8C9', '#E6BEAE'],
    'Vinnhorst, Hannover, Deutschland': ['#BA2D0B', '#D5F2E3', '#73BA9B', '#F79D5C'],
}

for i, (place, palette) in enumerate(places.items()):
    plot(
        place,
        ax = ax,
        layers = {
            'perimeter': {},
            'streets': {
                'width': {
                    'trunk': 6,
                    'primary': 6,
                    'secondary': 5,
                    'tertiary': 4,
                    'residential': 3.5,
                    'pedestrian': 3,
                    'footway': 3,
                    'path': 3,
                }
            },
            'building': {'tags': {'building': True, 'leisure': ['track', 'pitch']}, 'union': False},
            'water': {'tags': {'natural': ['water', 'bay']}},
            'park': {'tags': {'leisure': 'park'}},
            'forest': {'tags': {'landuse': 'forest'}},
            'garden': {'tags': {'leisure': 'garden'}},
        },
        drawing_kwargs = {
            'perimeter': {'fill': False, 'lw': 0, 'zorder': 0},
            'park': {'fc': '#AABD8C', 'ec': '#87996b', 'lw': 1, 'zorder': 1},
            'forest': {'fc': '#78A58D', 'ec': '#658a76', 'lw': 1, 'zorder': 1},
            'garden': {'fc': '#a9d1a9', 'ec': '#8ab58a', 'lw': 1, 'zorder': 1},
            'water': {'fc': '#92D5F2', 'ec': '#6da8c2', 'lw': 1, 'zorder': 2},
            'streets': {'fc': '#F1E6D0', 'ec': '#2F3737', 'lw': 1.5, 'zorder': 3},
            'building': {'palette': palette, 'ec': '#2F3737', 'lw': 1, 'zorder': 4},
        },

        osm_credit = {'x': -.55, 'y': -.25, 'color': '#2F3737'} if i == 0 else None
    )

ax.autoscale()

#plt.savefig('../prints/bomfim-farroupilha-cidadebaixa.png')
#plt.savefig('../prints/bomfim-farroupilha-cidadebaixa.svg')

but it failed with the error message

Traceback (most recent call last):
  File "error.py", line 24, in <module>
    plot(
  File "/home/kamil/.local/lib/python3.8/site-packages/prettymaps/draw.py", line 226, in plot
    else get_perimeter(query, by_osmid=query_mode == "osmid")
  File "/home/kamil/.local/lib/python3.8/site-packages/prettymaps/fetch.py", line 80, in get_perimeter
    return ox.geocode_to_gdf(
  File "/home/kamil/.local/lib/python3.8/site-packages/osmnx/geocoder.py", line 110, in geocode_to_gdf
    gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
  File "/home/kamil/.local/lib/python3.8/site-packages/osmnx/geocoder.py", line 166, in _geocode_query_to_gdf
    result = _get_first_polygon(results, query)
  File "/home/kamil/.local/lib/python3.8/site-packages/osmnx/geocoder.py", line 230, in _get_first_polygon
    raise ValueError(f'OSM did not return any polygonal geometries for query "{query}"')
ValueError: OSM did not return any polygonal geometries for query "Brink-Hafen, Hannover, Deutschland"

After that I´ve took a look at the relationat OSM: Brink-Hafen Relation There is one part which is not connected to the other, could it be the cause of the issue ?

Regards

mikedewar commented 2 years ago

I'm getting this now on previously working notebooks. Any ideas what's causing it?