saving and reading vector data cubes

Open
#26 35 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python, r
Domain
data

Research direction

Start by reproducing the reported write_stars failure with the example vector data cube, then read the CF geometry conventions and compare the shapely_to_cf and cfgeom approaches mentioned. The issue does not define a chosen format or implementation entry point; done would require an agreed interoperable storage approach and working round-trip wrappers for xvec-backed xarray objects.

Written by the indexing model from the issue text.

Description

At the moment, we have a decent set of functionality to work with in-memory vector data cubes. What we do not have is a way of saving them to a disk and reading back again, apart from using pickle which is not very interoperable.

We should find a way of saving to a file format that allows us interoperability with @edzer's stars in RSpatial. @edzer, you were mentioning that NetCDF is able to handle VDC. Does stars implements that? Can we create a data cube indexed by geometry and save it via GDAL to NetCDF? I tried only very briefly to play with the write_stars function to no avail[^1].

The spec for NetCDF way of storing geometries is here but as someone who never worked with the file format, it is not super clear to me how it all works together.

Over in Python, there is some work @dcherian posted on conversion of shapely geometries to CF geometries and back (https://cf-xarray.readthedocs.io/en/latest/generated/cf_xarray.shapely_to_cf.html) [^2]. There is also https://github.com/twhiteaker/cfgeom which may potentially be used (although it is only a reference implementation that is not maintained).

So it seems that NetCDF should be able to store vector data cubes and we may just need to figure out some wrappers for a convenient IO from xvec-backed xarray objects. But I'd welcome some help or at least a guidance from someone more familiar with CF conventions.

The other option seems to be Zarr as discussed here but that is at this stage only an idea and (Geo)Zarr spec is not ready as of now.

The last option is to convert the cube to a long-form dataframe and save it as a GeoParquet but that kind of breaks the point of having a cube in the first place.

[^1]: Getting Error in !all.equal(match(xydims, names(d)), 1:2) : invalid argument type when trying to use write_stars(st, 'test.nc') on the example cube from https://r-spatial.github.io/stars/articles/stars1.html#vector-data-cube-example.
[^2]: only points are implemented so far but that may change

Dominant language
Python
Stars
139
Forks
14
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xarray-contrib/xvec

All issues in xarray-contrib/xvec

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.