Shapely 1.8.5 中文文档

⌘K
  1. 主页
  2. 文档
  3. Shapely 1.8.5 中文文档...
  4. User Manual
  5. Geometric Objects(几何对象)...
  6. Collections(集合)

Collections(集合)

Heterogeneous collections of geometric objects may result from some Shapely operations. For example, two LineStrings may intersect along a line and at a point. To represent these kind of results, Shapely provides frozenset-like, immutable collections of geometric objects. The collections may be homogeneous (MultiPoint etc.) or heterogeneous.

一些Shapely操作可能会出现多项几何对象的集合(collections)。例如,两个LineString可能沿着一条线和在一个点相交。为了表示这些结果,Shapely提供了类似于frozenset的、不可改变的几何对象的集合。这些集合可以是同质的(复合点等)或异质的(点与线的集合)。

>>> a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
>>> b = LineString([(0, 0), (1, 1), (2,1), (2,2)])
>>> x = a.intersection(b)
>>> x
<shapely.geometry.collection.GeometryCollection object at 0x...>
>>> from pprint import pprint
>>> pprint(list(x))
[<shapely.geometry.point.Point object at 0x...>,
 <shapely.geometry.linestring.LineString object at 0x...>]

(Source codepnghires.pngpdf)

Figure 5. a) a green and a yellow line that intersect along a line and at a single point; b) the intersection (in blue) is a collection containing one LineString  and one Point.图5. a) 一条绿色和一条黄色的线,在一条线和一个点上相交;b) 交点(蓝色)是一个包含一个LineString和一个Point的集合。

Members of a GeometryCollection are accessed via the geoms property or via the iterator protocol using in or list().

几何集合(GeometryCollection)的成员可以通过geoms属性或通过in、list()的迭代器协议来访问。

>>> pprint(list(x.geoms))
[<shapely.geometry.point.Point object at 0x...>,
 <shapely.geometry.linestring.LineString object at 0x...>]
>>> pprint(list(x))
[<shapely.geometry.point.Point object at 0x...>,
 <shapely.geometry.linestring.LineString object at 0x...>]

Collections can also be sliced.

集合也可以执行切片操作。

>>> from shapely.geometry import MultiPoint
>>> m = MultiPoint([(0, 0), (1, 1), (1,2), (2,2)])
>>> m[:1].wkt
'MULTIPOINT (0.0000000000000000 0.0000000000000000)'
>>> m[3:].wkt
'MULTIPOINT (2.0000000000000000 2.0000000000000000)'
>>> m[4:].wkt
'GEOMETRYCOLLECTION EMPTY'

New in version 1.2.14.

Note

When possible, it is better to use one of the homogeneous collection types described below.

在可能的情况下,最好使用下面描述的同质化集合类型之一。

标签 ,

我们要如何帮助您?

欢迎留下您的宝贵建议

Please enter your comment!
Please enter your name here