2

I've tried adjusting parameters and changing the order in which these circles are added. I can't get the interior circle, or "hole", to remain transparent. The outer circle always predominates.

m = folium.Map(tiles="cartodbpositron", location=xy, zoom_start=14, attr="CartoDB")

folium.Circle(xy, radius=1800, fill=True, fill_opacity=.5, fill_color='black').add_to(m)
folium.Circle(xy, radius=1000, fill=False, fill_opacity=0, fill_color=None).add_to(m)

m

In effect, I'm trying to do what Shapely does:

donut = Point(0, 0).buffer(2.0).difference(Point(0, 0).buffer(1.0))

But I want to do it with Folium because projecting a circle made with Shapely yields an object that's rough, even elliptical.

Folium Donut Hole attempt

1 Answer 1

1

You can unfortunately not do this that way, with two circles on top of each other. A Circle element with a hole in it should be drawn as a polygon with a hole in it.

You should use what you did:

donut = Point(0, 0).buffer(2.0).difference(Point(0, 0).buffer(1.0))

In order to have it shown not as an elliptical geometry, you should take care of using projected coordinates instead of geographical coordinates. This can be done with (for example) geopandas. See this example.

1
  • I tried donut.crs = {'init': 'epsg:4326'} and it still projects an ellipse. If I do geopandas.GeoSeries(donut).to_crs(epsg=4326), I get ValueError: Cannot transform naive geometries. Please set a crs on the object first. Can you elaborate, please?
    – zadrozny
    Commented Apr 20, 2020 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.