Closed codesian closed 5 years ago
Hi, @codesian . Thank you for your question!
There's a few ways you can do this. Let me know if one works. If not, I'm happy to write a new way for you :-)
Also, do you happen to be doing this in the browser on the frontend or using Node on the backend?
geoblaze actually already caches tiff files by default so if you run geoblaze.load on the same url, it won't load it multiple times. But it only caches it once it is successfully loaded though, so if you make a second request before the first completes, it won't work. I can rewrite this so it automatically creates an entry in the cache before the first complete to prevent multiple requests. For your reference, here's the source code that grabs the georaster from the cache.
const url = "https://s3.amazonaws.com/geoblaze/wildfires.tiff";
geoblaze.load(url);
// wait for url to load
geoblaze.load(url);
// there is no second request
geoblaze operates on georaster objects, which are simple wrappers around geotiff.js objects. Most people who use geoblaze actually don't directly use geotiff.js. They use geotiff.js indirectly through geoblaze.load. You can create and cache a georaster like so:
const url = "https://s3.amazonaws.com/geoblaze/wildfires.tiff";
geoblaze.load(url).then(georaster => {
// caches tiff globally
window.tiff = georaster;
});
// later on...
geoblaze.sum(window.tiff);
geoblaze.min(window.tiff);
geoblaze.max(window.tiff);
If the two ways above don't work, let me know and our community will write code that will help you :-) For example, geoblaze.load doesn't directly take in geotiff.js objects, but we can write code that could do this. Should we write the following code for you?
import GeoTIFF from 'geotiff';
const url = "https://s3.amazonaws.com/geoblaze/wildfires.tiff";
GeoTIFF.fromUrl(url).then(tiff => window.tiff = tiff);
// later in code
geoblaze.load(window.tiff).then(georaster => {
geoblaze.sum(georaster);
});
Let me know what you would like! Thanks for your interest :-)
Thanks @DanielJDufour for this great response! Im trying to do this on front end, a leaflet layer, with offline stats computation, and layers custom live renderings for drone aerial images.
Finally i remove geotiff.js tiff load process and replace it with geoblaze as you ask me, and change rendering algorithm done with geoblaze data instead with Float32array. I manually manage cache, just because i need my own cache control in a client persistent data store.
I have another question about get, and geometry intersection, i think its better to write it on another issue.
Thanks for your time, and your patience to elaborate this complex response, it helps me a lot!
Glad to hear it helped. If this issue is resolved, would you mind closing this issue? I also saw your new issue and will read and respond to that soon :-)
Sure, sorry and thanks!
Its possible to use a preloaded and cached TIF file on a Float32array from geotif.js to use it with geoblaze? In order to avoid load multiple times from url. How can i achieve that?
Thanks