File size: 2,437 Bytes
581bb1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from datetime import datetime

import pandas as pd
import streamlit as st

from utils.kml_creator import generate_kml_from_df

st.title("πŸ“‘ Telecom Sector KML Generator")


# display mandatory columns

col1, col2 = st.columns(2)

with col1:
    st.write("Mandatory columns:")
    st.markdown(
        """
    | Column Name | Description |
    | --- | --- |
    | code| code of the site |
    | name | Name of the sector |
    | Azimut | Azimuth of the sector |
    | Longitude | Longitude of the sector |
    | Latitude | Latitude of the sector |
    | Size | Size of the sector ex:100 |
    | colors | Color of the sector |
    """
    )
    st.write(
        "All other columns added in the file will be displayed in the KML description for each sector."
    )

with col2:
    st.markdown(
        """
    | Color Name | KML Color Code (AABBGGRR) |
    | --- | --- |
    | Red | 7f0000ff |
    | Green | 7f00ff00 |
    | Blue | 7fff0000 |
    | Yellow | 7f00ffff |
    | Cyan | 7fffff00 |
    | Magenta | 7fff00ff |
    | Orange | 7f007fff |
    | Purple | 7f7f00ff |
    | Pink | 7fcc99ff |
    | Brown | 7f2a2aa5 |
    """
    )

sector_kml_sample_file = "samples/Sector_kml.xlsx"

# Create a download button
st.download_button(
    label="Download Sector KML sample File",
    data=open(sector_kml_sample_file, "rb").read(),
    file_name="Sector_kml.xlsx",
    mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)


st.write("Upload an excel file containing sectors data to generate a KML file.")
# Upload CSV file
uploaded_file = st.file_uploader("Upload XLSX file", type=["xlsx"])

if uploaded_file is not None:
    # Read CSV
    df = pd.read_excel(uploaded_file, keep_default_na=False)

    # Check if required columns exist
    required_columns = {
        "code",
        "name",
        "Azimut",
        "Longitude",
        "Latitude",
        "size",
        "color",
    }
    if not required_columns.issubset(df.columns):
        st.error(f"Uploaded file must contain columns: {', '.join(required_columns)}")
    else:
        # Generate KML
        kml_data = generate_kml_from_df(df)

        # Download button
        st.download_button(
            label="πŸ“₯ Download KML",
            data=kml_data,
            file_name=f"Sectors_kml_{datetime.now()}.kml",
            mime="application/vnd.google-earth.kml+xml",
        )

        st.success("KML file generated successfully! πŸŽ‰")