Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

graph-conversion

БесплатноБез исполняемых скриптовНе проверен

Convert city2graph GeoDataFrame graph tables to and from NetworkX, rustworkx, and optional PyTorch Geometric representations, including heterogeneous…

lza6от lza6★ 19 звёзд на GitHub

Об этом скилле

Graph conversion

Use this skill when the task is to move a city2graph graph between its GeoDataFrame-first representation and NetworkX, rustworkx, or PyTorch Geometric (PyG), or when constructing derived heterogeneous relations with metapaths. Keep the GeoDataFrame tables as the source of truth: graph objects use integer/positional IDs and attached metadata, while the GeoDataFrame indexes carry the original node and edge identifiers.

Fast route

  1. Classify the input. Use one GeoDataFrame for a homogeneous graph, or dictionaries for a heterogeneous graph. The heterogeneous node dictionary is keyed by node type strings; the edge dictionary is keyed by (source_type, relation_type, target_type) tuples.
  2. Validate the table contract before conversion. Node IDs are the node GeoDataFrame index values. Edge endpoints are the first two levels of an edge MultiIndex; a third level is an edge key. All non-empty tables in a graph must use a consistent CRS.
  3. Choose the target. Use gdf_to_nx/nx_to_gdf for graph algorithms and attribute-preserving spatial round trips; use gdf_to_pyg/pyg_to_gdf for tensor workflows; use nx_to_pyg or pyg_to_nx when bridging formats; use nx_to_rx/rx_to_nx for rustworkx algorithms.
  4. Make semantics explicit. Decide directed, multigraph, keep_geom, feature/label columns, and (for heterogeneous PyG) reverse edge types before converting. The default PyG conversion is undirected and therefore symmetrizes safe edges.
  5. Verify the result. Check graph class, node/edge counts, edge-type stores, tensor shapes, graph_metadata, CRS, index names, and whether a round trip is expected to preserve exact geometry or only centroid/straight-line geometry.

Detailed signatures and return-shape rules are in references/api-reference.md. Heterogeneous and PyG-specific semantics are in references/heterogeneous-and-pyg.md. Error diagnosis and minimal probes are in references/troubleshooting.md.

Canonical GeoDataFrame contract

Homogeneous tables

nodes: geopandas.GeoDataFrame | None
edges: geopandas.GeoDataFrame | None
  • A node table's index is the node identifier space. A named Index is preserved by the NetworkX/PyG metadata; a MultiIndex is also supported.
  • A non-empty edge table used by PyG must have a pandas.MultiIndex with at least two levels: (source_id, target_id). The first two values are looked up in nodes.index. A third level (source, target, key) identifies a multigraph edge and is preserved.
  • NetworkX conversion can infer endpoints from the first and last coordinates of LineString geometries. If edges have no geometry, use a two-level edge MultiIndex and provide the node table; endpoint IDs are then resolved from the node index. Unknown endpoint IDs are dropped with a warning in this path.
  • Node geometries may be Points, polygons, or other valid geometries; node positions are represented by centroids when a graph/tensor format requires coordinates. Edge geometries normally are LineString or MultiLineString. Homogeneous NetworkX conversion can accept geometryless edges when their first two index levels identify endpoints and a node frame is supplied; geometryless nodes cannot provide positions.
  • Empty tables are allowed by the conversion validators. In particular, an empty edge frame may lack a MultiIndex for PyG; a non-empty one may not.
  • CRS is metadata, not a node/edge attribute. Non-empty node and edge tables must have equal CRS values. A missing CRS is accepted, but distances, lengths, and geographic-coordinate computations need caller judgment.

Heterogeneous tables

nodes = {"building": building_nodes, "road": road_nodes}
edges = {
    ("building", "connects_to", "road"): building_road_edges,
    ("road", "links_to", "road"): road_road_edges,
}
  • Every node-type key is a string. Every edge-type key is a three-string tuple.
  • Each edge frame's first index level contains IDs from its source node-type frame; its second level contains IDs from its destination node-type frame.
  • Node IDs may overlap between types because type namespaces distinguish them.
  • Heterogeneous NetworkX nodes receive node_type; heterogeneous edges receive edge_type. Heterogeneous PyG uses HeteroData stores keyed by node and edge types.
  • Validate all table CRSs together. Do not silently combine frames in different CRSs merely because their index values happen to match.

NetworkX and rustworkx route

GeoDataFrame ↔ NetworkX

from city2graph import gdf_to_nx, nx_to_gdf

G = gdf_to_nx(nodes=nodes, edges=edges,
              keep_geom=True, multigraph=False, directed=False)
nodes_back, edges_back = nx_to_gdf(G)

gdf_to_nx chooses Graph, DiGraph, MultiGraph, or MultiDiGraph from directed and `

Полный SKILL.md на GitHub

Установить graph-conversion в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/api-reference.mdreferences/heterogeneous-and-pyg.mdreferences/troubleshooting.md

FAQ

Что делает скилл graph-conversion?

Convert city2graph GeoDataFrame graph tables to and from NetworkX, rustworkx, and optional PyTorch Geometric representations, including heterogeneous relations, metadata, features, labels, directionality, multigraph keys, and metapaths.

Как установить скилл graph-conversion?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл graph-conversion запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить graph-conversion с