Skip to content

Add node_geom_col and set_point_nodes in contiguity graph and group_nodes#95

Merged
yu-ta-sato merged 6 commits intoc2g-dev:mainfrom
yu-ta-sato:add_node_geom_col_in_contiguity_graph
Dec 28, 2025
Merged

Add node_geom_col and set_point_nodes in contiguity graph and group_nodes#95
yu-ta-sato merged 6 commits intoc2g-dev:mainfrom
yu-ta-sato:add_node_geom_col_in_contiguity_graph

Conversation

@yu-ta-sato
Copy link
Collaborator

Description

This pull request introduces enhanced flexibility for controlling node geometries in proximity and contiguity graph construction functions within city2graph/proximity.py. The main improvements allow users to specify custom point geometries for polygon nodes (instead of always using centroids), and to optionally swap polygon geometries for points while preserving the original shapes.

The most important changes are:

API Enhancements: Polygon Node Geometry Control

  • Added node_geom_col and set_point_nodes parameters to group_nodes and contiguity_graph, allowing users to specify a custom column of point geometries for nodes and to swap polygon geometries for points while preserving original geometries. [1] [2] [3] [4]
  • Modified internal logic so that, when these options are used, node positions and edge computations use the provided point geometries rather than centroids. [1] [2] [3]

Edge Construction Logic

  • Updated _edges_gdf_from_pairs to accept custom polygon node positions for accurate edge geometry and weight calculation when node geometries are overridden. [1] [2]

Graph Metadata

  • The graph now records which columns were used for node geometries and the index names in its metadata for better traceability.

Testing and Validation

  • Added tests to cover custom node geometry columns, swapping to point nodes, preservation of original geometries, and error handling for missing columns in both group_nodes and contiguity_graph. [1] [2]

These changes provide more control and transparency over how spatial graphs are constructed, making the API more flexible for advanced spatial analysis workflows.

Related Issues

NA

Checklist

  • I have read the Contributing Guide.
  • I have updated the documentation, if necessary.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Pre-commit checks passed locally.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yu-ta-sato yu-ta-sato merged commit 08a8bc1 into c2g-dev:main Dec 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant