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

'Polygon' object is not subscriptable #45

Open mikedewar opened 2 years ago

mikedewar commented 2 years ago

Hi,

First of all - thanks so much for this library. It's gorgeous.

I'm trying to follow along with the "Palmanova, Italy" example, which is bounded by the city's walls

https://nbviewer.jupyter.org/github/marceloprates/prettymaps/blob/main/notebooks/examples.ipynb#Palmanova,-Italy-(circle-plot-with-postprocessing-step)

I'm getting stuck with the preprocessing function, as to start with my notebook doesn't know what the Polygon function is. After digging into the source a bit it turns out you're using shapely.geometry.Polygon and so I hoped that if I import that directly then it would be OK. So I add

from shapely.geometry import Polygon

If I do this, I now have a Polygon function but I don't think I've gotten it right, because I instead receive when I execute boundary = Polygon(layers['green'].buffer(5)[0].exterior).buffer(0) I receive

TypeError: 'Polygon' object is not subscriptable

at which point I gave up.

Any clues you could provide would be most appreciated!

mikedewar commented 2 years ago

took about 30 more seconds of mucking around to realise that the answer is

from shapely.geometry.polygon import Polygon

so many polygons!

Will leave this here just in case others are having similar issues to me. I don't know if I did something wrong on the install, but it might be that the Polygon you're expecting to be in everyone's namespace isn't actually there!