当前位置:   article > 正文

Shapely - Python Package - Polygons_shapely polygon

shapely polygon

Shapely - Python Package - Polygons

class Polygon(exterior[, interiors=None])
The Polygon constructor takes two positional parameters. The first is an ordered sequence of (x, y[, z]) point tuples and is treated exactly as in the LinearRing case. The second is an optional unordered sequence of ring-like sequences specifying the interior boundaries or “holes” of the feature.
Rings of a valid Polygon may not cross each other, but may touch at a single point only. Again, Shapely will not prevent the creation of invalid features, but exceptions will be raised when they are operated on.

Figure 1. On the left, a valid Polygon with one interior ring that touches the exterior ring at one point, and on the right a Polygon that is invalid because its interior ring touches the exterior ring at more than one point. The points that describe the rings are shown in grey.

Figure 2. On the left, a Polygon that is invalid because its exterior and interior rings touch along a line, and on the right, a Polygon that is invalid because its interior rings touch along a line.

A Polygon has non-zero area and non-zero length.
>>> from shapely.geometry import Polygon
>>> polygon = Polygon([(0, 0), (1, 1), (1, 0)])
>>> polygon.area
0.5
>>> polygon.length
3.4142135623730949

Its x-y bounding box is a (minx, miny, maxx, maxy) tuple.
>>> polygon.bounds
(0.0, 0.0, 1.0, 1.0)


  1. strong@foreverstrong:~$ python
  2. Python 2.7.12 (default, Dec 4 2017, 14:50:18)
  3. [GCC 5.4.0 20160609] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> from shapely.geometry import Polygon
  6. >>> polygon = Polygon([(0, 0), (1, 1), (1, 0)])
  7. >>> polygon.area
  8. 0.5
  9. >>>
  10. >>> polygon.length
  11. 3.414213562373095
  12. >>>
  13. >>> polygon.bounds
  14. (0.0, 0.0, 1.0, 1.0)
  15. >>>
  16. >>> exit()
  17. strong@foreverstrong:~$

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/193532?site
推荐阅读
相关标签
  

闽ICP备14008679号