Example #1
0
    def test_simplify_min(self):
        # A line
        x_data = [1, 2]
        y_data = [1, 2]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)

        # A line string
        x_data = [1, 2, 3]
        y_data = [1, 2, 3]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertEqual((sx.size, sy.size), (2, 2))
        self.assertEqual(list(sx), [1, 3])
        self.assertEqual(list(sy), [1, 3])

        # A square (ring)
        x_data = [1, 3, 3, 1, 1]
        y_data = [1, 1, 3, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertEqual((sx.size, sy.size), (4, 4))
        self.assertEqual(list(sx), [1, 3, 1, 1])
        self.assertEqual(list(sy), [1, 3, 3, 1])
Example #2
0
    def test_simplify_min(self):
        # A line
        x_data = [1, 2]
        y_data = [1, 2]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)

        # A line string
        x_data = [1, 2, 3]
        y_data = [1, 2, 3]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertEqual((sx.size, sy.size), (2, 2))
        self.assertEqual(list(sx), [1, 3])
        self.assertEqual(list(sy), [1, 3])

        # A square (ring)
        x_data = [1, 3, 3, 1, 1]
        y_data = [1, 1, 3, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 0.0)
        self.assertEqual((sx.size, sy.size), (4, 4))
        self.assertEqual(list(sx), [1, 3, 1, 1])
        self.assertEqual(list(sy), [1, 3, 3, 1])
Example #3
0
    def test_simplify_square(self):
        x_data = [1, 2, 3, 3, 3, 2, 1, 1, 1]
        y_data = [1, 1, 1, 2, 3, 3, 3, 2, 1]

        #
        #  3  o----o----o         3  o---------o
        #     |         |            |         |
        #  2  o         o   ==>   2  |         |
        #     |         |            |         |
        #  1  o----o----o         1  o---------o
        #     1    2    3            1    2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 5. / 9.)
        self.assertEqual((sx.size, sy.size), (5, 5))
        self.assertEqual(list(sx), [1, 3, 3, 1, 1])
        self.assertEqual(list(sy), [1, 1, 3, 3, 1])

        #
        #  3  o----o----o         3  o----o----o
        #     |         |            |         |
        #  2  o         o   ==>   2  o         |
        #     |         |            |         |
        #  1  o----o----o         1  o---------o
        #     1    2    3            1    2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 7. / 9.)
        self.assertEqual((sx.size, sy.size), (7, 7))
        self.assertEqual(list(sx), [1, 3, 3, 2, 1, 1, 1])
        self.assertEqual(list(sy), [1, 1, 3, 3, 3, 2, 1])

        #
        #  3  o----o----o         3  o----------o
        #     |         |            |       _/
        #  2  o         o   ==>   2  |    _/
        #     |         |            | _/
        #  1  o----o----o         1  o
        #     1    2    3            1     2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 4. / 9.)
        self.assertEqual((sx.size, sy.size), (4, 4))
        self.assertEqual(list(sx), [1, 3, 1, 1])
        self.assertEqual(list(sy), [1, 3, 3, 1])
Example #4
0
    def test_simplify_square(self):
        x_data = [1, 2, 3, 3, 3, 2, 1, 1, 1]
        y_data = [1, 1, 1, 2, 3, 3, 3, 2, 1]

        #
        #  3  o----o----o         3  o---------o
        #     |         |            |         |
        #  2  o         o   ==>   2  |         |
        #     |         |            |         |
        #  1  o----o----o         1  o---------o
        #     1    2    3            1    2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 5. / 9.)
        self.assertEqual((sx.size, sy.size), (5, 5))
        self.assertEqual(list(sx), [1, 3, 3, 1, 1])
        self.assertEqual(list(sy), [1, 1, 3, 3, 1])

        #
        #  3  o----o----o         3  o----o----o
        #     |         |            |         |
        #  2  o         o   ==>   2  o         |
        #     |         |            |         |
        #  1  o----o----o         1  o---------o
        #     1    2    3            1    2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 7. / 9.)
        self.assertEqual((sx.size, sy.size), (7, 7))
        self.assertEqual(list(sx), [1, 3, 3, 2, 1, 1, 1])
        self.assertEqual(list(sy), [1, 1, 3, 3, 3, 2, 1])

        #
        #  3  o----o----o         3  o----------o
        #     |         |            |       _/
        #  2  o         o   ==>   2  |    _/
        #     |         |            | _/
        #  1  o----o----o         1  o
        #     1    2    3            1     2    3
        #
        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 4. / 9.)
        self.assertEqual((sx.size, sy.size), (4, 4))
        self.assertEqual(list(sx), [1, 3, 1, 1])
        self.assertEqual(list(sy), [1, 3, 3, 1])
Example #5
0
    def test_simplify_none(self):
        # A triangle (ring)
        x_data = [1, 3, 3, 1]
        y_data = [1, 1, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 1.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)

        # A square (ring)
        x_data = [1, 3, 3, 1, 1]
        y_data = [1, 1, 3, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 1.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)
Example #6
0
    def test_simplify_none(self):
        # A triangle (ring)
        x_data = [1, 3, 3, 1]
        y_data = [1, 1, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 1.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)

        # A square (ring)
        x_data = [1, 3, 3, 1, 1]
        y_data = [1, 1, 3, 3, 1]

        x = np.array(x_data)
        y = np.array(y_data)
        sx, sy = simplify_geometry(x, y, 1.0)
        self.assertIs(sx, x)
        self.assertIs(sy, y)