courtiol / IsoriX

This is the website dedicated to the development of the R package IsoriX
12 stars 5 forks source link

Need methods to store objects #172

Closed courtiol closed 8 months ago

courtiol commented 9 months ago

Problem

It is no longer possible to directly save objects created by IsoriX onto the hard drive with terra.

Context

When relying on raster it was possible to save objects created by IsoriX onto the hard drive as *.rda or *.rds.

Objects created by IsoriX are composite in the sense that they may contain rasters, spatial vectors, and non-spatial info all bundled together as a list.

Those list cannot be saved with terra since this package has functions designed to save rasters or vectors specifically and no function to store any kinds of composite.

This matters for users because spatial objects created by IsoriX can be very slow to create. This also matters to me for editing the bookdown.

Solution

Turning files into binaries ("serialisation") does not seem to be a recommended practice for spatial objects, and even with raster it led to issues if the values were not stored in memory.

So the solution seems to implement methods to save specific classes of IsoriX-created objects. These methods would create a folder with a particular structure within which the different parts of the objects would be saved separately.

We would also have methods to read these folders so as to recreate the IsoriX objects.

Objects created in IsoriX containing spatial data

Open questions

courtiol commented 9 months ago

@rhijmans, if you have thoughts, please share them with us :-)

rhijmans commented 9 months ago

I think you can define a saveRDS method for these objects. These can then call terra::wrap for SpatRaster/SpatVector objects before calling base::saveRDS. That is what terra does for saveRDS<SpatVector> and saveRDS<SpatRaster>. And do the inverse for readRDS.