test_snap.py 763 B

123456789101112131415161718192021222324
  1. import unittest
  2. from shapely.geometry import LineString, Polygon
  3. from shapely.ops import snap
  4. class Snap(unittest.TestCase):
  5. def test_snap(self):
  6. # input geometries
  7. square = Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])
  8. line = LineString([(0, 0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)])
  9. square_coords = square.exterior.coords[:]
  10. line_coords = line.coords[:]
  11. result = snap(line, square, 0.5)
  12. # test result is correct
  13. assert isinstance(result, LineString)
  14. assert result.coords[:] == [(0.0, 0.0), (1.0, 1.0), (2.0, 1.0), (2.6, 0.5)]
  15. # test inputs have not been modified
  16. assert square.exterior.coords[:] == square_coords
  17. assert line.coords[:] == line_coords