Python Forum
Adding markers to Folium map only adding last element.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding markers to Folium map only adding last element.
#1
I'm finally done with collecting data from FAA website, now I want to add the data to a website using Folium. I'm using the following link for reference.

https://python-graph-gallery.com/312-add...olium-map/

When I run the script, its only adding the last airport, and I think the problem is because its not adding. When I run my code, I'm getting this below. If you notice, I'm showing 0 for everything.

Quote: lat lon name color metar
0 28.5455 -81.332901 Orlando Executive Airport Blue KORL 161453Z 23014KT 10SM FEW022 FEW029 29/22 ...
lat lon name color metar
0 66.91390228 -151.529007 Bettles Airport Green PABT 161453Z 01006KT 10SM CLR M15/M17 A2946 RM...
lat lon name color metar
0 65.99279785 -153.7039948 Indian Mountain LRRS Airport Green PAIM 161455Z 08014KT 040V140 10SM SCT150 BKN18...
lat lon name color metar
0 59.75439835 -154.9109955 Iliamna Airport Blue PAIL 161453Z 36004KT 10SM BKN022 OVC055 M01/M0...
lat lon name color metar
0 59.01139831542969 -161.82000732421875 Platinum Airport Blue PAPM 161456Z AUTO 11015KT 10SM -RA BKN020 BKN0...
lat lon name color metar
0 44.451599 -83.394096 Oscoda Wurtsmith Airport Blue KOSC 161515Z AUTO 26009KT 10SM OVC017 11/08 A2...
lat lon name color metar
0 38.55390167 -121.2979965 Sacramento Mather Airport Green KMHR 161455Z 11003KT 10SM SKC 08/04 A2999
lat lon name color metar
0 35.2804985046 -116.629997253 Bicycle Lake Army Air Field Green KBYS 161458Z AUTO 00000KT 8SM CLR 11/M11 A3006...
lat lon name color metar
0 34.2961998 -116.1620026 Twentynine Palms (Self) Airport Green KNXP 161456Z AUTO 32006KT 10SM CLR 16/M02 A301...
lat lon ... color metar
0 39.1754 -76.668297 ... Red KBWI 161517Z 14007G15KT 10SM -RA FEW009 SCT023...

[1 rows x 5 columns]

I ran the code from the example above, and I'm getting this below, and its showing all the locations.

Quote: lat lon name
0 -58.00 -34.00 Buenos Aires
1 2.00 49.00 Paris
2 145.00 -38.00 melbourne
3 30.32 59.93 St Petersbourg
4 -4.03 5.33 Abidjan
5 -73.57 45.52 Montreal
6 36.82 -1.29 Nairobi
7 -38.50 -12.97 Salvador

This is my script. I'm reading a CSV file which contains the name, latitude and longitude of the airports.
for row in csvread:
    icao = row[0]
    name = row[1]
    latitude = row[2]
    longitude = row[3]

    metar_link = 'https://www.aviationweather.gov/metar/data?ids=' + icao + '&format=decoded&date=&hours=0'
    page = requests.get(metar_link)
    soup = bs(page.content, 'html.parser')

    if soup.select_one('td:contains("Text:") + td').text == 'No data found' or not 'SM' in (
            soup.select_one('td:contains("Text:") + td').text):
        continue

    metar = soup.select_one('td:contains("Text:") + td').text
    metar_data = func.fraction(metar)
    visibility = float(func.convert_to_float(metar_data))
    ceiling = func.convert_ceiling(metar)
    flight_conditions = func.flight_conditions(ceiling, visibility)
    color = func.colorize(flight_conditions)

    data = pd.DataFrame({
            'lat': [latitude],
            'lon': [longitude],
            'name': [name],
            'color': [color],
            'metar': [metar]
        })

    print(data)

    metar_map = folium.Map(location=[50.4512, -104.6166], tiles='cartodbpositron', zoom_start=4)

    for i in range(0, len(data)):
        folium.CircleMarker(location=[data.iloc[i]['lat'], data.iloc[i]['lon']], radius=5, color=data.iloc[i]['color'], fill=True, fill_color=data.iloc[i]['color'], tooltip=([data.iloc[i]['name']]+[data.iloc[i]['metar']])).add_to(metar_map)
        metar_map.save('metars_map.html')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding PD DataFrame column bsben 2 245 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Rows not adding to sqlite3 database using SQLAlchemy Calab 11 1,597 Jun-02-2023, 05:53 PM
Last Post: bowlofred
  Adding libraries to embedded Python as a ZIP The_Oman 0 1,192 May-05-2023, 04:05 PM
Last Post: The_Oman
  File path by adding various variables Mishal0488 2 966 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Adding MIDI Channels to each Input zach1234 6 1,145 Apr-20-2023, 11:51 AM
Last Post: jefsummers
  Adding values with reduce() function from the list of tuples kinimod 10 2,514 Jan-24-2023, 08:22 AM
Last Post: perfringo
  Adding a subroutine to a larger program Led_Zeppelin 2 880 Jan-18-2023, 11:02 PM
Last Post: deanhystad
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 877 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  Help adding a loop inside a loop Extra 31 4,335 Oct-23-2022, 12:16 AM
Last Post: Extra
  problem adding two numpy arrays djf123 2 2,042 Aug-09-2022, 08:31 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020