Shapely 2.0.0 中文文档

  1. 主页
  2. 文档
  3. Shapely 2.0.0 中文文档
  4. User Manual
  5. Other Operations(其他操作)
  6. Merging Linear Features(合并线状要素)

Merging Linear Features(合并线状要素)

Sequences of touching lines can be merged into MultiLineStrings or Polygons using functions in the shapely.ops module.

使用shapely.ops模块中的函数,可以将相邻接的线序列合并成复合线或复合多边形。

  • shapely.ops.polygonize(lines)

Returns an iterator over polygons constructed from the input lines.

返回一个由输入线构建的多边形的迭代器。

As with the MultiLineString constructor, the input elements may be any line-like object.

与MultiLineString构造函数一样,输入元素可以是任何线性对象。

>>> from shapely.ops import polygonize
>>> lines = [
...     ((0, 0), (1, 1)),
...     ((0, 0), (0, 1)),
...     ((0, 1), (1, 1)),
...     ((1, 1), (1, 0)),
...     ((1, 0), (0, 0))
...     ]
>>> list(polygonize(lines))
[<POLYGON ((0 0, 1 1, 1 0, 0 0))>, <POLYGON ((1 1, 0 0, 0 1, 1 1))>]
  • shapely.ops.polygonize_full(lines)

Creates polygons from a source of lines, returning the polygons and leftover geometries.

从线的源头创建多边形,返回多边形和剩余的几何对象。

The source may be a MultiLineString, a sequence of LineString objects, or a sequence of objects than can be adapted to LineStrings.

源可以是MultiLineString,LineString对象序列,或者LineStrings的对象序列。

Returns a tuple of objects: (polygons, cut edges, dangles, invalid ring lines). Each are a geometry collection.

返回一个对象的元组:(多边形、悬边、切割边、无效环线)。每个对象都是一个几何集合。

Dangles are edges which have one or both ends which are not incident on another edge endpoint. Cut edges are connected at both ends but do not form part of polygon. Invalid ring lines form rings which are invalid (bowties, etc).

悬边是指有一个或两个端点不与另一个端点相交的边。切割边是两端相连但不构成多边形的一部分。无效环线形成的环是无效的(蝴蝶结等)。

New in version 1.2.18.

>>> from shapely.ops import polygonize_full
>>> lines = [
...     ((0, 0), (1, 1)),
...     ((0, 0), (0, 1)),
...     ((0, 1), (1, 1)),
...     ((1, 1), (1, 0)),
...     ((1, 0), (0, 0)),
...     ((5, 5), (6, 6)),
...     ((1, 1), (100, 100)),
...     ]
>>> result, cuts, dangles, invalids = polygonize_full(lines)
>>> len(result.geoms)
2
>>> list(result.geoms)
[<POLYGON ((0 0, 1 1, 1 0, 0 0))>, <POLYGON ((1 1, 0 0, 0 1, 1 1))>]
>>> list(dangles.geoms)
[<LINESTRING (1 1, 100 100)>, <LINESTRING (5 5, 6 6)>]
  • shapely.ops.linemerge(lines)

Returns a LineString or MultiLineString representing the merger of all contiguous elements of lines.

返回一个LineString或MultiLineString,代表所有相邻的线要素的合并。

As with shapely.ops.polygonize(), the input elements may be any line-like object.

与shapely.ops.polygonize()一样,输入元素可以是任何线性对象。

>>> from shapely.ops import linemerge
>>> linemerge(lines)
<MULTILINESTRING ((1 1, 1 0, 0 0), (0 0, 1 1), (0 0, 0 1, 1 1), (1 1, 100 10...>
>>> list(linemerge(lines).geoms)
[<LINESTRING (1 1, 1 0, 0 0)>,
 <LINESTRING (0 0, 1 1)>,
 <LINESTRING (0 0, 0 1, 1 1)>,
 <LINESTRING (1 1, 100 100)>,
 <LINESTRING (5 5, 6 6)>]
标签 ,
这篇文章对您有用吗?

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here