File: test_ndarrays.py

package info (click to toggle)
python-shapely 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,528 kB
  • sloc: python: 18,648; ansic: 6,615; makefile: 88; sh: 62
file content (42 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (3)
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),
        ]