NextDrought commited on
Commit
f6a12f6
1 Parent(s): f00bac0

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +58 -0
  2. app.py +68 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build stage
2
+ FROM python:3.10-slim AS build-stage
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ build-essential \
10
+ gcc \
11
+ libpq-dev \
12
+ gdal-bin \
13
+ libgdal-dev \
14
+ python3-gdal \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Set environment variables for GDAL
18
+ ENV GDAL_CONFIG=/usr/bin/gdal-config
19
+ ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
20
+ ENV C_INCLUDE_PATH=/usr/include/gdal
21
+
22
+ # Copy the requirements file into the container
23
+ COPY requirements.txt .
24
+
25
+ # Install Python dependencies
26
+ RUN pip install --no-cache-dir --upgrade pip \
27
+ && pip install --no-cache-dir -r requirements.txt
28
+
29
+ # Stage 2: Final stage
30
+ FROM python:3.10-slim AS final-stage
31
+
32
+ # Set the working directory in the container
33
+ WORKDIR /app
34
+
35
+ # Install runtime dependencies
36
+ RUN apt-get update && apt-get install -y --no-install-recommends \
37
+ libpq5 \
38
+ gdal-bin \
39
+ && rm -rf /var/lib/apt/lists/*
40
+
41
+ # Copy Python packages and dependencies from build stage
42
+ COPY --from=build-stage /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
43
+ COPY --from=build-stage /usr/local/bin /usr/local/bin
44
+
45
+ # Copy your application code
46
+ COPY . .
47
+
48
+ # Change permissions to allow all users to write to the /app directory
49
+ RUN chmod 777 /app
50
+
51
+ # Expose port 8501 for Streamlit
52
+ EXPOSE 8501
53
+
54
+ # Define environment variable for Streamlit
55
+ ENV STREAMLIT_PORT=8501
56
+
57
+ # Command to run the Streamlit app
58
+ CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import geopandas as gpd
3
+ import folium
4
+ from streamlit_folium import st_folium
5
+ from folium.plugins import Draw
6
+
7
+ # Title of the app
8
+ st.title("Vector Data Editor")
9
+
10
+ # Default file path
11
+ default_file_path = "./nyc_roads.geojson"
12
+
13
+ # Option to choose whether to load the default file or upload a new one
14
+ use_default = st.checkbox("Load default file (nyc_roads.geojson)", value=True)
15
+
16
+ if use_default:
17
+ # Load the vector data from the default file path
18
+ try:
19
+ gdf = gpd.read_file(default_file_path)
20
+ except Exception as e:
21
+ st.error(f"Error reading the default file: {e}")
22
+ st.stop()
23
+ else:
24
+ # File uploader for vector data
25
+ uploaded_file = st.file_uploader("Choose a vector file", type=["geojson", "shp"])
26
+
27
+ if uploaded_file is not None:
28
+ # Load the vector data (GeoJSON or SHP) into a GeoDataFrame
29
+ try:
30
+ gdf = gpd.read_file(uploaded_file)
31
+ except Exception as e:
32
+ st.error(f"Error reading file: {e}")
33
+ st.stop()
34
+ else:
35
+ st.write("Please upload a vector file to start editing.")
36
+ st.stop()
37
+
38
+ # Create a Folium map centered on the uploaded/default data
39
+ m = folium.Map(location=[gdf.geometry.centroid.y.mean(), gdf.geometry.centroid.x.mean()], zoom_start=10)
40
+
41
+ # Add the vector data to the map in an editable form
42
+ geo_json = folium.GeoJson(gdf, name="Loaded Data").add_to(m)
43
+
44
+ # Add the Draw plugin to the map to enable editing
45
+ draw = Draw(
46
+ export=True,
47
+ edit_options={'edit': {'selectedPathOptions': None}},
48
+ draw_options={'polyline': False, 'polygon': True, 'circle': False, 'marker': True}
49
+ )
50
+ draw.add_to(m)
51
+
52
+ # Display the map in Streamlit
53
+ output = st_folium(m, width=800, height=600)
54
+
55
+ # Handle the edited data
56
+ if output["last_active_drawing"]:
57
+ # Get the last edited drawing from the map
58
+ edited_geojson = output["last_active_drawing"]
59
+ edited_gdf = gpd.GeoDataFrame.from_features(edited_geojson["features"])
60
+
61
+ # Display the edited GeoDataFrame
62
+ st.write(edited_gdf)
63
+
64
+ # Save changes and download the edited data
65
+ if st.button("Save Changes"):
66
+ edited_gdf.to_file("edited_data.geojson", driver="GeoJSON")
67
+ with open("edited_data.geojson", "rb") as file:
68
+ st.download_button("Download Edited File", data=file, file_name="edited_data.geojson")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ geopandas
3
+ folium
4
+ streamlit-folium