After a bit of tinkering I got something working, sortof
It’s probably super inefficient but at least it works; based on your work @randyzwitch on streamlit-folium and rasterio:
import streamlit as st
from streamlit_folium import folium_static
import numpy as np
# A dummy Sentinel 2 COG I had laying around
tif = "streamlit_app/WGS84_S2_image.tif"
# This is probably hugely inefficient, but it works. Opens the COG as a numpy array
src = rasterio.open(tif)
array = src.read()
bounds = src.bounds
x1,y1,x2,y2 = src.bounds
bbox = [(bounds.bottom, bounds.left), (bounds.top, bounds.right)]
# center on Liberty Bell
m = folium.Map(location=[14.59, 120.98], zoom_start=6)
# add marker for Liberty Bell
tooltip = "Manilla city"
[14.599512, 120.984222], popup="This is it!", tooltip=tooltip
img = folium.raster_layers.ImageOverlay(
image=np.moveaxis(array, 0, -1),
# folium.Popup("I am an image").add_to(img)
# call to render Folium map in Streamlit
Now this is far from perfect of course but I think it should do the tricky for some very basic visualization at least.
I’d love to hear more about how this could be improved
I would imagine:
- No need to save the raster as COG here, all that is need is 1. the array, 2. the bounding box. Those can be saved seperately, for something that gets open in Python a lot faster than using
rasterio. Maybe a PNG is the way to go then?
if this isn’t clear yet I’m in the process of learning anything having to do with frontend and webapp