rossant / smopy

OpenStreetMap image tiles in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature request] support for geopandas objects

knaaptime opened this issue · comments

Hi Cyrille,

thanks for your work; this is an excellent package.

I'd like to use smopy as a way of adding basemaps to static images, similar to what you suggest here. Ideally, however, I'd like to use this functionality underneath geopandas choropleth maps.

I'm no matplotlib wiz, but from what I can tell from your code, this may already be possible... the only trouble is passing geopandas polygons to smopy's to_pixels method. (is that correct?). Your example notebook mentions that the to_pixels method can handle polygons and patches, but doesn't provide an example

Would it be possible to add an example showing to_pixels used with polygons and/or plotting geopandas objects directly? I don't think I'm skilled enough to submit a PR, but I might be able to after seeing an example. I'm also happy to offer whatever other labor I can

thanks

Hi,

Have you tried https://github.com/python-visualization/folium ? It seems like it would do what you want?

Otherwise you might be able to use smopy, but it might be a bit tricky (I should also say that smopy is not very well supported and it's been a while since I last worked on it!). smopy gives you a to_pixels() function for converting coordinates into pixels. If you can transform geopandas object into lists of NumPy arrays and conversely, I suppose you could do:

geopandas -> list of NumPy arrays with coordinates -> list of NumPy arrays with pixels -> geopandas

Then you would have to draw polygons using the matplotlib API (see here for example).

Hope that helps!

thanks for your reply

I like folium and I use it quite a bit, but in this particular case I'm looking to create a series of static images that I can use in other (non web-based) documents. I imagine this is not a terribly uncommon use case (in fact this same question has come up on the folium boards as well), so maybe I should raise the issue with the Geopandas devs too.

I'm sure that Geopandas geometries can be converted into a list of NumPy arrays, but it requires traversing the layers of Pandas/NumPy/Shapely in a way that I haven't quite cracked. So the pipeline you outline is exactly what I'd been trying to do, but with little success. I'll keep working on it and see what I can come up with.

thanks!