graph-conversion
БесплатноБез исполняемых скриптовНе проверенConvert city2graph GeoDataFrame graph tables to and from NetworkX, rustworkx, and optional PyTorch Geometric representations, including heterogeneous…
от 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
- 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. - 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. - Choose the target. Use
gdf_to_nx/nx_to_gdffor graph algorithms and attribute-preserving spatial round trips; usegdf_to_pyg/pyg_to_gdffor tensor workflows; usenx_to_pygorpyg_to_nxwhen bridging formats; usenx_to_rx/rx_to_nxfor rustworkx algorithms. - 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. - 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
Indexis preserved by the NetworkX/PyG metadata; aMultiIndexis also supported. - A non-empty edge table used by PyG must have a
pandas.MultiIndexwith at least two levels:(source_id, target_id). The first two values are looked up innodes.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 receiveedge_type. Heterogeneous PyG usesHeteroDatastores 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 `
Установить graph-conversion в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic