1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
# Tests of support for Numpy ndarrays. See
# https://github.com/sgillies/shapely/issues/26 for discussion.
import unittest
from functools import reduce
import numpy as np
from shapely import geometry
class TransposeTestCase(unittest.TestCase):
def test_multipoint(self):
arr = np.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
tarr = arr.T
shape = geometry.MultiPoint(tarr)
coords = reduce(lambda x, y: x + y, [list(g.coords) for g in shape.geoms])
assert coords == [(1.0, 3.0), (1.0, 4.0), (2.0, 4.0), (2.0, 3.0), (1.0, 3.0)]
def test_linestring(self):
a = np.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
t = a.T
s = geometry.LineString(t)
assert list(s.coords) == [
(1.0, 3.0),
(1.0, 4.0),
(2.0, 4.0),
(2.0, 3.0),
(1.0, 3.0),
]
def test_polygon(self):
a = np.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
t = a.T
s = geometry.Polygon(t)
assert list(s.exterior.coords) == [
(1.0, 3.0),
(1.0, 4.0),
(2.0, 4.0),
(2.0, 3.0),
(1.0, 3.0),
]
|