Ejemplo n.º 1
0
 def test_merge_multilines(self):
     x = np.arange(5)
     y = np.arange(5, 10)
     mp1 = Multiline([list(zip(x, y)),
                      list(zip(-x, -y)),
                      list(zip(x, -y))],
                     properties={
                         "a": 1,
                         "b": 2
                     },
                     data={
                         "A": np.arange(5),
                         "B": np.arange(10, 15)
                     })
     mp2 = Multiline(
         [list(zip(x, 2 * y)),
          list(zip(-2 * x, y)),
          list(zip(1.5 * x, y))],
         properties={
             "a": 1,
             "c": 3
         },
         data={
             "A": np.arange(5),
             "C": np.arange(15, 20)
         })
     mp = merge_multiparts(mp1, mp2)
     self.assertTrue(len(mp), 10)
     self.assertEqual(set(mp.data.fields), set(["A"]))
     self.assertEqual(set(mp.properties.keys()), set(["a", "b", "c"]))
     self.assertEqual(mp.properties["a"], 1)
Ejemplo n.º 2
0
    def test_merge_lines(self):
        ml1 = Multiline([[(1, 2), (3, 4), (5, 6)], [(3, 4), (2, 3)]])
        ln1 = Line([(5, 6, 1), (5, 4, 2), (4, 3, 0)])
        ml2 = Multiline([[(4, 2), (8, 4), (1, 5)], [(2, 4), (8, 6)]])
        ln2 = Line([(5, 6), (4, 7), (3, 9), (4, 9)])

        merged = Multiline.merge(ml1, ln1, ml2, ln2)
        self.assertEqual(len(merged), 6)
        self.assertEqual(merged.vertices[0].asarray().shape, (3, 2))
        self.assertEqual(merged.vertices[1].asarray().shape, (2, 2))
Ejemplo n.º 3
0
 def test_merge_multilines(self):
     x = np.arange(5)
     y = np.arange(5, 10)
     mp1 = Multiline([list(zip(x, y)), list(zip(-x, -y)), list(zip(x, -y))],
                      data={"A": np.arange(3), "B": np.arange(10, 13)})
     mp2 = Multiline([list(zip(x, 2*y)), list(zip(-2*x, y)), list(zip(1.5*x, y))],
                      data={"A": np.arange(3), "C": np.arange(15, 18)})
     ml = Multiline.merge(mp1, mp2)
     self.assertTrue(len(ml), 10)
     self.assertEqual(set(ml.data.fields), set(["A"]))
Ejemplo n.º 4
0
    def test_multiline(self):
        vertices = []
        data = {"a": []}
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            vertices.append(sub)
            data["a"].append(i * j)

        Multiline(vertices, data=data)
Ejemplo n.º 5
0
    def test_multiline_from_lines(self):
        lines = []
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            lines.append(Line(sub, properties={"d": i * j}, crs=LonLatWGS84))

        g = Multiline(lines)
        self.assertEqual(g.d["d"], [0, 4, 8, 12, 16])
        self.assertEqual(g.crs, LonLatWGS84)
Ejemplo n.º 6
0
 def test_merge_multilines(self):
     x = np.arange(5)
     y = np.arange(5, 10)
     mp1 = Multiline([list(zip(x, y)),
                      list(zip(-x, -y)),
                      list(zip(x, -y))],
                     data={
                         "A": np.arange(3),
                         "B": np.arange(10, 13)
                     })
     mp2 = Multiline(
         [list(zip(x, 2 * y)),
          list(zip(-2 * x, y)),
          list(zip(1.5 * x, y))],
         data={
             "A": np.arange(3),
             "C": np.arange(15, 18)
         })
     ml = Multiline.merge(mp1, mp2)
     self.assertTrue(len(ml), 10)
     self.assertEqual(set(ml.data.fields), set(["A"]))
Ejemplo n.º 7
0
    def test_multiline_from_lines_constructor(self):
        lines = []
        for i in range(5):
            sub = []
            for j in range(5):
                sub.append((2 * j + i, -1.5 * j + 2 * i))
            lines.append(Line(sub, crs=LonLatWGS84))

        g = Multiline(lines)
        for l, l_ in zip(g, lines):
            self.assertTrue(np.all(l.vertices() == l_.vertices()))
        self.assertEqual(g.crs, LonLatWGS84)
Ejemplo n.º 8
0
 def test_empty_multiline(self):
     ml = Multiline([])
     self.assertEqual(len(ml), 0)
     return