Skip to content

Commit 18db70a

Browse files
authored
Merge pull request SciTools#1406 from kacmak7/i/1349
Fix geometry_length method
2 parents 9b90b69 + d04a951 commit 18db70a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

docs/source/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ the package wouldn't be as rich or diverse as it is today:
3939
* Robert Redl
4040
* Greg Lucas
4141
* Sadie Bartholomew
42+
* Kacper Makuch
4243

4344
Thank you!
4445

lib/cartopy/geodesic/_geodesic.pyx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2015 - 2018, Met Office
1+
# (C) British Crown Copyright 2015 - 2020, Met Office
22
#
33
# This file is part of cartopy.
44
#
@@ -271,13 +271,8 @@ cdef class Geodesic:
271271
# Polygon.
272272
result = self.geometry_length(geometry.exterior)
273273

274-
elif hasattr(geometry, 'coords'):
274+
elif hasattr(geometry, 'coords') and not isinstance(geometry, sgeom.Point):
275275
coords = np.array(geometry.coords)
276-
277-
# LinearRings are (N, 2), whereas LineStrings are (2, N).
278-
if not isinstance(geometry, sgeom.LinearRing):
279-
coords = coords.T
280-
281276
result = self.geometry_length(coords)
282277

283278
elif isinstance(geometry, np.ndarray):

lib/cartopy/tests/test_geodesic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2015 - 2019, Met Office
1+
# (C) British Crown Copyright 2015 - 2020, Met Office
22
#
33
# This file is part of cartopy.
44
#
@@ -151,16 +151,16 @@ def test_geometry_length_ndarray():
151151

152152
def test_geometry_length_linestring():
153153
geod = geodesic.Geodesic()
154-
geom = sgeom.LineString(np.array([lhr, jfk, lhr]).T)
154+
geom = sgeom.LineString(np.array([lhr, jfk, lhr]))
155155
expected = pytest.approx(lhr_to_jfk * 2, abs=1)
156156
assert geod.geometry_length(geom) == expected
157157

158158

159159
def test_geometry_length_multilinestring():
160160
geod = geodesic.Geodesic()
161161
geom = sgeom.MultiLineString(
162-
[sgeom.LineString(np.array([lhr, jfk]).T),
163-
sgeom.LineString(np.array([tul, jfk]).T)])
162+
[sgeom.LineString(np.array([lhr, jfk])),
163+
sgeom.LineString(np.array([tul, jfk]))])
164164
expected = pytest.approx(lhr_to_jfk + jfk_to_tul, abs=1)
165165
assert geod.geometry_length(geom) == expected
166166

@@ -182,5 +182,5 @@ def test_geometry_length_polygon():
182182
def test_geometry_length_point():
183183
geod = geodesic.Geodesic()
184184
geom = sgeom.Point(lhr)
185-
with pytest.raises(ValueError):
185+
with pytest.raises(TypeError):
186186
geod.geometry_length(geom)

0 commit comments

Comments
 (0)