本文整理汇总了Python中karta.vector.geometry.Polygon.get_extents方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.get_extents方法的具体用法?Python Polygon.get_extents怎么用?Python Polygon.get_extents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karta.vector.geometry.Polygon
的用法示例。
在下文中一共展示了Polygon.get_extents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGeometry
# 需要导入模块: from karta.vector.geometry import Polygon [as 别名]
# 或者: from karta.vector.geometry.Polygon import get_extents [as 别名]
#.........这里部分代码省略.........
def test_line_intersection(self):
line0 = Line([(0.0, 0.0), (3.0, 3.0)])
line1 = Line([(0.0, 3.0), (3.0, 0.0)])
self.assertTrue(line0.intersects(line1))
self.assertEqual(line0.intersections(line1), Multipoint([(1.5, 1.5)]))
return
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))))