当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.apply_transform方法代码示例

本文整理汇总了Python中karta.vector.geometry.Polygon.apply_transform方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.apply_transform方法的具体用法?Python Polygon.apply_transform怎么用?Python Polygon.apply_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karta.vector.geometry.Polygon的用法示例。


在下文中一共展示了Polygon.apply_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAffineTransforms

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import apply_transform [as 别名]
class TestAffineTransforms(unittest.TestCase):

    def setUp(self):
        self.square = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
        return

    def test_translate_point(self):
        pt = Point((0, 0), crs=Cartesian)

        with self.assertRaises(ValueError):
            newpt = pt.apply_transform(np.array([[0, 0, 1, 0], [0, 0, 2, 0]]))

        newpt = pt.apply_transform(np.array([[0, 0, 1], [0, 0, 2]]))
        self.assertEqual(newpt.x, 1.0)
        self.assertEqual(newpt.y, 2.0)
        return

    def test_translate_point_3(self):
        pt = Point((0, 0, 3), crs=Cartesian)
        newpt = pt.apply_transform(np.array([[0, 0, 1], [0, 0, 2]]))
        self.assertEqual(newpt.x, 1.0)
        self.assertEqual(newpt.y, 2.0)
        self.assertEqual(newpt.z, 3.0)
        return

    def test_transform_multiline(self):
        g = Multiline([[(0,0), (1,1), (1,2)], [(-3,2),  (-2,-1), (0,1)]])
        pi = math.pi
        gnew = g.apply_transform(np.array([[math.cos(0.5*pi), -math.sin(0.5*pi), 0],
                                           [math.sin(0.5*pi), math.cos(0.5*pi), 0]]))
        l1, l2 = gnew.vertices()
        self.assertTrue(np.allclose(l1, np.array([(0,0), (-1,1), (-2,1)])))
        self.assertTrue(np.allclose(l2, np.array([(-2,-3), (1,-2), (-1,0)])))

        gnew2 = gnew.apply_transform(np.array([[2, 0, 0],
                                               [0, -3, 0]]))
        l1, l2 = gnew2.vertices()
        self.assertTrue(np.allclose(l1, np.array([(0,0), (-2,-3), (-4,-3)])))
        self.assertTrue(np.allclose(l2, np.array([(-4,9), (2,6), (-2,0)])))
        return

    def test_translate_multipoint(self):
        M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
                          Multipoint([(1,0), (2,0), (1,1)]))
        Mans = np.array([[1, 0, 1], [0, 1, 0]])
        self.assertTrue(np.allclose(M, Mans))

        translated_square = self.square.apply_transform(M)
        ans = np.array([[1, 0], [1, 1], [2, 1], [2, 0]])
        self.assertTrue(np.allclose(translated_square.vertices(), ans))
        return

    def test_rotate_multipoint(self):
        s2 = math.sqrt(0.5)
        M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
                          Multipoint([(0,0), (s2,s2), (-s2,s2)]))
        Mans = np.array([[s2, -s2, 0], [s2, s2, 0]])
        self.assertTrue(np.allclose(M, Mans))

        translated_square = self.square.apply_transform(M)
        ans = np.array([[0, 0], [-s2, s2], [0, 2*s2], [s2, s2]])
        self.assertTrue(np.allclose(translated_square.vertices(), ans))
        return

    def test_stretch_multipoint(self):
        M = affine_matrix(Multipoint([(0,0), (1,0), (0,1)]),
                          Multipoint([(0,0), (2,0), (0,2)]))
        Mans = np.array([[2, 0, 0], [0, 2, 0]])
        self.assertTrue(np.allclose(M, Mans))

        translated_square = self.square.apply_transform(M)
        ans = np.array([[0, 0], [0, 2], [2, 2], [2, 0]])
        self.assertTrue(np.allclose(translated_square.vertices(), ans))
        return
开发者ID:fortyninemaps,项目名称:karta,代码行数:76,代码来源:geometry_tests.py


注:本文中的karta.vector.geometry.Polygon.apply_transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。