python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.91k stars 2.22k forks source link

GeoJson Winding order #1102

Closed psychemedia closed 5 years ago

psychemedia commented 5 years ago

Trying to create a choropleth map using shapes created by the https://github.com/WZBSocialScienceCenter/geovoronoi/ package, folium was was unable to generate valid geojson from a geopandas dataframe created around the voronoi boundaries.

However, I was able to explicitly generate valid geojson from my dataframe as:

import json
from geojson_rewind import rewind

gdf = gdf.set_geometry('voronoi_boundary')
rewoundGeoJSON = rewind( json.dumps(gdf['voronoi_boundary'].__geo_interface__) )

I don't have a small reproducible example offhand - just filing this here in case it's useful for others or perhaps merits a guard that will automatically rewind the geojson shapes.

mazzma12 commented 5 years ago

Hi ! I encountered the same Issue with Vega that enforces count clockwise oriented polygon. I don't know the geojson_rewind library, but shapely library provides a somehow hidden method to perform the rewind see :

import shapely

# Orient the shape counter clockwise to be Vega conform
df.geometry = df.geometry.map(lambda polygon: shapely.ops.transform(shapely.geometry.polygon.orient)
Conengmo commented 5 years ago

Thanks for reporting this to you both! I'm not familiar with this particular problem, but it sounds like something that we won't have to include in the folium library, since it is already solved by other libraries. I'm therefore closing the issue, but feel free to add more comments on this topic. We can always reopen if someone wants to make the case for something that has to be done in folium.

psychemedia commented 5 years ago

@Conengmo Not a folium issue per se, but for non-expert users using folium as an easy way of plotting maps, this may be an issue that they encounter but cannot necessarily identify from folium error messages or fix themselves?