本文整理匯總了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))))