GeoTIFF / georaster-layer-for-leaflet

Display GeoTIFFs and soon other types of raster on your Leaflet Map
https://geotiff.github.io/georaster-layer-for-leaflet-example/
Apache License 2.0
284 stars 57 forks source link

Serialization of a layer #61

Open martinhschei opened 3 years ago

martinhschei commented 3 years ago

Is your feature request related to a problem? Please describe. Not a problem - more a request for assistance/feature.

I'm reading quite heavy files from disk (GB++) and i want to save the rendered raster layer on disk for use next time the user wants to view it. I simply save the result from new geoRasterLayer() as a JSON; JSON.stringify(layer). When it's time to read the file from disk i can't seem to assemble the layer from the object created from the previously saved raster layer.

Describe the solution you'd like I would like the possibility to do this:

// first time this TIFF is used
let layer = new geoRasterLayer(options);
geoRasterLayer.writeLayerToDisk(path, layer);

// next time this layer will be used (hours or days later)
let layer = geoRasterLayer.readLayerFromDisk(path);
this.map.addLayer(layer);

I can see that this approach might be beyond the scope of this package; so the next best solution would be to create a new layer from a simple object that was previously written to file in JSON;

// first time this TIFF is used
let layer = new geoRasterLayer(options);
fs.writeFile(JSON.stringify(path), layer);

// next time this layer will be used (hours or days later)
let cachedLayer = JSON.parse(fs.readFile(path));
let layer = new geoRasterLayer(cachedLayer);
this.map.addLayer(layer);

Describe alternatives you've considered I have tried the second approach but i get errors like: "The provided object is not a Layer." "You must initialize a GeoRasterLayer with a georaster or georasters value"

DanielJDufour commented 3 years ago

Hi, @martinhschei . This is a great question. I definitely think it's within scope of the package!

I think we will a few options, but it depends on answers to a couple questions:

Thanks for your patience as we sort this out!