-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_linemerge.py
52 lines (42 loc) · 1.55 KB
/
test_linemerge.py
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
from . import unittest
from shapely.geometry import LineString, MultiLineString
from shapely.ops import linemerge
class LineMergeTestCase(unittest.TestCase):
def test_linemerge(self):
lines = MultiLineString(
[((0, 0), (1, 1)),
((2, 0), (2, 1), (1, 1))])
result = linemerge(lines)
self.assertIsInstance(result, LineString)
self.assertFalse(result.is_ring)
self.assertEqual(len(result.coords), 4)
self.assertEqual(result.coords[0], (0.0, 0.0))
self.assertEqual(result.coords[3], (2.0, 0.0))
lines2 = MultiLineString(
[((0, 0), (1, 1)),
((0, 0), (2, 0), (2, 1), (1, 1))])
result = linemerge(lines2)
self.assertTrue(result.is_ring)
self.assertEqual(len(result.coords), 5)
lines3 = [
LineString(((0, 0), (1, 1))),
LineString(((0, 0), (0, 1))),
]
result = linemerge(lines3)
self.assertFalse(result.is_ring)
self.assertEqual(len(result.coords), 3)
self.assertEqual(result.coords[0], (0.0, 1.0))
self.assertEqual(result.coords[2], (1.0, 1.0))
lines4 = [
((0, 0), (1, 1)),
((0, 0), (0, 1)),
]
self.assertTrue(result.equals(linemerge(lines4)))
lines5 = [
((0, 0), (1, 1)),
((1, 0), (0, 1)),
]
result = linemerge(lines5)
self.assertEqual(result.type, 'MultiLineString')
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(LineMergeTestCase)