Hi all,
I would need to visualise large geospatial datasets in GeoTiff format. Does streamlit work well with that? Does anyone have an example or tutorial that I could look at?
Many thanks
Hi all,
I would need to visualise large geospatial datasets in GeoTiff format. Does streamlit work well with that? Does anyone have an example or tutorial that I could look at?
Many thanks
These can be displayed as a jpg, or do you need to keep the high resolution/file format?
Unfortunately jpg won’t do for me. I need to retain the high resolution file and format.
Sounds quite specialised. I would suggest also searching for examples where people have worked with medical imagery, which has similar specialised requirements
Per StackOverflow, it sounds like TIFF files are not well supported in browsers:
I tried this in Chrome (5MB tif, guess it depends on what is “large”) and it didn’t render:
import streamlit as st
st.markdown("")
I don’t have a Mac to test on for Safari, but if it’s going to work, I think this is how you would do it.
Best,
Randy
Hi Randy, thanks for the link. Yes, it seems there are some issues rendering the .tiff files.
You can use Pillow to load the tiff, then display it directly or convert to png. If the issue is that the file is very large, you could convert it to a cloud optimised geotiff (COG) as these support range requests. You could then display one of the downsampled tiles
@randyzwitch Can I upload GeoTiff files using streamlit.file_uploader() function in streamlit?
Why not? It just depends how large they are and what you want to do with them afterwards.
Can you please share some code sample. The size is 100MB. I have to later use that GeoTiff in my code. So how should I use it ? How to access the data of GeoTiff image ?
How would you have worked with the GeoTiff image in Python if you weren’t using Streamlit?
How to access the data of GeoTiff image ?
What Python package do you use to access the data of the GeoTiff image?
If can give me a code example (with an existing package) of how you intend to use and manipulate the GeoTiff image in Python, I could help you access the GeoTiff from the file uploader widget.
The file uploader docs show a few common examples of reading files uploaded via st.file_uploader
:
I want to load the numpy array of that GeoTiff image in python which I have uploaded. How should I do that? Geotiff image have a numpy array of shape (64,1200,1200). Please help me out with some code.
I want to load the numpy array of that GeoTiff image in python which I have uploaded. How should I do that? Geotiff image have a numpy array of shape (64,1200,1200). Please help me out with some code structure.
Have you even tried?
I would suggest: Read the documentation, look at the examples, try it yourself and if you get stuck, share your github link with us and we will help.
Yes I have tried but I am unable to do so.
I am not getting the original array which is of shape (64,1200,1200) but only a 1 dimension array of shape (47238183,).
I don’t know why!
Please share some code snippet. i am not able to do with documentation.
This is not a streamlit related question, it is numpy or geopython related.
Anyway, to give you some hints, what about:
y = np.frombuffer(bytes_data, dtype="float32").reshape(64, 1200, 1200)
If you cannot sort this out with the numpy
package, i assume you have to use some more sophisticated geopython related python packages, i would look into geotiff
or gdal
or rasterio
packages for a possible solution.
Every time the user give a new image to streamlit file_uploader, so every time the shape is different. So can you please provide a more general solution
for example: user can give any shape like this -
(12,1200,1345)
(15,1500,3422)
(16,34,12)
(100,452,313)
so infinite amount of shapes are possible.
Can you please help me out in this.
I gave you some hints for geo related libraries.
If you want to handle geo data you have to deal with this stuff anyway.
Just use google and stackoverflow and you will find a lot of approaches:
python read geotiff
Thanks it worked.
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.
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.
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.
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.