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


Python geometry.Polygon类代码示例

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


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

示例1: test_poly_contains_polar

 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,代码行数:7,代码来源:vector_predicate_tests.py

示例2: setUp

    def setUp(self):
        self.points = [Point((1, 1), data={"species": "T. officianale"}, crs=LonLatWGS84),
                       Point((3, 1), data={"species": "C. tectorum"}, crs=LonLatWGS84),
                       Point((4, 3), data={"species": "M. alba"}, crs=LonLatWGS84),
                       Point((2, 2), data={"species": "V. cracca"}, crs=LonLatWGS84)]

        self.multipoint = Multipoint([(1,1), (3,1), (4,3), (2,2)],
                                     data={"species": ["T. officianale", "C. tectorum",
                                                       "M. alba", "V. cracca"]},
                                     crs=LonLatWGS84)

        self.line = Line([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
                         properties={"geom_id": 27, "name": "test line"},
                         crs=LonLatWGS84)

        self.polygon = Polygon([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)],
                               crs=LonLatWGS84)

        self.points3 = [Point((1, 1, 0), crs=LonLatWGS84),
                        Point((3, 1, 3), crs=LonLatWGS84),
                        Point((4, 3, 2), crs=LonLatWGS84),
                        Point((2, 2, -1), crs=LonLatWGS84)]

        self.line3 = Line([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)

        self.polygon3 = Polygon([(1,5,2),(5,5,-1),(5,1,3),(3,3,1),(1,1,0)], crs=LonLatWGS84)

        testfiles = ["points.shp", "line.shp", "polygon.shp"]
        if any(not exists(join(TMPDATA, "shapefiles/", fnm)) for fnm in testfiles):
            self.saveTestData()
        return
开发者ID:acrosby,项目名称:karta,代码行数:31,代码来源:shapefile_tests.py

示例3: setUp

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

        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)
        self.poly = Polygon([(0.0, 8.0), (0.0, 5.0), (6.0, 1.0)])
        self.poly3 = Polygon([(0.0, 8.0, 0.5), (0.0, 5.0, 0.8), (6.0, 1.0, 0.6)])
        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
开发者ID:ivn888,项目名称:karta,代码行数:25,代码来源:geometry_tests.py

示例4: test_poly_extent_foreign_crs

 def test_poly_extent_foreign_crs(self):
     poly = Polygon([(0.0, 8.0), (0.0, 5.0), (6.0, 1.0)], crs=LonLatWGS84)
     poly3 = Polygon([(0.0, 8.0, 0.5), (0.0, 5.0, 0.8), (6.0, 1.0, 0.6)], crs=LonLatWGS84)
     x, y = zip(*poly.get_vertices(crs=NSIDCNorth))
     self.assertEqual(poly.get_extent(NSIDCNorth), (min(x), max(x), min(y), max(y)))
     self.assertEqual(poly3.get_extent(NSIDCNorth), (min(x), max(x), min(y), max(y)))
     return
开发者ID:acrosby,项目名称:karta,代码行数:7,代码来源:geometry_tests.py

示例5: test_poly_contains3

 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,代码行数:8,代码来源:geometry_tests.py

示例6: test_polygon_write

    def test_polygon_write(self):
        p = Polygon([[100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
                     [100.0, 1.0]], crs=LonLatWGS84)
        s = p.as_geojson(urn="urn:ogc:def:crs:EPSG::5806")
        ans = """{ "properties": {}, "bbox": [100.0, 0.0, 101.0, 1.0], "geometry": { "type": "Polygon", "coordinates": [ [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ] ] }, "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::5806" } }, "type": "Feature" }"""

        self.verifyJSON(s, ans)
        return
开发者ID:fortyninemaps,项目名称:karta,代码行数:8,代码来源:geojson_tests.py

示例7: test_poly_rotate

 def test_poly_rotate(self):
     poly = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)])
     rot45 = poly.rotate(45, (0.5, 0.5))
     self.assertTrue(np.allclose(rot45.coords(),
                                 np.array([[ 0.5,  1.20710678, 0.5, -0.20710678],
                                           [-0.20710678, 0.5,  1.20710678, 0.5 ]])))
     rot90 = poly.rotate(90, (0.0, 0.0))
     self.assertTrue(np.allclose(rot90.coords(),
                                 np.array([[0.0, 0.0, -1.0, -1.0],
                                           [0.0, 1.0, 1.0, 0.0]])))
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:11,代码来源:geometry_tests.py

示例8: test_poly_contains4

 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,代码行数:11,代码来源:vector_predicate_tests.py

示例9: test_poly_intersection

 def test_poly_intersection(self):
     # test polygons formed exactly as in test_line_intersection2, except
     # the rings are implicitly closed
     #   -----
     #   | --x--
     #   | . . |
     #   --x-- |
     #     -----
     poly0 = Polygon([(0.0, 0.0), (3.0, 0.0), (3.0, 3.0), (0.0, 3.0)])
     poly1 = Polygon([(1.0, 4.0), (-2.0, 4.0), (-2.0, 1.0), (1.0, 1.0)])
     self.assertTrue(poly0.intersects(poly1))
     self.assertEqual(poly0.intersections(poly1), Multipoint([(0.0, 1.0), (1.0, 3.0)]))
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:13,代码来源:vector_predicate_tests.py

示例10: test_multipoint_within_polygon

    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,代码行数:14,代码来源:vector_predicate_tests.py

示例11: test_poly_contains1

    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,代码行数:18,代码来源:vector_predicate_tests.py

示例12: TestAffineTransforms

class TestAffineTransforms(unittest.TestCase):

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

    def test_translate(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], [0, 0, 1]])
        self.assertTrue(np.allclose(M, Mans))

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

    def test_rotate(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], [0, 0, 1]])
        self.assertTrue(np.allclose(M, Mans))

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

    def test_stretch(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], [0, 0, 1]])
        self.assertTrue(np.allclose(M, Mans))

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

示例13: test_poly_polar

    def test_poly_polar(self):
        p = Polygon([(0.0, 80.0), (30.0, 80.0), (60.0, 80.0), (90.0, 80.0),
                     (120.0, 80.0), (150.0, 80.0), (180.0, 80.0),
                     (-150.0, 80.0), (-120.0, 80.0), (-90.0, 80.0),
                     (-60.0, 80.0), (-30.0, 80.0)], crs=SphericalEarth)
        self.assertTrue(p.ispolar())

        p = Polygon([(0.0, 85.0, 0.0), (90.0, 85.0, 0.0), (180.0, 85.0, 0.0),
                     (-90.0, 85.0, 0.0)], crs=SphericalEarth)
        self.assertTrue(p.ispolar())

        p = Polygon([(45.0, 30.0), (40.0, 25.0), (45.0, 20.0), (35.0, 25.0)],
                    crs=SphericalEarth)
        self.assertFalse(p.ispolar())

        p = Polygon([(-80, 0), (-50, -10), (20, -8), (35, -17), (55, 15),
                     (-45, 18), (-60, 12)], crs=LonLatWGS84)
        self.assertFalse(p.ispolar())

        p = Polygon([(45.0, 30.0), (40.0, 25.0), (45.0, 20.0), (35.0, 25.0)],
                    crs=Cartesian)
        self.assertRaises(CRSError, p.ispolar)
        return
开发者ID:fortyninemaps,项目名称:karta,代码行数:23,代码来源:vector_predicate_tests.py

示例14: test_poly_clockwise

 def test_poly_clockwise(self):
     p = Polygon([(0,0), (0,1), (1,1), (1,0)])
     self.assertTrue(p.isclockwise())
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:4,代码来源:vector_predicate_tests.py

示例15: test_poly_output

 def test_poly_output(self):
     p = Polygon([(4, 2), (3, 5), (3, 2), (7, 3)])
     sp = shapely.geometry.shape(p.geomdict)
     self.assertEqual(p.bbox(), sp.bounds)
     return
开发者ID:fortyninemaps,项目名称:karta,代码行数:5,代码来源:geointerface_tests.py


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