Py.Cafe

youssef-gis/

streamlit-data-explorer

Exploring Geospatial Data with Streamlit

DocsPricing
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
import numpy as np
import pandas as pd
import geopandas as gpd
import leafmap.foliumap as leafmap
from shapely.geometry import Point
import folium
from folium.plugins import Geocoder, Fullscreen
from folium.plugins import MarkerCluster
from streamlit_folium import st_folium, folium_static

st.set_page_config(layout="wide")
date_format = "%Y-%m-%d"


def main():

    st.title('STER PROJETS')

    # Upload CSV file
    uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
    if uploaded_file:
        df= pd.read_csv(uploaded_file)
        print(df.Etat_projet)
        geometry = [Point(xy) for xy in zip(df['longitude'], df['latitude'])]
        gdf = gpd.GeoDataFrame(df, geometry=geometry)
        gdf.crs = 'EPSG:4326'
        points_df = gdf[['latitude', 'longitude']]

        map_center = [points_df['latitude'].mean(), points_df['longitude'].mean()]
        m= leafmap.Map(location=map_center, draw_control=False, measure_control=False, zoom=5)    
        

        # for _, row in points_df.iterrows():
        #     leafmap.Marker(
        #         location=[row['latitude'], row['longitude']],
        #         popup=f"Lat: {row['latitude']}, Lon: {row['longitude']}"
        #     ).add_to(m)

        

                #create a marker cluster group for the closest points
        mcg = MarkerCluster()
        for idx, row in gdf.iterrows():
            popup_content = "Id projet: " + str(row["identifiant_projet"])+ "<br>" + "Projet: " + row["projet"] + "<br>" + "Etat: " +row["Etat_projet"]
            if row["Etat_projet"] == "En_attente":
                color= "#FF0000"
            elif row["Etat_projet"] == "En_cours":
                color="#fbff00"
            elif row["Etat_projet"] == "Conclu":
                color="#008000"

            folium.Marker(location=[row['geometry'].y, row['geometry'].x], popup=popup_content, max_width='250',  icon=folium.Icon(icon_color=color)).add_to(mcg)

                # add the marker cluster group to the folium map
        mcg.add_to(m)
        st_folium(m)

if __name__  =='__main__':
    main()