Skip to content

Commit c17bc4d

Browse files
committed
Add docs
1 parent f21cecd commit c17bc4d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

cf_xarray/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
from .options import set_options # noqa
1010
from .utils import _get_version
1111

12+
from . import geometry # noqa
13+
1214
__version__ = _get_version()

doc/api.rst

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ Top-level API
1717
encode_multi_index_as_compress
1818
decode_compress_to_multi_index
1919

20+
Geometries
21+
----------
22+
.. autosummary::
23+
:toctree: generated/
24+
25+
geometry.decode_geometries
26+
geometry.encode_geometries
27+
geometry.shapely_to_cf
28+
geometry.cf_to_shapely
29+
2030
.. currentmodule:: xarray
2131

2232
DataArray

doc/geometry.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,30 @@ da = xr.DataArray(
5050
geometries of the same type.
5151
```
5252

53-
Now we can take that `xr.DataArray` containing shapely geometries and convert it to cf:
53+
## Encode / Decode
54+
55+
`cf-xarray` provides {py:func}`geometry.encode_geometries` and {py:func}`geometry.decode_geometries` to
56+
encode and decode xarray Datasets to/from a CF-compliant form that can be written to any array storage format.
57+
58+
For example:
59+
60+
```{code-cell}
61+
ds = da.to_dataset()
62+
encoded = cfxr.geometry.encode_geometries(ds)
63+
encoded
64+
```
65+
66+
This dataset can then be written to any format supported by Xarray.
67+
To decode, reverse the process using {py:func}`geometry.decode_geometries`
68+
69+
```{code-cell}
70+
decoded = cfxr.geometry.decode_geometries(encoded)
71+
ds.identical(decoded)
72+
```
73+
74+
## Lower-level conversions
75+
76+
Encoding a single DataArray is possible using {py:func}`cf_xarray.geometry.shapely_to_cf`.
5477

5578
```{code-cell}
5679
ds_cf = cfxr.shapely_to_cf(da)
@@ -94,6 +117,6 @@ By default these are called `crd_x` and `crd_y` unless `grid_mapping` is specifi
94117

95118
For MultiPolygons with holes the CF notation is slightly ambiguous on which hole is associated
96119
with which polygon. This is problematic because shapely stores holes within the polygon
97-
object that they are associated with. `cf_xarray` assumes that the the shapes are interleaved
120+
object that they are associated with. `cf_xarray` assumes that the shapes are interleaved
98121
such that the holes (interior rings) are associated with the exteriors (exterior rings) that
99122
immediately precede them.

0 commit comments

Comments
 (0)