Search code examples
pythonjupyterfolium

folium draw circle not drawing


I'm trying to draw some circles to outline koala sightings around Brisbane Aus. When I try and run it in jupyter, it draws the map and if I replace the coordinate[["decimalLatitude"],coordinate["decimalLongitude"]] with actual values, it displays, but otherwise it doesn't. Here's my code and a sample pic of the data.

import folium

map_of_koala_sightings = folium.Map(
    location =[-27.470125,153.021072],
    zoom_start=13, tiles='Stamen Terrain'
)


for coordinate in koala_df:
    try:
        folium.Circle(
        radius=300,
        location = coordinate[["decimalLatitude"],coordinate["decimalLongitude"]],
        color='#3388ff',
            fill=True).add_to(map_of_koala_sightings)
    except:
        pass
map_of_koala_sightings

Sample Data


Solution

  • This works for me (with a subset of coordinates).

    import folium
    import pandas as pd
    
    koala_df = pd.DataFrame(columns = ['decimalLatitude','decimalLongitude'],
                            data = [[-26.770484,152.838467],
                                    [-28.103458,153.375882],
                                    [-26.4,146.25]])
    
    print(koala_df.head())
    
    
    map_of_koala_sightings = folium.Map(
        location =[-27.470125,153.021072],
        zoom_start=5, tiles='Stamen Terrain'
    )
    
    
    for idx,coordinate in koala_df.iterrows():
        folium.Circle(radius=300,
                      location = [coordinate['decimalLatitude'],coordinate['decimalLongitude']],
                      color='#3388ff',
                      fill=True).add_to(map_of_koala_sightings)
    
    #map_of_koala_sightings
    
    #For saving to html file
    map_of_koala_sightings.save('koalas.html')
    

    Output:

       decimalLatitude  decimalLongitude
    0       -26.770484        152.838467
    1       -28.103458        153.375882
    2       -26.400000        146.250000
    

    and 'koalas.html' contains:

    enter image description here