# pysal.explore.spaghetti.Network¶

class pysal.explore.spaghetti.Network(in_data=None, node_sig=11, unique_segs=True, extractgraph=True)[source]

Spatially-constrained network representation and analytical functionality.

Parameters: in_data : geopandas.GeoDataFrame or str The input geographic data. Either (1) a path to a shapefile (str); or (2) a geopandas.GeoDataFrame. node_sig : int Round the x and y coordinates of all nodes to node_sig significant digits (combined significant digits on the left and right of the decimal place). Default is 11. Set to None for no rounding. unique_segs : bool If True (default), keep only unique segments (i.e., prune out any duplicated segments). If False keep all segments. extractgraph : bool If True, extract a graph-theoretic object with no degree 2 nodes. Default is True.

Examples

Instantiate an instance of a network.

>>> import pysal.explore.spaghetti as spgh
>>> streets_file = examples.get_path('streets.shp')
>>> ntw = spgh.Network(in_data=streets_file)


Snap point observations to the network with attribute information.

>>> crimes_file = examples.get_path('crimes.shp')
>>> ntw.snapobservations(crimes_file, 'crimes', attribute=True)


And without attribute information.

>>> schools_file = examples.get_path('schools.shp')
>>> ntw.snapobservations(schools_file, 'schools', attribute=False)

Attributes: in_data : str The input shapefile. This must be in .shp format. adjacencylist : list List of lists storing node adjacency. nodes : dict Keys are tuples of node coords and values are the node ID. edge_lengths : dict Keys are tuples of sorted node IDs representing an edge and values are the length. pointpatterns : dict Keys are a string name of the pattern and values are point pattern class instances. node_coords : dict Keys are the node ID and values are the (x,y) coordinates inverse to nodes. edges : list List of edges, where each edge is a sorted tuple of node IDs. node_list : list List of node IDs. alldistances : dict Keys are the node IDs (int). Values are tuples with two elements as follows (1) a list of the shortest path distances; (2) a dict with the key being the id of the destination node and the value being a list of the shortest path. distancematrix : numpy.ndarray all network nodes (non-observations) distance matrix. graphedges : list tuples of graph edge ids. graph_lengths : dict Keys are the graph edge ids (tuple). Values are the graph edge lenght (float).

Methods

 NetworkF(pointpattern[, nsteps, …]) Computes a network constrained F-Function NetworkG(pointpattern[, nsteps, …]) Computes a network constrained G-Function NetworkK(pointpattern[, nsteps, …]) Computes a network constrained K-Function allneighbordistances(sourcepattern[, …]) Compute either all distances between i and j in a single point pattern or all distances between each i from a source pattern and all j from a destination pattern. compute_distance_to_nodes(x, y, edge) Given an observation on a network edge, return the distance to the two nodes that bound that end. compute_snap_dist(pattern, idx) Given an observation snapped to a network edge, calculate the distance from the original location to the snapped location. contiguityweights([graph, weightings]) Create a contiguity based W object. count_per_edge(obs_on_network[, graph]) Compute the counts per edge. distancebandweights(threshold[, n_proccess, …]) Create distance based weights. enum_links_node(v0) Returns the edges (links) around node. extractgraph() Using the existing network representation, create a graph-theoretic representation by removing all nodes with a neighbor incidence of two (non-articulation points). loadnetwork(filename) Load a network from a binary file saved on disk. nearestneighbordistances(sourcepattern[, …]) Compute the interpattern nearest neighbor distances or the intrapattern nearest neighbor distances between a source pattern and a destination pattern. node_distance_matrix(n_processes[, gen_tree]) Called from within allneighbordistances(), nearestneighbordistances(), and distancebandweights(). savenetwork(filename) Save a network to disk as a binary file. segment_edges(distance) Segment all of the edges in the network at either a simulate_observations(count[, distribution]) Generate a simulated point pattern on the network. snapobservations(in_data, name[, …]) Snap a point pattern shapefile to this network object.
__init__(in_data=None, node_sig=11, unique_segs=True, extractgraph=True)[source]

Methods

 NetworkF(pointpattern[, nsteps, …]) Computes a network constrained F-Function NetworkG(pointpattern[, nsteps, …]) Computes a network constrained G-Function NetworkK(pointpattern[, nsteps, …]) Computes a network constrained K-Function __init__([in_data, node_sig, unique_segs, …]) allneighbordistances(sourcepattern[, …]) Compute either all distances between i and j in a single point pattern or all distances between each i from a source pattern and all j from a destination pattern. compute_distance_to_nodes(x, y, edge) Given an observation on a network edge, return the distance to the two nodes that bound that end. compute_snap_dist(pattern, idx) Given an observation snapped to a network edge, calculate the distance from the original location to the snapped location. contiguityweights([graph, weightings]) Create a contiguity based W object. count_per_edge(obs_on_network[, graph]) Compute the counts per edge. distancebandweights(threshold[, n_proccess, …]) Create distance based weights. enum_links_node(v0) Returns the edges (links) around node. extractgraph() Using the existing network representation, create a graph-theoretic representation by removing all nodes with a neighbor incidence of two (non-articulation points). loadnetwork(filename) Load a network from a binary file saved on disk. nearestneighbordistances(sourcepattern[, …]) Compute the interpattern nearest neighbor distances or the intrapattern nearest neighbor distances between a source pattern and a destination pattern. node_distance_matrix(n_processes[, gen_tree]) Called from within allneighbordistances(), nearestneighbordistances(), and distancebandweights(). savenetwork(filename) Save a network to disk as a binary file. segment_edges(distance) Segment all of the edges in the network at either a simulate_observations(count[, distribution]) Generate a simulated point pattern on the network. snapobservations(in_data, name[, …]) Snap a point pattern shapefile to this network object.