## 合并线性要素

#### shapely.ops.polygonize(lines)

In [2]:
```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))
]
```

#### shapely.ops.linemerge(lines)

In [3]:
```from shapely.ops import linemerge
linemerge(lines)
```
Out[3]:
In [4]:
```pprint(list(linemerge(lines)))
```
```Pretty printing has been turned OFF
```

### 级联合并

shapely的级联合并

`shapely.ops.cascaded_union(geoms)`

In [5]:
```from shapely.geometry import Point
polygons = [Point(i, 0).buffer(0.7) for i in range(5)]
```
In [6]:
```polygons[0].union(polygons[1]).area
```
Out[6]:
`2.8052569090548327`
In [7]:
```polygons[0].area
```
Out[7]:
`1.5369087603675098`
In [8]:
```cascaded_union(polygons)
```
Out[8]:

In [9]:
```from shapely.geometry import MultiPolygon
m = MultiPolygon(polygons)
m.area
```
Out[9]:
`7.684543801837549`
In [10]:
```cascaded_union(m).area
```
Out[10]:
`6.610301355116797`

### 预制的几何操作

Shapely几何体能够被加工为一种可以支持高效批次的操作的形式。

`prepared.prep(ob)`

In [11]:
```from shapely.geometry import Point
```
In [12]:
```from shapely.prepared import prep
```
In [13]:
```points = [...] # large list
```
In [14]:
```from shapely.geometry import Point
polygon = Point(0.0, 0.0).buffer(1.0)
prepared_polygon = prep(polygon)
prepared_polygon
```
Out[14]:
`<shapely.prepared.PreparedGeometry object at 0x7f34af7715c0>`
In [15]:
```hits = filter(prepared_polygon.contains, points)
hits
```
Out[15]:
`<filter object at 0x7f34af771630>`

### 对象的有效性判断方法

`validation.explain_validity(ob)`

In [16]:
```from shapely.geometry import Point
from shapely.geometry import Polygon
coords = [(0, 0), (0, 2), (1, 1), (2, 2), (2, 0), (1, 1), (0, 0)]
p = Polygon(coords)
from shapely.validation import explain_validity
explain_validity(p)
```
Out[16]:
`'Ring Self-intersection[1 1]'`

In [17]:
```import helper; helper.info()
```
```页面更新时间： 2019-02-28 18:44:08

Python: 3.5.3
```