question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does one [deep]copy a map object?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jwhendycommented, Sep 21, 2019

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.

0reactions
Conengmocommented, Sep 23, 2019

Cool project @jwhendy, thanks for sharing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Copying a HashMap in Java - Baeldung
A deep copy of a HashMap is a new HashMap that deeply copies all the mappings. Therefore, it creates new objects for all...
Read more >
How to copy a Map into another Map? [duplicate]
I know how to clone an array, but how do I clone/copy a Map ? var myArray = new Array(1, 2, 3); var...
Read more >
How to clone HashMap - Shallow and Deep Copy
The best way to create shallow clone of hashmap is to use it's clone() method. It returns a shallow copy of the map....
Read more >
How to Deep Copy Objects and Arrays in JavaScript
Making a shallow copy of an array or object means creating new references to the primitive values inside the object, copying them. That...
Read more >
5 ways to clone a Map in Java - Techie Delight
We can use a copy constructor to clone a map, which is a special constructor for creating a new object as a copy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found