File size: 2,032 Bytes
9ad0e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import leafmap.foliumap as leafmap
import pandas as pd
import streamlit as st


def app():

    st.title("Add Points from XY")

    sample_url = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/world_cities.csv"
    url = st.text_input("Enter URL:", sample_url)
    m = leafmap.Map(locate_control=True, plugin_LatLngPopup=False)

    if url:

        try:
            df = pd.read_csv(url)

            columns = df.columns.values.tolist()
            row1_col1, row1_col2, row1_col3, row1_col4, row1_col5 = st.columns(
                [1, 1, 3, 1, 1]
            )

            lon_index = 0
            lat_index = 0

            for col in columns:
                if col.lower() in ["lon", "longitude", "long", "lng"]:
                    lon_index = columns.index(col)
                elif col.lower() in ["lat", "latitude"]:
                    lat_index = columns.index(col)

            with row1_col1:
                x = st.selectbox("Select longitude column", columns, lon_index)

            with row1_col2:
                y = st.selectbox("Select latitude column", columns, lat_index)

            with row1_col3:
                popups = st.multiselect("Select popup columns", columns, columns)

            with row1_col4:
                heatmap = st.checkbox("Add heatmap")

            if heatmap:
                with row1_col5:
                    if "pop_max" in columns:
                        index = columns.index("pop_max")
                    else:
                        index = 0
                    heatmap_col = st.selectbox("Select heatmap column", columns, index)
                    try:
                        m.add_heatmap(df, y, x, heatmap_col)
                    except:
                        st.error("Please select a numeric column")

            try:
                m.add_points_from_xy(df, x, y, popups)
            except:
                st.error("Please select a numeric column")

        except Exception as e:
            st.error(e)

    m.to_streamlit()