Shapely 2.0.0 中文文档

  1. 主页
  2. 文档
  3. Shapely 2.0.0 中文文档
  4. User Manual
  5. Geometric Objects(几何对象)
  6. Polygons(多边形几何要素)

Polygons(多边形几何要素)

class Polygon(shell[, holes=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.

Polygon构造函数需要两个位置参数。第一个位置参数是一个(x, y[, z])点元祖的有序序列,与LinearRing的情况完全相同。第二个位置参数是一个可选的无序的环状序列,用于指定几何要素的内部”洞”的边界 。

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.

一个有效的多边形的环不能相互交叉,而只能在一个点上接触。同样,Shapely不会阻止无效要素的创建,但在对其进行操作时可能会出现异常。

(Source codepnghires.pngpdf)

Figure 3. 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.图3. 左边是一个有效的多边形,它的内环与外环在一点接触。右边是一个无效的多边形,因为它的内环与外环有多余一点的接触。描述环的点以灰色显示。

(Source codepnghires.pngpdf)

Figure 4. 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.图4. 左边是一个无效的多边形,因为它的外环和内环沿着一条线接触,右边也是一个无效的多边形,因为它的内环沿着一条线接触。

A Polygon has non-zero area and non-zero length.

一个多边形具有非零的面积和非零的长度。

>>> from shapely import Polygon
>>> polygon = Polygon([(0, 0), (1, 1), (1, 0)])
>>> polygon.area
0.5
>>> polygon.length
3.414213562373095

Its x-y bounding box is a (minx, miny, maxx, maxy) tuple.

它的边界是一个元组(minx, miny, maxx, maxy)。

>>> polygon.bounds
(0.0, 0.0, 1.0, 1.0)

Component rings are accessed via exterior and interiors properties.

内环和外环可以通过exterior和interiors属性进行访问。

>>> list(polygon.exterior.coords)
[(0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]
>>> list(polygon.interiors)
[]

The Polygon constructor also accepts instances of LineString and LinearRing.

Polygon构造函数也接受LineString和LinearRing实例。

>>> coords = [(0, 0), (1, 1), (1, 0)]
>>> r = LinearRing(coords)
>>> s = Polygon(r)
>>> s.area
0.5
>>> t = Polygon(s.buffer(1.0).exterior, [r])
>>> t.area
6.5507620529190325

Rectangular polygons occur commonly, and can be conveniently constructed using the shapely.geometry.box() function.

矩形多边形经常出现,可以使用shapely.geometry.box()函数方便地构建。

  • shapely.geometry.box(minxminymaxxmaxyccw=True)

Makes a rectangular polygon from the provided bounding box values, with counter-clockwise order by default.

根据提供的边界框值生成一个矩形的多边形,默认为逆时针顺序。

New in version 1.2.9.

For example:

>>> from shapely import box
>>> b = box(0.0, 0.0, 1.0, 1.0)
>>> b
<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>
>>> list(b.exterior.coords)
[(1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)]

This is the first appearance of an explicit polygon handedness in Shapely.

To obtain a polygon with a known orientation, use shapely.geometry.polygon.orient():

为了获得一个已知方向的多边形, 可以使用shapely.geometry.polygon.orient():

  • shapely.geometry.polygon.orient(polygonsign=1.0)

Returns a properly oriented copy of the given polygon. The signed area of the result will have the given sign. A sign of 1.0 means that the coordinates of the product’s exterior ring will be oriented counter-clockwise and the interior rings (holes) will be oriented clockwise.

返回给定多边形正确方向的副本。结果中带符号区域将具有给定的符号。sign为1.0意味着矩形外部环的坐标将是逆时针方向的,内部环(孔)将是顺时针方向的。

New in version 1.2.10.

标签 ,
这篇文章对您有用吗?

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here