Shapely是一个Python库,用于操作和分析笛卡尔坐标系中的几何对象。
本文通过部分示例介绍了空间处理库Shape的部分概念与操作函数。
官方文档:https://shapely.readthedocs.io/en/latest/manual.html#introduction
1、函数列表
函数类型 | 算子名称 | Shapely包提供的函数 |
获取属性(各种几何对象共有的属性) | 获取面积 | object.area |
获取边界 | object.bounds | |
获取长度 | object.length | |
获取类型 | object.geom_type | |
获取距离 | object.distance(other) | |
获取hausdorff距离 | object.hausdorff_distance(other) | |
获取representative点 | object.representative_point() | |
转换为wkt格式 | object.wkt | |
是否为空 | object.is_empty | |
是否包含z坐标 | object.has_z | |
是否是有效对象 | object.is_valid | |
获取包含对象的最小凸多边形 | object.convex_hull | |
获取包含对象的最小矩形 | object.envelope | |
获取包含对象的最小边界矩形 | object.minimum_rotated_rectangle | |
获取对象右侧或左侧的一个LineString或MultiLineString | object.parallel_offset(distance, side, resolution=16, join_style=1, mitre_limit=5.0) | |
获取对象的一个简单表示 | object.simplify(tolerance, preserve_topology=True) | |
点的处理 | 获取点的坐标 | point.coords[:] |
线的处理 | 获取线的坐标 | line.coords |
是否为闭环 | line.is_ring | |
是否是简单的 | line.is_simple | |
线性环LineraRings | 获取线性环的坐标 | ring.coords |
坐标是否为逆时针 | ring.is_ccw | |
是否为闭环 | ring.is_ring | |
多边形
| 获取多边形的外环坐标 | polygon.exterior.coords |
获取多边形的内环 | polygon.interiors | |
集合 | 获取集合中各对象的类型 | collection.geoms list(collection.geoms) len(collection.geoms) 除collection类型为,其它集合类型如Multipoint、MultiLineString、MulitPolygon也支持这些操作。 |
获取两个对象的关系 | 是否完全相同:类型和坐标都相同 | object.__eq__(other) |
是否相同:边界、interior和exterior相同 | object.equals(other) | |
是否近似相同 | object.almost_equals(other[, decimal=6]) | |
是否包含 | object.contains(other) | |
是否反向包含 | object.within(other) | |
是否交叉 | object.crosses(other) | |
是否反向交叉 | object.disjoint(other) | |
是否交叉 | object.intersects(other) | |
是否覆盖 | object.overlaps(other) | |
是否接触 | object.touches(other) | |
创建新的对象 | 差集 | object.difference(other) |
交集 | object.intersection(other) | |
对称差集 | object.symmetric_difference(other) | |
并集 | object.union(other) |
2、演示(使用jupyter)