8

I'm plotting the missions ran by the USAF on North Korea during the Korean War.

The following is the map with 2800 plots.

enter image description here

I have a total of about 7500 plots, but whenever I try to plot above 2800 a blank map renders. I'm rendering on a pc laptop. Would it render if I use a desktop? Or is this a limit with folium?

I'm not speculating that it's an issue with the data. I'll share the coordinates data in case someone would like to explore it: link to public excel sheet.

ekim420
  • 455
  • 1
  • 6
  • 19

2 Answers2

11

As @Bob Haffner suggested you can use FastMarkerCluster from Folium library. Here is my code, in my file there is ~500K points.

import pandas as pd
import json
from folium.plugins import FastMarkerCluster

rome_lat, rome_lng = 41.9028, 12.4964
with open("file_name.json", 'r') as f:
  # create a new DataFrame
  samples = pd.DataFrame(json.loads(f.read()))        
# init the folium map object
my_map = folium.Map(location=[rome_lat, rome_lng], zoom_start=5)
# add all the point from the file to the map object using FastMarkerCluster
my_map.add_child(FastMarkerCluster(samples[['latitude', 'longitude']].values.tolist()))
# save the map 
my_map.save("save_file.html")

This code takes ~10ms to render the map.

For more details example please follow this link: FastMarkerCluster example

Hope this is helpful.

blong
  • 2,815
  • 8
  • 44
  • 110
DavidDr90
  • 559
  • 5
  • 20
  • It's Marker not Circle. – secsilm Apr 29 '21 at 02:29
  • The link to "FastMarkerCluster example" is broken. Is there another version or archive of that blog post? – blong May 05 '21 at 16:28
  • 1
    Hi @blong you can try explore the code from the old post in Bob Haffner's GitHub [LINK](https://github.com/bobhaffner/medium_posts/blob/master/folium_markerclusters/folium_markerclusters.ipynb) – DavidDr90 May 06 '21 at 06:48
1

Another option is that we can add a specific number of markers(let's say 3000 markers) on a layer, using folium.map.FeatureGroup() function that will add 3000 markers on a single layer, and we can add that layer to the map using add_child() function, which reduces the number of layers on the map. I got the result for 20,000 Markers and 3000 line string. And is able to load within 40-45 seconds.