File: test_operators.py

package info (click to toggle)
python-shapely 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,528 kB
  • sloc: python: 18,648; ansic: 6,615; makefile: 88; sh: 62
file content (60 lines) | stat: -rw-r--r-- 1,948 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import unittest

from shapely.geometry import LineString, MultiPoint, Point, Polygon


class OperatorsTestCase(unittest.TestCase):
    def test_point(self):
        point = Point(0, 0)
        point2 = Point(-1, 1)
        assert point.union(point2).equals(point | point2)
        assert (point & point2).is_empty
        assert point.equals(point - point2)
        assert point.symmetric_difference(point2).equals(point ^ point2)
        assert point != point2
        point_dupe = Point(0, 0)
        assert point, point_dupe

    def test_multipoint(self):
        mp1 = MultiPoint([(0, 0), (1, 1)])
        mp1_dup = MultiPoint([(0, 0), (1, 1)])
        mp1_rev = MultiPoint([(1, 1), (0, 0)])
        mp2 = MultiPoint([(0, 0), (1, 1), (2, 2)])
        mp3 = MultiPoint([(0, 0), (1, 1), (2, 3)])

        assert mp1 == mp1_dup
        assert mp1 != mp1_rev
        assert mp1 != mp2
        assert mp2 != mp3

        p = Point(0, 0)
        mp = MultiPoint([(0, 0)])
        assert p != mp
        assert mp != p

    def test_polygon(self):
        shell = ((0, 0), (3, 0), (3, 3), (0, 3))
        hole = ((1, 1), (2, 1), (2, 2), (1, 2))
        p_solid = Polygon(shell)
        p2_solid = Polygon(shell)
        p_hole = Polygon(shell, holes=[hole])
        p2_hole = Polygon(shell, holes=[hole])

        assert p_solid == p2_solid
        assert p_hole == p2_hole
        assert p_solid != p_hole

        shell2 = ((-5, 2), (10.5, 3), (7, 3))
        p3_hole = Polygon(shell2, holes=[hole])
        assert p_hole != p3_hole

    def test_linestring(self):
        line1 = LineString([(0, 0), (1, 1), (2, 2)])
        line2 = LineString([(0, 0), (2, 2)])
        line2_dup = LineString([(0, 0), (2, 2)])
        # .equals() indicates these are the same
        assert line1.equals(line2)
        # but != indicates these are different
        assert line1 != line2
        # but dupes are the same with ==
        assert line2 == line2_dup