當前位置: 首頁>>代碼示例>>Python>>正文


Python Multipoint.nearest_point_to方法代碼示例

本文整理匯總了Python中karta.vector.geometry.Multipoint.nearest_point_to方法的典型用法代碼示例。如果您正苦於以下問題:Python Multipoint.nearest_point_to方法的具體用法?Python Multipoint.nearest_point_to怎麽用?Python Multipoint.nearest_point_to使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在karta.vector.geometry.Multipoint的用法示例。


在下文中一共展示了Multipoint.nearest_point_to方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestGeometry

# 需要導入模塊: from karta.vector.geometry import Multipoint [as 別名]
# 或者: from karta.vector.geometry.Multipoint import nearest_point_to [as 別名]
class TestGeometry(unittest.TestCase):

    def setUp(self):
        self.point = Point((1.0, 2.0, 3.0), data={"color":(43,67,10)},
                           properties="apple")

        self.vertices = [(2.0, 9.0, 9.0), (4.0, 1.0, 9.0), (4.0, 1.0, 5.0),
                         (2.0, 8.0, 0.0), (9.0, 8.0, 4.0), (1.0, 4.0, 6.0),
                         (7.0, 3.0, 4.0), (2.0, 5.0, 3.0), (1.0, 6.0, 6.0),
                         (8.0, 1.0, 0.0), (5.0, 5.0, 1.0), (4.0, 5.0, 7.0),
                         (3.0, 3.0, 5.0), (9.0, 0.0, 9.0), (6.0, 3.0, 8.0),
                         (4.0, 5.0, 7.0), (9.0, 9.0, 4.0), (1.0, 4.0, 7.0),
                         (1.0, 7.0, 8.0), (9.0, 1.0, 6.0)]

        self.data = [99.0, 2.0, 60.0, 75.0, 71.0, 34.0, 1.0, 49.0, 4.0, 36.0,
                     47.0, 58.0, 65.0, 72.0, 4.0, 27.0, 52.0, 37.0, 95.0, 17.0]

        self.mp = Multipoint(self.vertices, data=self.data)
        self.line = Line(self.vertices, data=self.data)
        self.poly = Polygon([(0.0, 8.0), (0.0, 5.0), (6.0, 1.0)])
        self.ring = Polygon([(2.0, 2.0), (4.0, 2.0), (3.0, 6.0)])
        self.ringed_poly = Polygon([(0.0, 0.0), (10, 0.0),
                                    (10.0, 10.0), (0.0, 10.0)],
                                   subs=[self.ring])
        self.unitsquare = Polygon([(0.0,0.0), (1.0,0.0), (1.0,1.0), (0.0,1.0)])
        return

    def test_point_equality(self):
        pt1 = Point((3.0, 4.0))
        pt2 = Point((3.0, 4.0, 5.0))
        pt3 = Point((3.0, 4.0, 5.0), data={"species":"T. officianale", "density":"high"})
        self.assertFalse(pt1 == pt2)
        self.assertFalse(pt1 == pt3)
        self.assertFalse(pt2 == pt3)
        return

    def test_point_vertex(self):
        self.assertEqual(self.point.get_vertex(), (1.0, 2.0, 3.0))
        return

    def test_point_coordsxy(self):
        self.assertEqual(self.point.coordsxy(), (1.0, 2.0))
        self.assertEqual(self.point[0], 1.0)
        self.assertEqual(self.point[1], 2.0)
        return

    def test_point_azimuth(self):
        point = Point((1.0, 2.0))

        other = Point((2.0, 3.0))
        self.assertEqual(point.azimuth(other), 0.25*180)

        other = Point((0.0, 3.0))
        self.assertEqual(point.azimuth(other), 1.75*180)

        other = Point((0.0, 1.0))
        self.assertEqual(point.azimuth(other), 1.25*180)

        other = Point((2.0, 1.0))
        self.assertEqual(point.azimuth(other), 0.75*180)

        other = Point((1.0, 3.0))
        self.assertEqual(point.azimuth(other), 0.0)

        other = Point((1.0, 1.0))
        self.assertEqual(point.azimuth(other), 180.0)
        return

    def test_point_azimuth2(self):
        point = Point((5.0, 2.0))
        other = Point((5.0, 2.0))
        self.assertTrue(np.isnan(point.azimuth(other)))
        return

    def test_point_azimuth3(self):
        """ Verify with:

        printf "0 -1000000\n100000 -900000" | proj +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +units=m +datum=WGS84 +no_defs -I -s | tr '\n' ' ' | invgeod +ellps=WGS84 -f "%.6f"
        """
        point = Point((0.0, -10e5), crs=NSIDCNorth)
        other = Point((1e5, -9e5), crs=NSIDCNorth)
        self.assertAlmostEqual(point.azimuth(other), 45.036973, places=6)
        return

    def test_point_shift(self):
        point = Point((-3.0, 5.0, 2.5), data={"color":(43,67,10)},
                      properties="apple")
        point.shift((4.0, -3.0, 0.5))
        self.assertEqual(self.point, point)
        return

    def test_nearest_to(self):
        self.assertEqual(self.mp.nearest_point_to(self.point), self.mp[12])
        return

    def test_empty_multipoint(self):
        mp = Multipoint([], crs=LonLatWGS84)
        self.assertEqual(len(mp), 0)
        return

#.........這裏部分代碼省略.........
開發者ID:jmjak86,項目名稱:karta,代碼行數:103,代碼來源:geometry_tests.py


注:本文中的karta.vector.geometry.Multipoint.nearest_point_to方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。