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


Python Polygon.contains方法代码示例

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


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

示例1: test_poly_contains_polar

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
 def test_poly_contains_polar(self):
     p = Polygon([(0, 80), (45, 80), (90, 80), (135, 80), (180, 80),
                  (225, 80), (270, 80), (315, 80)],
                 crs=SphericalEarth)
     self.assertTrue(p.contains(Point((45, 85), crs=SphericalEarth)))
     self.assertFalse(p.contains(Point((45, 75), crs=SphericalEarth)))
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:9,代码来源:vector_predicate_tests.py

示例2: test_poly_contains3

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
 def test_poly_contains3(self):
     # test some hard cases
     diamond = Polygon([(0,0), (1,1), (2,0), (1, -1)])
     self.assertFalse(diamond.contains(Point((2, 1))))
     self.assertTrue(diamond.contains(Point((1, 0))))
     self.assertFalse(diamond.contains(Point((2.5, 0))))
     self.assertFalse(diamond.contains(Point((2, -1))))
     return
开发者ID:jmjak86,项目名称:karta,代码行数:10,代码来源:geometry_tests.py

示例3: test_multipoint_within_polygon

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
    def test_multipoint_within_polygon(self):
        np.random.seed(42)
        x = (np.random.random(100) - 0.5) * 180.0
        y = (np.random.random(100) - 0.5) * 30.0
        xp = [-80, -50, 20, 35, 55, -45, -60]
        yp = [0, -10, -8, -17, 15, 18, 12]
        poly = Polygon(zip(xp, yp), crs=LonLatWGS84)
        mp = Multipoint(zip(x, y), crs=LonLatWGS84)

        subset = mp.within_polygon(poly)
        excluded = [pt for pt in mp if pt not in subset]
        self.assertTrue(all(poly.contains(pt) for pt in subset))
        self.assertFalse(any(poly.contains(pt) for pt in excluded))
        return
开发者ID:fortyninemaps,项目名称:karta,代码行数:16,代码来源:vector_predicate_tests.py

示例4: test_poly_contains1

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
    def test_poly_contains1(self):
        # trivial cases
        pt0 = Point((-0.5, 0.92))
        unitsquare = Polygon([(0.0,0.0), (1.0,0.0), (1.0,1.0), (0.0,1.0)])
        self.assertFalse(unitsquare.contains(pt0))

        pt1 = Point((0.125, 0.875))
        self.assertTrue(unitsquare.contains(pt1))

        x = np.arange(-4, 5)
        y = (x)**2
        line = Line([(x_,y_) for x_,y_ in zip(x, y)], crs=Cartesian)
        bbox = Polygon([(-2.5, 2.5), (2.5, 2.5), (2.5, -2.5), (-2.5, -2.5)],
                             crs=Cartesian)

        self.assertEqual(list(filter(bbox.contains, line)),
                         [Point((-1, 1)), Point((0, 0)), Point((1, 1))])
        return
开发者ID:fortyninemaps,项目名称:karta,代码行数:20,代码来源:vector_predicate_tests.py

示例5: test_poly_contains4

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
 def test_poly_contains4(self):
     # hippie star
     theta = np.linspace(0, 2*np.pi, 361)[:-1]
     r = 10*np.sin(theta*8) + 15
     x = np.cos(theta) * r + 25
     y = np.sin(theta) * r + 25
     polygon = Polygon(zip(x, y))
     # causes naive cross-product methods to fail
     pt = Point((28.75, 25.625))
     self.assertTrue(polygon.contains(pt))
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:13,代码来源:vector_predicate_tests.py

示例6: test_poly_contains3

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]
 def test_poly_contains3(self):
     # case where point is on an edge (should return true)
     square = Polygon([(0,0), (1,0), (1,1), (0,1)])
     self.assertTrue(square.contains(Point([0.5, 0])))
     self.assertTrue(square.contains(Point([0, 0.5])))
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:8,代码来源:vector_predicate_tests.py

示例7: TestGeometryAnalysis

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]

#.........这里部分代码省略.........
    def test_multipoint_bbox_overlap(self):
        self.assertTrue(self.mp._bbox_overlap(self.poly))
        return

    def test_multipoint_within_radius(self):
        vertices = [(float(x),float(y)) for x in range(-10,11)
                                        for y in range(-10,11)]
        ans = [v for v in vertices if math.sqrt(v[0]**2 + v[1]**2) < 5.0]
        mp = Multipoint(vertices)
        sub = mp.within_radius(Point((0,0)), 5.0)
        self.assertEqual(sub, Multipoint(ans))
        return

    def test_multipoint_within_bbox(self):
        vertices = [(float(x),float(y)) for x in range(-10,11)
                                        for y in range(-10,11)]
        ans = [v for v in vertices if (-5.0<v[0]<5.0) and (-4.0<v[1]<6.0)]
        mp = Multipoint(vertices)
        sub = mp.within_bbox((-5.0, -4.0, 5.0, 6.0))
        self.assertEqual(sub, Multipoint(ans))
        return

    def test_multipoint_within_polygon(self):
        np.random.seed(42)
        x = (np.random.random(100) - 0.5) * 180.0
        y = (np.random.random(100) - 0.5) * 30.0
        xp = [-80, -50, 20, 35, 55, -45, -60]
        yp = [0, -10, -8, -17, 15, 18, 12]
        poly = Polygon(zip(xp, yp), crs=LonLatWGS84)
        mp = Multipoint(zip(x, y), crs=LonLatWGS84)

        subset = mp.within_polygon(poly)
        excluded = [pt for pt in mp if pt not in subset]
        self.assertTrue(all(poly.contains(pt) for pt in subset))
        self.assertFalse(any(poly.contains(pt) for pt in excluded))
        return

    def test_multipoint_convex_hull(self):
        vertices = [(953, 198), (986, 271), (937, 305), (934, 464), (967, 595),
                (965, 704), (800, 407), (782, 322), (863, 979), (637, 689),
                (254, 944), (330, 745), (363, 646), (27, 990), (127, 696),
                (286, 352), (436, 205), (88, 254), (187, 85)]
        mp = Multipoint(vertices)
        ch = mp.convex_hull()
        hull_vertices = [(187, 85), (953, 198), (986, 271), (965, 704), (863,
            979), (27, 990), (88, 254)]
        self.assertTrue(np.all(np.equal(ch.vertices, hull_vertices)))
        return

    def test_multipoint_convex_hull2(self):
        vertices = [(-158, 175), (-179, 230), (-404, -390), (259, -79), (32,
            144), (-59, 355), (402, 301), (239, 159), (-421, 172), (-482, 26),
            (2, -499), (134, -72), (-412, -12), (476, 235), (-412, 40), (-198,
                -256), (314, 331), (431, -492), (325, -415), (-400, -491)]
        mp = Multipoint(vertices)
        ch = mp.convex_hull()
        hull_vertices = [(2, -499), (431, -492), (476, 235), (402, 301), (314,
            331), (-59, 355), (-421, 172), (-482, 26), (-400, -491)]
        self.assertTrue(np.all(np.equal(ch.vertices, hull_vertices)))
        return

    def test_connected_multipoint_shortest_distance_to(self):
        line = Line([(0.0, 0.0), (2.0, 2.0), (5.0, 4.0)])
        dist = line.shortest_distance_to(Point((0.0, 2.0)))
        self.assertTrue(abs(dist - math.sqrt(2)) < 1e-10)
        return
开发者ID:ivn888,项目名称:karta,代码行数:70,代码来源:geometry_tests.py

示例8: TestGeometry

# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import contains [as 别名]

#.........这里部分代码省略.........

    def test_line_intersection_horizontal(self):
        line0 = Line([(-2.5, 2.5), (2.5, 2.5)])
        line1 = Line([(0.0, 0.0), (1.0, 5.0)])
        self.assertTrue(line0.intersects(line1))
        self.assertEqual(line0.intersections(line1), Multipoint([(0.5, 2.5)]))
        return

    def test_line_intersection_vertical(self):
        line0 = Line([(2.5, 2.5), (2.5, -2.5)])
        line1 = Line([(1.5, 2.5), (3.5, -2.5)])
        self.assertTrue(line0.intersects(line1))
        self.assertEqual(line0.intersections(line1), Multipoint([(2.5, 0.0)]))
        return

    def test_poly_clockwise(self):
        p = Polygon([(0,0), (0,1), (1,1), (1,0)])
        self.assertTrue(p.isclockwise())
        return

    def test_poly_counterclockwise(self):
        p = Polygon([(0,0), (1,0), (1,1), (0,1)])
        self.assertFalse(p.isclockwise())
        return

    def test_poly_extents(self):
        self.assertEqual(self.poly.get_extents(), (0.0, 6.0, 1.0, 8.0))
        return

    def test_poly_length(self):
        self.assertEqual(self.poly.length, 19.430647008220866)
        return

    def test_poly_contains1(self):
        # trivial case
        pt0 = Point((-0.5, 0.92))
        pt1 = Point((0.125, 0.875))
        self.assertFalse(self.unitsquare.contains(pt0))
        self.assertTrue(self.unitsquare.contains(pt1))
        return

    def test_poly_contains2(self):
        # trivial but more interesting case
        x = np.arange(-4, 5)
        y = (x)**2
        line = Line([(x_,y_) for x_,y_ in zip(x, y)], crs=Cartesian)
        bbox = Polygon([(-2.5, 2.5), (2.5, 2.5), (2.5, -2.5), (-2.5, -2.5)],
                             crs=Cartesian)

        self.assertEqual(list(filter(bbox.contains, line)),
                         [Point((-1, 1)), Point((0, 0)), Point((1, 1))])

    def test_poly_contains3(self):
        # test some hard cases
        diamond = Polygon([(0,0), (1,1), (2,0), (1, -1)])
        self.assertFalse(diamond.contains(Point((2, 1))))
        self.assertTrue(diamond.contains(Point((1, 0))))
        self.assertFalse(diamond.contains(Point((2.5, 0))))
        self.assertFalse(diamond.contains(Point((2, -1))))
        return

    def test_poly_contains4(self):
        # case where point is on an edge (should return true)
        square = Polygon([(0,0), (1,0), (1,1), (0,1)])
        pt = Point([0.5, 0])
        self.assertTrue(square.contains(pt))
开发者ID:jmjak86,项目名称:karta,代码行数:70,代码来源:geometry_tests.py


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