File: test_shared_paths.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 (45 lines) | stat: -rw-r--r-- 1,434 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
import unittest

import pytest

from shapely.errors import GeometryTypeError
from shapely.geometry import GeometryCollection, LineString, MultiLineString, Point
from shapely.ops import shared_paths


class SharedPaths(unittest.TestCase):
    def test_shared_paths_forward(self):
        g1 = LineString([(0, 0), (10, 0), (10, 5), (20, 5)])
        g2 = LineString([(5, 0), (15, 0)])
        result = shared_paths(g1, g2)

        assert isinstance(result, GeometryCollection)
        assert len(result.geoms) == 2
        a, b = result.geoms
        assert isinstance(a, MultiLineString)
        assert len(a.geoms) == 1
        assert a.geoms[0].coords[:] == [(5, 0), (10, 0)]
        assert b.is_empty

    def test_shared_paths_forward2(self):
        g1 = LineString([(0, 0), (10, 0), (10, 5), (20, 5)])
        g2 = LineString([(15, 0), (5, 0)])
        result = shared_paths(g1, g2)

        assert isinstance(result, GeometryCollection)
        assert len(result.geoms) == 2
        a, b = result.geoms
        assert isinstance(b, MultiLineString)
        assert len(b.geoms) == 1
        assert b.geoms[0].coords[:] == [(5, 0), (10, 0)]
        assert a.is_empty

    def test_wrong_type(self):
        g1 = Point(0, 0)
        g2 = LineString([(5, 0), (15, 0)])

        with pytest.raises(GeometryTypeError):
            shared_paths(g1, g2)

        with pytest.raises(GeometryTypeError):
            shared_paths(g2, g1)