Networks between two point sets are built with from_point_sets, tagged with bipartite¶
SpatialNetwork.from_point_sets(origins, targets, ...) builds an undirected network across two sets of points, such as schools and clinics or schools and fibre nodes, using the same unit-sphere KD-tree and haversine lengths as from_points and connect_points. Each origin links to its k nearest targets (connect="knn", k=1 by default) or to every target within max_distance metres (connect="distance"), and all points from both sets stay as nodes even when max_distance leaves them without edges. within ("none", "origins", "targets", or "both", with optional within_k and within_max_distance overrides) adds links inside either set: within="origins" lets ConnectionPlanner route schools through nearby schools to reach a fibre root instead of forcing every school onto a direct link to its nearest root.
Every node keeps kind="point" and carries bipartite (0 for origins, 1 for targets) in all within modes, and SpatialNetwork.distance_table uses bipartite == 0 and 1 as its default origins and targets when producing a long ["origin", "target", "distance"] table of finite reachable pairs for spopt and access. build_distance_graph in gigaspatial.processing.algorithms is deprecated (to be removed in 0.12) and delegates to from_points and from_point_sets, and EntityTable.to_distance_graph and to_distance_graph_with index entities by e.id rather than positional row numbers.
Considered options¶
- Chaining
from_pointsandconnect_pointsinstead of a constructor. Rejected:within="none"has no edge-less starting network fromfrom_points;from_points(origins).connect_points(targets)searches from each target tokorigins (the reverse KNN direction); andconnect_pointsdrops isolated points beyondmax_distance. - New
NODE_KINDS("origin","target") instead of abipartitecolumn. Rejected:kindrecords structural roles ("road","point","split") thatsimplifyandconnect_pointsbranch on, whereasbipartite(0and1) is the node attributenetworkx.algorithms.bipartiteexpects afterto_networkx(). - Setting
bipartiteonly whenwithin="none". Rejected: keepingbipartitein allwithinmodes gives one way to select origins and targets (nodes["bipartite"] == 0) and letsdistance_table()find its default sets even when within-set edges are present. - Auto-prefixing clashing IDs between
originsandtargets. Rejected: rewriting node IDs behind the caller's back breaks downstream calls such asConnectionPlanner(net, terminals=schools.index, roots=fibre.index)because the network's node IDs no longer match the caller's tables. Colliding IDs raiseValueError, asinsert_points,connect_points, andadd_nodesdo, and emptyoriginsortargetsraiseValueErrorpointing tofrom_points.
Consequences¶
- When
within != "none", the network has intra-set edges and is not mathematically bipartite (nx.is_bipartite(G)isFalse), even though nodes carrybipartite(0and1) to identify their set. EntityTable.to_distance_graph_withno longer silently merges row0of both tables into a single graph node; if two tables share an entityid,from_point_setsraisesValueError.