File: test_snap.py

package info (click to toggle)
python-shapely 2.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,564 kB
  • sloc: python: 18,650; ansic: 6,615; makefile: 88; sh: 62
file content (24 lines) | stat: -rw-r--r-- 763 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
import unittest

from shapely.geometry import LineString, Polygon
from shapely.ops import snap


class Snap(unittest.TestCase):
    def test_snap(self):
        # input geometries
        square = Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])
        line = LineString([(0, 0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)])

        square_coords = square.exterior.coords[:]
        line_coords = line.coords[:]

        result = snap(line, square, 0.5)

        # test result is correct
        assert isinstance(result, LineString)
        assert result.coords[:] == [(0.0, 0.0), (1.0, 1.0), (2.0, 1.0), (2.6, 0.5)]

        # test inputs have not been modified
        assert square.exterior.coords[:] == square_coords
        assert line.coords[:] == line_coords