Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow encoding/decoding multiple geometries #526

Merged
merged 13 commits into from
Jul 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Docs
dcherian committed Jul 17, 2024
commit f92f098802b81025ae69b31a8631e34e894ed672
7 changes: 1 addition & 6 deletions cf_xarray/geometry.py
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ def _get_geometry_containers(obj: xr.DataArray | xr.Dataset) -> list[Hashable]:

def decode_geometries(encoded: xr.Dataset) -> xr.Dataset:
"""
Decode CF encoded geometries to a numpy object array containing shapely geometries.
Decode CF encoded geometries to numpy object arrays containing shapely geometries.

Parameters
----------
@@ -255,11 +255,6 @@ def encode_geometries(ds: xr.Dataset):
Practically speaking, geometry variables are numpy object arrays where the first
element is a shapely geometry.

.. warning::

Only a single geometry variable is supported at present. Contributions to fix this
are welcome.

Parameters
----------
ds : Dataset
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ Geometries
geometry.encode_geometries
geometry.shapely_to_cf
geometry.cf_to_shapely
geometry.GeometryNames

.. currentmodule:: xarray

5 changes: 2 additions & 3 deletions doc/geometry.md
Original file line number Diff line number Diff line change
@@ -97,9 +97,8 @@ ds.identical(decoded)

The following limitations can be relaxed in the future. PRs welcome!

1. cf-xarray uses `"geometry_container"` as the name for the geometry variable always
1. cf-xarray only supports decoding a single geometry in a Dataset.
1. CF xarray will not set the `"geometry"` attribute that links a variable to a geometry by default unless the geometry variable is a dimension coordiante for that variable. This heuristic works OK for vector data cubes (e.g. [xvec](https://xvec.readthedocs.io/en/stable/)). You should set the `"geometry"` attribute manually otherwise. Suggestions for better behaviour here are very welcome.
1. cf-xarray uses `"geometry_container"` as the name for the geometry variable always. If there are multiple geometry variables then `"geometry_N"`is used where N is an integer >= 0. cf-xarray behaves similarly for all associated geometry variables names: i.e. `"node"`, `"node_count"`, `"part_node_count"`, `"part"`, `"interior_ring"`. `"x"`, `"y"` (with suffixes if needed) are always the node coordinate variable names, and `"crd_x"`, `"crd_y"` are the nominal X, Y coordinate locations. None of this is configurable at the moment.
1. CF xarray will not set the `"geometry"` attribute that links a variable to a geometry by default unless the geometry variable is a dimension coordinate for that variable. This heuristic works OK for vector data cubes (e.g. [xvec](https://xvec.readthedocs.io/en/stable/)). You should set the `"geometry"` attribute manually otherwise. Suggestions for better behaviour here are very welcome.

## Lower-level conversions