Skip to content

Commit 583c416

Browse files
Fix for shapely 2.0 (#386)
* Fix for shapely 2.0 - upd whats new * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use instance check instead of attr check Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2b8b4fd commit 583c416

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cf_xarray/geometry.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def points_to_cf(pts: Union[xr.DataArray, Sequence]):
185185
A Dataset with variables 'x', 'y', 'crd_x', 'crd_y', 'node_count' and 'geometry_container'.
186186
The coordinates of MultiPoint instances are their first point.
187187
"""
188+
from shapely.geometry import MultiPoint
189+
188190
if isinstance(pts, xr.DataArray):
189191
dim = pts.dims[0]
190192
coord = pts[dim] if dim in pts.coords else None
@@ -195,7 +197,10 @@ def points_to_cf(pts: Union[xr.DataArray, Sequence]):
195197

196198
x, y, node_count, crdX, crdY = [], [], [], [], []
197199
for pt in pts:
198-
xy = np.atleast_2d(np.array(pt))
200+
if isinstance(pt, MultiPoint):
201+
xy = np.concatenate([p.coords for p in pt.geoms])
202+
else:
203+
xy = np.atleast_2d(pt.coords)
199204
x.extend(xy[:, 0])
200205
y.extend(xy[:, 1])
201206
node_count.append(xy.shape[0])

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
What's New
44
----------
55

6+
v0.7.7 (Unreleased)
7+
===================
8+
- Fix to ``geometry.points_to_cf`` to support shapely 2.0. (:pr:`386`).
9+
By `Pascal Bourgault`_
10+
611
v0.7.6 (Dec 07, 2022)
712
=====================
813

0 commit comments

Comments
 (0)