How does one [deep]copy a map object?
See original GitHub issueI was hoping to cycle through a dataframe of (lat, lon)
locations and add a big, opaque point for each, then a less opaque, smaller point. As I go, I want the small dots to stay to draw attention to each new point added.
I tried this without success (well, via df.iterrows()
on my end, but here’s a simper reproducible example):
bbox = [[44.935, -93.09], [44.955, -93.06]]
m = folium.Map(location=[np.mean([bbox[0][0], bbox[1][0]]), np.mean([bbox[0][1], bbox[1][1]])])
m.fit_bounds(bounds=bbox)
m1 = m
#m1 = folium.Map(location=[np.mean([bbox[0][0], bbox[1][0]]), np.mean([bbox[0][1], bbox[1][1]])])
#m1.fit_bounds(bounds=bbox)
folium.Circle(location=[44.95, -93.07], radius=50, fill=True, stroke=False, fill_opacity=0.8, fill_color='blue').add_to(m1)
IPython.display.display(m1)
time.sleep(2)
IPython.display.clear_output(wait=True)
folium.Circle(location=[44.95, -93.07], radius=20, fill=True, stroke=False, fill_opacity=0.3, fill_color='blue').add_to(m)
IPython.display.display(m)
time.sleep(2)
IPython.display.clear_output(wait=True)
I’m guessing m1
is actually referencing m
and is not really a copy. I tried m1 = copy.deepcopy(m)
but get TypeError: __new__() missing 1 required positional argument: 'source'
Any suggestions? If I create the m1
object explicitly using the commented lines above, it works, but this wouldn’t work to create the desired effect of having existing translucent dots always there and only adding the new opaque dot on each iteration.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thanks for the feedback. I wasn’t sure on the performance hit of recreating a new map, as well as having to re-add all previous points vs. just adding the ones since the last time through the loop. My process is working well, though. I’ll post the output so you can see it!
It’s a hobby project exploring accident data I was able to get from my city to see if the accident rate changed since the bridge was redone. Turns out it has 😃 Thankfully
folium
could enable me to verify this. Now I’m trying to create a compelling graphic to see about getting improved signage. Should have my final result later today.Cool project @jwhendy, thanks for sharing!