-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
59 lines (47 loc) · 1.62 KB
/
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
import json
from json.decoder import JSONDecodeError
import folium
import streamlit as st
from folium.plugins import Fullscreen
from localtileserver import RemoteTileClient, get_folium_tile_layer
from localtileserver.validate import (ValidateCloudOptimizedGeoTIFFException,
validate_cog)
from streamlit_folium import folium_static
st.set_page_config(page_title="streamlit-remotetileserver")
"# streamlit-remotetileserver"
url = st.text_input(
"Input a URL, try: https://data.kitware.com/api/v1/file/626854a14acac99f42126a74/download",
placeholder="https://data.kitware.com/api/v1/file/626854a14acac99f42126a74/download",
)
with st.expander("Styling"):
style_text = st.text_area(
"Style dictionary",
help="https://girder.github.io/large_image/tilesource_options.html#style",
)
style = None
if style_text:
try:
style = json.loads(style_text)
except JSONDecodeError:
st.warning("Style is not valid JSON")
if url:
client = RemoteTileClient(url)
layer = get_folium_tile_layer(client, style=style)
try:
is_valid = validate_cog(client)
except ValidateCloudOptimizedGeoTIFFException:
is_valid = False
st.write(f"Is valid Cloud Optimized GeoTiff?: {is_valid}")
m = folium.Map(location=client.center(), zoom_start=client.default_zoom)
m.add_child(layer)
with st.sidebar:
st.image(str(client.thumbnail()))
st.write("Metadata")
st.json(client.metadata())
else:
with st.sidebar:
pass
m = folium.Map()
Fullscreen().add_to(m)
# call to render Folium map in Streamlit
folium_static(m)