Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mambostephen authored Feb 24, 2024
0 parents commit 6ce9dd0
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 0 deletions.
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
private/
.vscode/

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Qiusheng Wu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: sh setup.sh && streamlit run streamlit_app.py
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# streamlit-template

A streamlit app template for geospatial applications based on [streamlit-option-menu](https://github.com/victoryhb/streamlit-option-menu).

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/giswqs/streamlit-template/master?urlpath=proxy/8501/)

App URL: <https://share.streamlit.io/giswqs/streamlit-template>

![](https://i.imgur.com/xd64mCi.png)
19 changes: 19 additions & 0 deletions apps/heatmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import streamlit as st
import leafmap.foliumap as leafmap


def app():

st.title("Heatmap")

filepath = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv"
m = leafmap.Map(tiles="stamentoner")
m.add_heatmap(
filepath,
latitude="latitude",
longitude="longitude",
value="pop_max",
name="Heat map",
radius=20,
)
m.to_streamlit(height=700)
19 changes: 19 additions & 0 deletions apps/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import streamlit as st
import leafmap.foliumap as leafmap


def app():
st.title("Home")

st.markdown(
"""
A [streamlit](https://streamlit.io) app template for geospatial applications based on [streamlit-option-menu](https://github.com/victoryhb/streamlit-option-menu).
To create a direct link to a pre-selected menu, add `?page=<app name>` to the URL, e.g., `?page=upload`.
https://share.streamlit.io/giswqs/streamlit-template?page=upload
"""
)

m = leafmap.Map(locate_control=True)
m.add_basemap("ROADMAP")
m.to_streamlit(height=700)
97 changes: 97 additions & 0 deletions apps/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os
import geopandas as gpd
import streamlit as st


def save_uploaded_file(file_content, file_name):
"""
Save the uploaded file to a temporary directory
"""
import tempfile
import os
import uuid

_, file_extension = os.path.splitext(file_name)
file_id = str(uuid.uuid4())
file_path = os.path.join(tempfile.gettempdir(), f"{file_id}{file_extension}")

with open(file_path, "wb") as file:
file.write(file_content.getbuffer())

return file_path


def app():

st.title("Upload Vector Data")

row1_col1, row1_col2 = st.columns([2, 1])
width = 950
height = 600

with row1_col2:

backend = st.selectbox(
"Select a plotting backend", ["folium", "kepler.gl", "pydeck"], index=2
)

if backend == "folium":
import leafmap.foliumap as leafmap
elif backend == "kepler.gl":
import leafmap.kepler as leafmap
elif backend == "pydeck":
import leafmap.deck as leafmap

url = st.text_input(
"Enter a URL to a vector dataset",
"https://github.com/giswqs/streamlit-geospatial/raw/master/data/us_states.geojson",
)

data = st.file_uploader(
"Upload a vector dataset", type=["geojson", "kml", "zip", "tab"]
)

container = st.container()

if data or url:
if data:
file_path = save_uploaded_file(data, data.name)
layer_name = os.path.splitext(data.name)[0]
elif url:
file_path = url
layer_name = url.split("/")[-1].split(".")[0]

with row1_col1:
if file_path.lower().endswith(".kml"):
gpd.io.file.fiona.drvsupport.supported_drivers["KML"] = "rw"
gdf = gpd.read_file(file_path, driver="KML")
else:
gdf = gpd.read_file(file_path)
lon, lat = leafmap.gdf_centroid(gdf)
if backend == "pydeck":

column_names = gdf.columns.values.tolist()
random_column = None
with container:
random_color = st.checkbox("Apply random colors", True)
if random_color:
random_column = st.selectbox(
"Select a column to apply random colors", column_names
)

m = leafmap.Map(center=(40, -100))
# m = leafmap.Map(center=(lat, lon))
m.add_gdf(gdf, random_color_column=random_column)
st.pydeck_chart(m)

else:
m = leafmap.Map(center=(lat, lon), draw_export=True)
m.add_gdf(gdf, layer_name=layer_name)
if backend == "folium":
m.zoom_to_gdf(gdf)
m.to_streamlit(width=width, height=height)

else:
with row1_col1:
m = leafmap.Map()
st.pydeck_chart(m)
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Streamlit Web App</title>
<style type="text/css">
html {
overflow: auto;
}
html,
body,
div,
iframe {
margin: 0px;
padding: 0px;
height: 100%;
border: none;
}
iframe {
display: block;
width: 100%;
border: none;
overflow-y: auto;
overflow-x: hidden;
}
</style>
</head>
<body>
<iframe
src="https://share.streamlit.io/giswqs/streamlit-template"
frameborder="0"
marginheight="0"
marginwidth="0"
width="100%"
height="100%"
scrolling="auto"
allow="geolocation"
>
</iframe>
</body>
</html>
6 changes: 6 additions & 0 deletions packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ffmpeg
gifsicle
build-essential
python3-dev
gdal-bin
libgdal-dev
6 changes: 6 additions & 0 deletions postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# enable nbserverproxy
jupyter serverextension enable --sys-prefix nbserverproxy
# streamlit launches at startup
mv streamlit_call.py ${NB_PYTHON_PREFIX}/lib/python*/site-packages/
# enable streamlit extension
jupyter serverextension enable --sys-prefix streamlit_call
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--find-links=https://girder.github.io/large_image_wheels GDAL
geemap
geopandas
jupyter-server-proxy
keplergl
leafmap
localtileserver
nbserverproxy
streamlit
streamlit-option-menu

18 changes: 18 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update
# sudo apt-get update
# sudo apt-get install python3-dev
# sudo apt-get install gdal-bin
# sudo apt-get install libgdal-dev
# export CPLUS_INCLUDE_PATH=/usr/include/gdal
# export C_INCLUDE_PATH=/usr/include/gdal
# gdal-config --version
# pip install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}') localtileserver

mkdir -p ~/.streamlit/
echo "\
[server]\n\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
\n\
" > ~/.streamlit/config.toml
Loading

0 comments on commit 6ce9dd0

Please sign in to comment.