Generate Network Spatial Weights (Spatial Statistics)

Constructs a spatial weights matrix file (.swm) from a Network dataset which defines spatial relationships among all features in terms of an underlying network structure. Note: requires the Network Analyst extension.

Learn more about how Generate Network Spatial Weights Matrix works


Network based spatial relationships.

Usage tips


GenerateNetworkSpatialWeights_stats (Input_Feature_Class, Unique_ID_Field, Output_Spatial_Weights_Matrix_File, Input_Network, Impedance_Attribute, Impedance_Cutoff, Maximum_Number_of_Neighbors, Barriers, U-turn_Policy, Restrictions, Use_Hierarchy_in_Analysis, Search_Tolerance, Conceptualization_of_Spatial_Relationships, Exponent, Row_Standardization)
Parameter Explanation Datatype
Input Feature Class (Required)

The point feature class for which Network spatial relationships among features will be assessed.

Feature Layer
Unique ID Field (Required)

An integer field containing a different value for every feature in the Input Feature Class.

Output Spatial Weights Matrix File (Required)

The full pathname for the network spatial weights matrix file (.swm) you want to create.

OInput analysis network (Required)

The network dataset for which spatial relationships among features in the input feature class will be defined.

Network Dataset Layer
Impedance Attribute (Required)

The type of cost units to use as impedance in the analysis.

Impedance Cutoff (Optional)

Specifies a cutoff value for Inverse and Fixed conceptualizations of spatial relationships. Enter this value using the units specified by the Impedance Attribute parameter. A value of zero indicates that no threshold is applied. When this parameter is left blank, a default threshold value is computed based on input feature class extent and the number of features.

Maximum Number of Neighbors (Optional)

An integer reflecting the maximum number of neighbors to find for each feature.

Barriers (Optional)

The name of a point feature class with features representing blocked intersections, road closures, accident sites, or other locations where travel is blocked along the network.

Feature Class
U-turn Policy (Optional)

Specifies optional U-turn restrictions.

  • ALLOW_UTURNS—U-turns will be possible anywhere (default).
  • NO_UTURNS—No u-turns will be allowed during navigation.
  • ALLOW_DEAD_ENDS_ONLY—U-turns will be possible only at the dead ends (i.e., single-valent junctions).

Restrictions (Optional)

A list of restrictions. Check ON the restrictions to be honored in spatial relationship computations.

Use Hierarchy in Analysis (Optional)

Specifies whether or not to use a hierarchy in the analysis.

  • USE_HIERARCHY—Will use the network dataset's hierarchy attribute in a heuristic path algorithm to speed analysis.
  • NO_HIERARCHY—Will use an exact path algorithm instead. If there is no hierarchy attribute, this option does not affect analysis.

Search Tolerance (Required)

The search threshold used to locate features in the Input Feature Class onto the Network Dataset. This parameter includes a search value and the units for the tolerance.

Linear Unit
Conceptualization of Spatial Relationships (Required)

Specifies how the weighting associated with each spatial relationship is specified. For INVERSE, features farther away have a smaller weight than features nearby. For FIXED, features within the Impedance Cutoff of a target feature are neighbors (weight of 1); features outside the Impedance Cutoff of a target feature are not (weight of 0).

Exponent (Optional)

Parameter for the INVERSE Conceptualization of Spatial Relationships calculation. Typical values are 1 or 2. Weights drop off quicker with distance as this exponent value increases.

Row Standardization (Optional)

Row standardization is recommended whenever feature distribution is potentially biased due to sampling design or to an imposed aggregation scheme.

  • Row—Spatial weights are standardized by row. Each weight is divided by its row sum.
  • None—No standardization of spatial weights is applied.

Data types for geoprocessing tool parameters

Script Example

# Create a Spatial Weights Matrix based on Network Data 
# Import system modules
import arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
gp.OverwriteOutput = 1
# Local variables...
workspace = "C:\Data\SanFranciscoNetwork"

# Set the current workspace (to avoid having to specify the full path to the feature classes each time)
    gp.workspace = workspace

# Create Spatial Weights Matrix based on Network Data 

 # Process: Generate Network Spatial Weights... 
    nwm = gp.GenerateNetworkSpatialWeights("Hospital.shp", "MyID",
                        "network6Neighs.swm", "Streets_ND",
                        "MINUTES", 10, 6, "#", "ALLOW_UTURNS",
                        "#", "USE_HIERARCHY", "#", "INVERSE",
                        1, "ROW_STANDARDIZATION")

# Create Spatial Weights Matrix based on Euclidean Distance
    # Process: Generate Spatial Weights Matrix... 
    swm = gp.GenerateSpatialWeightsMatrix("Hospital.shp", "MYID",
                        "#", "#", "#", 6) 

# Calculate Moran's Index of Spatial Autocorrelation for 
    # average hospital visit times using Network Spatial Weights 
    # Process: Spatial Autocorrelation (Morans I)...       
    moransINet = gp.SpatialAutocorrelation("Hospital.shp", "VisitTime",
                        "false", "Get Spatial Weights From File", 
                        "Euclidean Distance", "None", "#", 

# Calculate Moran's Index of Spatial Autocorrelation for 
    # average hospital visit times using Euclidean Spatial Weights   
    # Process: Spatial Autocorrelation (Morans I)...       
    moransIEuc = gp.SpatialAutocorrelation("Hospital.shp", "VisitTime",
                        "false", "Get Spatial Weights From File", 
                        "Euclidean Distance", "None", "#", 

# If an error occurred when running the tool, print out the error message.
    print gp.GetMessages()

See Also

  • Spatial Autocorrelation (Morans I) (Spatial Statistics)
  • High/Low Clustering (Getis-Ord General G) (Spatial Statistics)
  • Cluster and Outlier Analysis: Anselin Local Moran's I (Spatial Statistics)
  • Hot Spot Analysis (Getis-Ord Gi*) (Spatial Statistics)
  • Modeling spatial relationships
  • Generate Spatial Weights Matrix (Spatial Statistics)
  • Designing the Network Dataset
  • Creating an OD Cost Matrix
  • Network analysis classes