mcpField
S
shapely-compute

shapely-compute

github.com/parcadeiデータ・データベース3.9k497 回インストール39 週間前に更新
リポジトリ

shapely-compute について

shapely-computeは、Shapelyによる計算幾何のコマンドライン操作をまとめたスキルです。空間判定、計測、変換、妥当性確認などの処理をJSONで扱えます。

主な機能

  1. 01座標からジオメトリを作成
  2. 02ジオメトリのブーリアン演算
  3. 03空間関係の判定
  4. 04面積・長さ・距離の計測
  5. 05ジオメトリの変換と検証
  6. 06WKTの解析と座標の抽出

活用シーン

  1. 01図形の交差や点の包含を判定
  2. 02面積・長さ・距離を計算
  3. 03バッファー作成や図形の結合
  4. 04無効なジオメトリの修正

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/parcadei/continuous-claude-v3 --skill shapely-compute

インストール後、Claude Code で/shapely-computeを入力して読み込まれたか確認します。

詳細

Shapely による計算幾何学

使用する場面

  • 幾何図形(点、線、ポリゴン)の作成
  • ブール演算(交差、和、差)
  • 空間述語(包含、交差、内包)
  • 計測(面積、長さ、距離、重心)
  • 幾何変換(平行移動、回転、拡大・縮小)
  • 無効なジオメトリの検証と修正

クイックリファレンス

目的コマンド例
ジオメトリを作成するcreatecreate polygon --coords "0,0 1,0 1,1 0,1"
交差op intersectionop intersection --g1 "POLYGON(...)" --g2 "POLYGON(...)"
包含を確認するpred containspred contains --g1 "POLYGON(...)" --g2 "POINT(0.5 0.5)"
面積を計算するmeasure areameasure area --geom "POLYGON(...)"
距離distancedistance --g1 "POINT(0 0)" --g2 "POINT(3 4)"
変換するtransform translatetransform translate --geom "..." --params "1,2"
検証するvalidatevalidate --geom "POLYGON(...)"

コマンド

create

座標から幾何オブジェクトを作成します。

# Point
uv run python scripts/shapely_compute.py create point --coords "1,2"

# Line (2+ points)
uv run python scripts/shapely_compute.py create line --coords "0,0 1,1 2,0"

# Polygon (3+ points, auto-closes)
uv run python scripts/shapely_compute.py create polygon --coords "0,0 1,0 1,1 0,1"

# 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"

# MultiPoint
uv run python scripts/shapely_compute.py create multipoint --coords "0,0 1,1 2,2"

# MultiLineString (pipe-separated lines)
uv run python scripts/shapely_compute.py create multilinestring --coords "0,0 1,1|2,2 3,3"

# 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"
op(演算)

ブール幾何演算を実行します。

# Intersection 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))"

# Union
uv run python scripts/shapely_compute.py op union --g1 "POLYGON(...)" --g2 "POLYGON(...)"

# Difference (g1 - g2)
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 "..."

# Buffer (expand/erode)
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))"

# Envelope (bounding box)
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"
pred(述語)

空間的な関係を判定します(ブール値を返します)。

# Does 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)"

# Do geometries intersect?
uv run python scripts/shapely_compute.py pred intersects --g1 "..." --g2 "..."

# Is g1 within g2?
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 "..."

# Do geometries cross?
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 "..."

# Do geometries overlap?
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 "..."

# Does g1 cover g2?
uv run python scripts/shapely_compute.py pred covers --g1 "..." --g2 "..."

# Is g1 covered by g2?
uv run python scripts/shapely_compute.py pred covered_by --g1 "..." --g2 "..."
measure

幾何を計測します。

# Area (polygons)
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)"

# Centroid
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)
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(...)"

# 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))"
distance

ジオメトリ間の距離を計算します。

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"}
transform

アフィン変換を実行します。

# Translate (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"
# params: dx,dy or 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"
# params: angle or angle,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"
# params: sx,sy or sx,sy,origin_x,origin_y

# Skew
uv run python scripts/shapely_compute.py transform skew \
    --geom "POLYGON(...)" --params "15,0"
# params: xs,ys (degrees)
validate / makevalid

ジオメトリの妥当性を確認し、修正します。

# Check if valid
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", ...}

# 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))"
coords

ジオメトリから座標を抽出します。

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"}
fromwkt

WKT を解析し、ジオメトリの情報を取得します。

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, ...}

ジオメトリの種類

  • point - 単一の座標(x, y)または(x, y, z)
  • line/linestring - 接続された点の列
  • polygon - 穴を含む場合もある閉じた図形
  • multipoint、multilinestring、multipolygon - コレクション

入力形式

  • 座標文字列:"0,0 1,0 1,1 0,1"(x,y の組をスペース区切りで指定)
  • WKT:"POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))"

出力形式

すべてのコマンドは、次の内容を含む JSON を返します。

  • wkt:結果のジオメトリを表す WKT
  • type:ジオメトリの種類(Point、LineString、Polygon など)
  • bounds:(minx, miny, maxx, maxy)
  • is_valid、is_empty:妥当性フラグ
  • 計測内容に応じたフィールド(area、length、distance など)

よくある使用例

使用例コマンド
衝突検出pred intersects
点がポリゴン内にあるかの判定pred contains
面積の計算measure area
バッファー領域op buffer
図形の結合op union
図形の差し引きop difference
バウンディングボックスop envelope または measure bounds
パスの単純化op simplify

関連スキル

  • /math-mode - 数学処理の統合(SymPy、Z3)
  • /math-plot - matplotlib による可視化

コメント