赞
踩
主要是点(point)、线(linestring)、面(surface)
使用 Shapely 创建点时,可以直接提供 x 和 y 的坐标值,或者提供一个包含 x 和 y 值的元组
- from shapely import Point
-
- # 使用位置坐标值创建点
- point = Point(0.0, 0.0)
-
- # 使用点元组参数创建点
- q = Point((0.0, 0.0))
LineString
对象代表点之间的一个或多个连接的线性样条。有序序列中允许重复的点,但可能会导致性能损失,应该避免。LineString
可以自我交叉 line.area | 始终是0 |
line.length | 线段的长度 |
line.bounds | x-y 边界框是一个 (minx, miny, maxx, maxy) 元组 |
line.coords | 定义的坐标值可以通过 |
LinearRing
有零面积和非零长度LineString
一样,有序序列中允许重复的点,但可能会导致性能损失,应该避免。LinearRing
不能自我交叉,也不能在单个点上接触自身Polygon
类的构造函数接受两个位置参数。
LinearRing
的情况完全相同。- from shapely import Polygon
-
- poly=Polygon([(0,2),(2,2),(2,0)],
- [[(0.5, 1.5), (1.5, 1.5), (1.5, 0.5), (0.5, 0.5)]])
- poly
方形多边形
- from shapely.geometry import box
-
- box(0,0,1,2)
LineString
和 Point
,Shapely 会使用 GeometryCollection
类型来表示这些结果- from shapely.geometry import LineString
-
- a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
- b = LineString([(0, 0), (1, 1), (2,1), (2,2)])
- x = a.intersection(b)
- print(x)
- #GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), POINT (2 2))
通过 geoms
属性访问 GeometryCollection
中的成员
- list(x.geoms)
- #[<LINESTRING (0 0, 1 1)>, <POINT (2 2)>]
MultiPoint
类用于表示点的集合。
构造函数接受一个点的序列,其中每个点可以是 (x, y[, z])
形式的元组。
- from shapely import MultiPoint
- points = MultiPoint([(0.0, 0.0), (1.0, 1.0)])
- print(points.area)
- # 输出 0.0
- print(points.length)
- # 输出 0.0
MultiLineString
类表示线的集合。构造函数接受一系列类似线的序列或对象。
一个 MultiLineString
对象的面积为零,长度为非零
- from shapely import MultiLineString
- coords = [((0, 0), (1, 1)), ((-1, 0), (1, 0))]
- lines = MultiLineString(coords)
- lines
- from shapely import Polygon
- from shapely import MultiPolygon
- polygon1 = Polygon([(0, 0), (1, 1), (1, 0),(0,1)])
- polygon2 = Polygon([(0,0),(0,2),(1,1)])
-
- multiPolygon=MultiPolygon([polygon1,polygon2])
- multiPolygon
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。