spacenet.utils.spatial_network_from_points#
- spacenet.utils.spatial_network_from_points(points, network_type='Delaunay', inverse_distance_function=None, min_edge_distance=0, max_edge_distance=inf, number_of_nearest_neighbours=10, node_ids=None)#
Generates a spatial network using set of node coordinates. Edges will be created between objects based on the selected network type and distance constraints. Edge weights for ‘Distance’ and ‘Inverse Distance’ will be added to the network. Node indices correspond to the indices of the input points array. Nodes will have a ‘position’ attribute corresponding to their spatial coordinates from the input points array.
- Parameters:
- pointsnp.array
An array of coordinates relating to the spatial location of each node to be used for network generation.
- network_typestr, optional
The type of network to generate. Options are ‘Delaunay’ (Delaunay triangulation), ‘KNN’ (K-nearest neighbour), ‘Proximity’ and ‘RNG’ (relative neighbourhood graph).
- inverse_distance_functioncallable, optional
Function to compute inverse distance, by default None.
- min_edge_distancefloat, optional
Minimum edge distance, by default 0.
- max_edge_distancefloat, optional
Maximum edge distance, by default np.inf.
- number_of_nearest_neighboursint, optional
Number of nearest neighbours for KNN. Only used for KNN networks, by default 10.
- node_idsarray-like, optional
An array of custom node identifiers corresponding to the input points. If None, enumerated node indices will be used as identifiers. Default is None.
- Returns:
- networkx.Graph
The generated network. KNN networks will return a directed network (networkx.DiGraph).
Notes
Delaunay networks estimates a natural geometric triangulation for pointclouds. In spatial applications, a Delaunay network approximates contact-based connectivity using only centroid data. See Delaunay networks for more information.
K-Nearest Neighbours (KNN) networks estimates the local connectivity of points in space by connecting any object to it’s k closest objects. See KNN networks for more information.
Proximity networks define connectivity purely by distance thresholds. See Proximity networks for more information.
Relative Neighbourhood Graph (RNG) esimtates the natural connectivity of points in space. MuSpAn implements the Urquhart approximation to the RNG for computational efficiency. See RNGs for more information.
Examples
Example of generating a spatial Delaunay network from set of point locations:
import spacenet as sn # get data from the Spiral dataset sprial_df = sn.datasets.load_dataset('Spiral') points = sprial_df[['x','y']].values # generate a spatial network using the Delaunay triangulation method G = sn.utils.spatial_network_from_points(points,network_type='delaunay',max_edge_distance=75) # visualise the spatial network sn.utils.plot_spatial_network(G,edge_weight_name=None)
Example of generating a spatial proximity network from set of point locations:
import spacenet as sn # get data from the Spiral dataset sprial_df = sn.datasets.load_dataset('Spiral') points = sprial_df[['x','y']].values # generate a spatial network using the pure distance-based method G = sn.utils.spatial_network_from_points(points,network_type='proximity',max_edge_distance=75) # visualise the spatial network sn.utils.plot_spatial_network(G,edge_weight_name=None)
Example of generating a spatial KNN network from set of point locations:
import spacenet as sn # get data from the Spiral dataset sprial_df = sn.datasets.load_dataset('Spiral') points = sprial_df[['x','y']].values # generate a spatial network using the knn method G = sn.utils.spatial_network_from_points(points,network_type='knn',number_of_nearest_neighbours=10) # visualise the spatial network sn.utils.plot_spatial_network(G,edge_weight_name=None)
Example of generating a spatial RNG network from set of point locations:
import spacenet as sn # get data from the Spiral dataset sprial_df = sn.datasets.load_dataset('Spiral') points = sprial_df[['x','y']].values # generate a spatial network using the relative neighbourhood method G = sn.utils.spatial_network_from_points(points,network_type='rng',max_edge_distance=75) # visualise the spatial network sn.utils.plot_spatial_network(G,edge_weight_name=None)