xarray-contrib / xvec

Vector data cubes for Xarray
https://xvec.readthedocs.io
MIT License
89 stars 9 forks source link

Don't set crs in attrs. #71

Open dcherian opened 1 month ago

dcherian commented 1 month ago

Currently the crs is duplicated in attrs and on the index.

The edge-case to handle is when you select with a scalar the index is dropped. In this case we may want to set it on the variable attrs in IndexSelResult.

This commit is a good starting point.

martinfleis commented 1 month ago

I think I know the reason we originally did this. When selecting via a scalar coordinate from GeometryIndex, the result no longer has an index along the dimension, hence loses information on CRS. So when using the traffic_dataset from our tests

ds = traffic_dataset.sel(
    origin=shapely.Point(1, 2), day="2023-01-01", mode="car"
)

ds no longer contains any information on CRS of origin if we don't set attrs["CRS"]. I am not sure if it is a good enough reason to keep assigning it. In our tests this pops out in conversion to a GeoDataFrame, where resulting origin GeoSeries does not have a CRS assigned.

dcherian commented 1 month ago

Yes I think this is where the CRSIndex idea is useful. It can always be tied to a scalar spatial_ref variable and propagated.