Hello, so I am new to Streamlit and the whole process of hosting GIS-based tools online, and I am wondering if I might be able to use Streamlit through python to implement some sort of raster calculator functionality to create in-real-time rendered raster layers that are the result of a simple raster calculator operation, such as one might create with the raster calculator in ArcGIS or QGIS. The basic goal functionality I am trying to achieve is to allow the user to layer raster layer “tiles” over one another and allow the user to perform calculations across these layers to produce and view a resultant output raster tile. I am trying to figure out if this is possible using Streamlit, or if this type of functionality is at all even possible.
For example, let’s say we have a base map layer of a city. Over that layer we have a raster layer “tile”, whether a .PNG file or a .tiff file, which we overlay onto our base map, let’s say this layer represents total air exposure to a certain airborne chemical, where the pixel values are some concentration value. Now let’s say we have many, many of these pollution concentration raster tiles, where each raster layer represents a different chemical. I want to create a function that allows the user to add raster tiles together, so as to capture combined total pollution concentration. This means the user would load a tile for pollution “A” concentration and then the user to be able to add a tile for pollution “B” concentration over that, or pollution “C” concentration over that, and many more beyond, in whatever combination the user wanted. The exact science concept here is not important, what I am getting at is trying to find a way to do a simple raster math operation like take to raster layer tiles and simply add, or subtract, or average, etc. and display the output raster on the map.
Is this type of functionality possible with Streamlit through some sort of python protocol, perhaps using numpy behind the scenes? I am quite confused about how something like this would even work or whether this is even possible with a platform like Streamlit. Could someone please help advise me on how I should approach this challenge? Thank you!
Hello, thanks for responding. Yes, I understand that raster processing modules like ‘rasterio’ can be used for manipulating and producing raster files based on numpy operations, and this is what I would typically use for raster generation, but only from running code blocks individually, one at a time. I do not know how to create this type of functionality over a web app so that the user can create these rasters over an interactive map dynamically in real time, and this is what I was hoping I could do through Sreamlit.
I don’t think I understand your issue. Typically you would encapsulate that functionality in a function or a method. and you would call it whenever a new raster needs to be produced.
Hello, thank you for your reply. My apologies for not stating my question as clearly as it could be. Essentially I am asking if I have python code that creates a raster within a function, would I then be able to use this raster function with an interactive streamlit map? For example, if I load a building footprint shapefile into an interactive map, can I create some sort of streamlit functionality where I can click on one of the building footprint shapes, and I could for example create a raster resembling a buffer around the building shape. Yes, the raster buffer is created with python, but specifically I am having trouble figuring out how to “call” this function from within the streamlit app. In other words, within the streamlit interace, I can map and toggle-on/off vector and raster layers, but I cannot figure out how to actually create rasters interactively (e.g. by clicking on a shape in the interactive map). Perhaps I could share my code?
I think the tricky part here would be detecting the clicks and passing them back to the application along with the relevant data (like what feature was clicked). I don’t think any of the builtin widgets provide such functionality.
There is a third-party component called streamlit-folium, IIUC it allows you to show maps with custom layers and define callbacks for user actions, so it might suit your needs. I don’t have much access to computers these days so I am unable to take a deeper look myself.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.