shapely-compute
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseComputational Geometry with Shapely
基于Shapely的计算几何
When to Use
适用场景
- Creating geometric shapes (points, lines, polygons)
- Boolean operations (intersection, union, difference)
- Spatial predicates (contains, intersects, within)
- Measurements (area, length, distance, centroid)
- Geometry transformations (translate, rotate, scale)
- Validating and fixing invalid geometries
- 创建几何图形(点、线、多边形)
- 布尔运算(交集、并集、差集)
- 空间关系判断(包含、相交、在内部)
- 测量(面积、长度、距离、质心)
- 几何变换(平移、旋转、缩放)
- 验证与修复无效几何图形
Quick Reference
速查指南
| I want to... | Command | Example |
|---|---|---|
| Create geometry | | |
| Intersection | | |
| Check contains | | |
| Calculate area | | |
| Distance | | |
| Transform | | |
| Validate | | |
| 我想要... | 命令 | 示例 |
|---|---|---|
| 创建几何图形 | | |
| 求交集 | | |
| 检查包含关系 | | |
| 计算面积 | | |
| 计算距离 | | |
| 变换图形 | | |
| 验证有效性 | | |
Commands
命令说明
create
create
Create geometric objects from coordinates.
bash
undefined从坐标创建几何对象。
bash
undefinedPoint
Point
uv run python scripts/shapely_compute.py create point --coords "1,2"
uv run python scripts/shapely_compute.py create point --coords "1,2"
Line (2+ points)
Line (2+ points)
uv run python scripts/shapely_compute.py create line --coords "0,0 1,1 2,0"
uv run python scripts/shapely_compute.py create line --coords "0,0 1,1 2,0"
Polygon (3+ points, auto-closes)
Polygon (3+ points, auto-closes)
uv run python scripts/shapely_compute.py create polygon --coords "0,0 1,0 1,1 0,1"
uv run python scripts/shapely_compute.py create polygon --coords "0,0 1,0 1,1 0,1"
Polygon with hole
Polygon with hole
uv run python scripts/shapely_compute.py create polygon --coords "0,0 10,0 10,10 0,10" --holes "2,2 8,2 8,8 2,8"
uv run python scripts/shapely_compute.py create polygon --coords "0,0 10,0 10,10 0,10" --holes "2,2 8,2 8,8 2,8"
MultiPoint
MultiPoint
uv run python scripts/shapely_compute.py create multipoint --coords "0,0 1,1 2,2"
uv run python scripts/shapely_compute.py create multipoint --coords "0,0 1,1 2,2"
MultiLineString (pipe-separated lines)
MultiLineString (pipe-separated lines)
uv run python scripts/shapely_compute.py create multilinestring --coords "0,0 1,1|2,2 3,3"
uv run python scripts/shapely_compute.py create multilinestring --coords "0,0 1,1|2,2 3,3"
MultiPolygon (pipe-separated polygons)
MultiPolygon (pipe-separated polygons)
uv run python scripts/shapely_compute.py create multipolygon --coords "0,0 1,0 1,1 0,1|2,2 3,2 3,3 2,3"
undefineduv run python scripts/shapely_compute.py create multipolygon --coords "0,0 1,0 1,1 0,1|2,2 3,2 3,3 2,3"
undefinedop (operations)
op (operations)
Boolean geometry operations.
bash
undefined几何布尔运算。
bash
undefinedIntersection of two polygons
两个多边形的交集
uv run python scripts/shapely_compute.py op intersection
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POLYGON((1 1,3 1,3 3,1 3,1 1))"
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POLYGON((1 1,3 1,3 3,1 3,1 1))"
uv run python scripts/shapely_compute.py op intersection
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POLYGON((1 1,3 1,3 3,1 3,1 1))"
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POLYGON((1 1,3 1,3 3,1 3,1 1))"
Union
并集
uv run python scripts/shapely_compute.py op union --g1 "POLYGON(...)" --g2 "POLYGON(...)"
uv run python scripts/shapely_compute.py op union --g1 "POLYGON(...)" --g2 "POLYGON(...)"
Difference (g1 - g2)
差集(g1 - g2)
uv run python scripts/shapely_compute.py op difference --g1 "POLYGON(...)" --g2 "POLYGON(...)"
uv run python scripts/shapely_compute.py op difference --g1 "POLYGON(...)" --g2 "POLYGON(...)"
Symmetric difference (XOR)
对称差集(异或)
uv run python scripts/shapely_compute.py op symmetric_difference --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py op symmetric_difference --g1 "..." --g2 "..."
Buffer (expand/erode)
缓冲(扩展/侵蚀)
uv run python scripts/shapely_compute.py op buffer --g1 "POINT(0 0)" --g2 "1.5"
uv run python scripts/shapely_compute.py op buffer --g1 "POINT(0 0)" --g2 "1.5"
Convex hull
凸包
uv run python scripts/shapely_compute.py op convex_hull --g1 "MULTIPOINT((0 0),(1 1),(0 2),(2 0))"
uv run python scripts/shapely_compute.py op convex_hull --g1 "MULTIPOINT((0 0),(1 1),(0 2),(2 0))"
Envelope (bounding box)
外包矩形(边界框)
uv run python scripts/shapely_compute.py op envelope --g1 "POLYGON(...)"
uv run python scripts/shapely_compute.py op envelope --g1 "POLYGON(...)"
Simplify (reduce points)
简化(减少点数)
uv run python scripts/shapely_compute.py op simplify --g1 "LINESTRING(...)" --g2 "0.5"
undefineduv run python scripts/shapely_compute.py op simplify --g1 "LINESTRING(...)" --g2 "0.5"
undefinedpred (predicates)
pred (predicates)
Spatial relationship tests (returns boolean).
bash
undefined空间关系测试(返回布尔值)。
bash
undefinedDoes polygon contain point?
多边形是否包含点?
uv run python scripts/shapely_compute.py pred contains
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POINT(1 1)"
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POINT(1 1)"
uv run python scripts/shapely_compute.py pred contains
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POINT(1 1)"
--g1 "POLYGON((0 0,2 0,2 2,0 2,0 0))"
--g2 "POINT(1 1)"
Do geometries intersect?
几何图形是否相交?
uv run python scripts/shapely_compute.py pred intersects --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred intersects --g1 "..." --g2 "..."
Is g1 within g2?
g1是否在g2内部?
uv run python scripts/shapely_compute.py pred within --g1 "POINT(1 1)" --g2 "POLYGON(...)"
uv run python scripts/shapely_compute.py pred within --g1 "POINT(1 1)" --g2 "POLYGON(...)"
Do geometries touch (share boundary)?
几何图形是否相切(共享边界)?
uv run python scripts/shapely_compute.py pred touches --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred touches --g1 "..." --g2 "..."
Do geometries cross?
几何图形是否交叉?
uv run python scripts/shapely_compute.py pred crosses --g1 "LINESTRING(...)" --g2 "LINESTRING(...)"
uv run python scripts/shapely_compute.py pred crosses --g1 "LINESTRING(...)" --g2 "LINESTRING(...)"
Are geometries disjoint (no intersection)?
几何图形是否不相交?
uv run python scripts/shapely_compute.py pred disjoint --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred disjoint --g1 "..." --g2 "..."
Do geometries overlap?
几何图形是否重叠?
uv run python scripts/shapely_compute.py pred overlaps --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred overlaps --g1 "..." --g2 "..."
Are geometries equal?
几何图形是否相等?
uv run python scripts/shapely_compute.py pred equals --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred equals --g1 "..." --g2 "..."
Does g1 cover g2?
g1是否覆盖g2?
uv run python scripts/shapely_compute.py pred covers --g1 "..." --g2 "..."
uv run python scripts/shapely_compute.py pred covers --g1 "..." --g2 "..."
Is g1 covered by g2?
g1是否被g2覆盖?
uv run python scripts/shapely_compute.py pred covered_by --g1 "..." --g2 "..."
undefineduv run python scripts/shapely_compute.py pred covered_by --g1 "..." --g2 "..."
undefinedmeasure
measure
Geometric measurements.
bash
undefined几何测量。
bash
undefinedArea (polygons)
面积(多边形)
uv run python scripts/shapely_compute.py measure area --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"
uv run python scripts/shapely_compute.py measure area --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"
Length (lines, polygon perimeter)
长度(线、多边形周长)
uv run python scripts/shapely_compute.py measure length --geom "LINESTRING(0 0,3 4)"
uv run python scripts/shapely_compute.py measure length --geom "LINESTRING(0 0,3 4)"
Centroid
质心
uv run python scripts/shapely_compute.py measure centroid --geom "POLYGON((0 0,2 0,2 2,0 2,0 0))"
uv run python scripts/shapely_compute.py measure centroid --geom "POLYGON((0 0,2 0,2 2,0 2,0 0))"
Bounds (minx, miny, maxx, maxy)
边界范围(minx, miny, maxx, maxy)
uv run python scripts/shapely_compute.py measure bounds --geom "POLYGON(...)"
uv run python scripts/shapely_compute.py measure bounds --geom "POLYGON(...)"
Exterior ring (polygon only)
外环(仅适用于多边形)
uv run python scripts/shapely_compute.py measure exterior_ring --geom "POLYGON(...)"
uv run python scripts/shapely_compute.py measure exterior_ring --geom "POLYGON(...)"
All measurements at once
一次性获取所有测量值
uv run python scripts/shapely_compute.py measure all --geom "POLYGON((0 0,2 0,2 2,0 2,0 0))"
undefineduv run python scripts/shapely_compute.py measure all --geom "POLYGON((0 0,2 0,2 2,0 2,0 0))"
undefineddistance
distance
Distance between geometries.
bash
uv run python scripts/shapely_compute.py distance --g1 "POINT(0 0)" --g2 "POINT(3 4)"几何图形之间的距离。
bash
uv run python scripts/shapely_compute.py distance --g1 "POINT(0 0)" --g2 "POINT(3 4)"Returns: {"distance": 5.0, "g1_type": "Point", "g2_type": "Point"}
返回: {"distance": 5.0, "g1_type": "Point", "g2_type": "Point"}
undefinedundefinedtransform
transform
Affine transformations.
bash
undefined仿射变换。
bash
undefinedTranslate (move)
平移(移动)
uv run python scripts/shapely_compute.py transform translate
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "5,10"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "5,10"
uv run python scripts/shapely_compute.py transform translate
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "5,10"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "5,10"
params: dx,dy or dx,dy,dz
params: dx,dy 或 dx,dy,dz
Rotate (degrees, around centroid by default)
旋转(角度,默认围绕质心)
uv run python scripts/shapely_compute.py transform rotate
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "45"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "45"
uv run python scripts/shapely_compute.py transform rotate
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "45"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "45"
params: angle or angle,origin_x,origin_y
params: 角度 或 角度,origin_x,origin_y
Scale (from centroid by default)
缩放(默认围绕质心)
uv run python scripts/shapely_compute.py transform scale
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "2,2"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "2,2"
uv run python scripts/shapely_compute.py transform scale
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "2,2"
--geom "POLYGON((0 0,1 0,1 1,0 1,0 0))" --params "2,2"
params: sx,sy or sx,sy,origin_x,origin_y
params: sx,sy 或 sx,sy,origin_x,origin_y
Skew
斜切
uv run python scripts/shapely_compute.py transform skew
--geom "POLYGON(...)" --params "15,0"
--geom "POLYGON(...)" --params "15,0"
uv run python scripts/shapely_compute.py transform skew
--geom "POLYGON(...)" --params "15,0"
--geom "POLYGON(...)" --params "15,0"
params: xs,ys (degrees)
params: xs,ys(角度)
undefinedundefinedvalidate / makevalid
validate / makevalid
Check and fix geometry validity.
bash
undefined检查并修复几何图形的有效性。
bash
undefinedCheck if valid
检查是否有效
uv run python scripts/shapely_compute.py validate --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"
uv run python scripts/shapely_compute.py validate --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"
Returns: {"is_valid": true, "type": "Polygon", ...}
返回: {"is_valid": true, "type": "Polygon", ...}
Fix invalid geometry (self-intersecting, etc.)
修复无效几何图形(自相交等问题)
uv run python scripts/shapely_compute.py makevalid --geom "POLYGON((0 0,2 2,2 0,0 2,0 0))"
undefineduv run python scripts/shapely_compute.py makevalid --geom "POLYGON((0 0,2 2,2 0,0 2,0 0))"
undefinedcoords
coords
Extract coordinates from geometry.
bash
uv run python scripts/shapely_compute.py coords --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"从几何图形中提取坐标。
bash
uv run python scripts/shapely_compute.py coords --geom "POLYGON((0 0,1 0,1 1,0 1,0 0))"Returns: {"coords": [[0,0],[1,0],[1,1],[0,1],[0,0]], "type": "Polygon"}
返回: {"coords": [[0,0],[1,0],[1,1],[0,1],[0,0]], "type": "Polygon"}
undefinedundefinedfromwkt
fromwkt
Parse WKT and get geometry information.
bash
uv run python scripts/shapely_compute.py fromwkt "POLYGON((0 0,1 0,1 1,0 1,0 0))"解析WKT并获取几何图形信息。
bash
uv run python scripts/shapely_compute.py fromwkt "POLYGON((0 0,1 0,1 1,0 1,0 0))"Returns: {"type": "Polygon", "bounds": [...], "area": 1.0, ...}
返回: {"type": "Polygon", "bounds": [...], "area": 1.0, ...}
undefinedundefinedGeometry Types
几何类型
- - Single coordinate (x, y) or (x, y, z)
point - /
line- Sequence of connected pointslinestring - - Closed shape with optional holes
polygon - ,
multipoint,multilinestring- Collectionsmultipolygon
- - 单个坐标(x, y)或(x, y, z)
point - /
line- 连续点序列linestring - - 闭合图形,可包含孔洞
polygon - ,
multipoint,multilinestring- 集合类型multipolygon
Input Formats
输入格式
- Coordinates string: (space-separated x,y pairs)
"0,0 1,0 1,1 0,1" - WKT:
"POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))"
- 坐标字符串: (空格分隔的x,y对)
"0,0 1,0 1,1 0,1" - WKT:
"POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))"
Output Format
输出格式
All commands return JSON with:
- : WKT representation of result geometry
wkt - : Geometry type (Point, LineString, Polygon, etc.)
type - : (minx, miny, maxx, maxy)
bounds - ,
is_valid: Validity flagsis_empty - Measurement-specific fields (area, length, distance, etc.)
所有命令返回JSON格式数据,包含:
- : 结果几何图形的WKT表示
wkt - : 几何类型(Point, LineString, Polygon等)
type - : (minx, miny, maxx, maxy)
bounds - ,
is_valid: 有效性标记is_empty - 测量相关字段(area, length, distance等)
Common Use Cases
常见使用场景
| Use Case | Command |
|---|---|
| Collision detection | |
| Point-in-polygon | |
| Area calculation | |
| Buffer zones | |
| Shape combination | |
| Shape subtraction | |
| Bounding box | |
| Simplify path | |
| 使用场景 | 命令 |
|---|---|
| 碰撞检测 | |
| 点-in-多边形判断 | |
| 面积计算 | |
| 缓冲区域生成 | |
| 图形合并 | |
| 图形裁剪 | |
| 边界框获取 | |
| 路径简化 | |
Related Skills
相关技能
- - Full math orchestration (SymPy, Z3)
/math-mode - - Visualization with matplotlib
/math-plot
- - 完整数学编排(SymPy, Z3)
/math-mode - - 基于matplotlib的可视化
/math-plot