georaster-layer-for-leaflet icon indicating copy to clipboard operation
georaster-layer-for-leaflet copied to clipboard

Serialization of a layer

Open martinhschei opened this issue 4 years ago • 1 comments

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"

martinhschei avatar Mar 24 '21 09:03 martinhschei

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:

  • How are you originally constructing the GeoRaster object? Are you passing an ArrayBuffer or a GeoTIFF into parseGeoraster or something else? How are you fetching the large amount of data through a GET request to localhost or file input?
  • How many GB? In theory georaster-layer-for-leaflet should be able to handle layers of many GBs if the computer's memory supports it. However, I have run into max array length issues in the past when trying to serialize large GeoTIFFs. (Not sure that's an issue, but still could be).

Thanks for your patience as we sort this out!

DanielJDufour avatar Mar 25 '21 13:03 DanielJDufour