Generate Network Spatial Weights (Spatial Statistics)

Summary

Constructs a spatial weights matrix file (.swm) using a network dataset, defining spatial relationships in terms of the underlying network structure.

Learn more about how Generate Network Spatial Weights works

Illustration

Generate Network Spatial Weights tool illustration

Usage

  • The network dataset can come from any of the following sources:

    • A network dataset saved on a local drive or network. If your organization maintains its own street network datasets, you may already have access.
    • Logistic and routing services hosted in ArcGIS Online or ArcGIS Enterprise. If you perform an analysis using ArcGIS Online, the solver references a high-quality, worldwide network dataset stored in the ArcGIS Online cloud and consumes ArcGIS Online credits.
    • Configured network datasets provided by ArcGIS StreetMap Premium. These network datasets are in SDC format and include North America, Latin America, Europe, the Middle East, Africa, Japan, Australia, and New Zealand.

  • This tool creates a spatial weights matrix file (*.swm) as output. Various tools in the Spatial Statistics and Space Time Pattern Mining toolboxes include a Conceptualization of Spatial Relationships parameter that allows you to use this file to define the spatial relationships of the features. Using a spatial weights matrix with a network data source allows you to define spatial relationships by their distance, travel time, and cost of travel.

  • The Input Feature Class parameter value must be points. Polygons and polylines are not supported by this tool.

  • The Unique ID Field parameter is used to relate the output of this tool to the input features. If you don't have a field with unique ID values, you can create one by adding a new integer field to your feature class table and calculating the field values to equal the FID or OBJECTID field. Because the FID and OBJECTID field values may change when you copy or edit a feature class, you cannot use these fields directly for the Unique ID Field parameter.

  • The number of neighbors associated with each feature is determined by the Maximum Number of Neighbors parameter and the three impedance cutoff parameters. The tool will use as many of the closest neighbors to the input feature as possible without exceeding the maximum number of neighbors or using any features whose impedance exceeds any of the cutoff values. Impedance can be defined by distance, travel time, or cost. The types of impedance that can be used depend on the properties of the network data source and the value of the Travel Mode parameter.

  • If your network dataset has a hierarchy, it is used to define the spatial relationships. The hierarchy classifies network edges into primary, secondary, and local roads. When using the hierarchy of the network to create spatial relationships among features, preference will be given to travel on primary roads more than secondary roads and secondary roads more than local roads.

  • When the Inverse option is specified for the Conceptualization of Spatial Relationships parameter, it is recommended that you perform row standardization by checking the Row Standardization parameter. If row standardization is not performed, different distance units will result in different spatial weights.

  • All input features are projected to the spatial reference of the network dataset prior to analysis, and the network spatial weights matrix file will be built in this spatial reference. It is recommended that you perform all subsequent analysis in this spatial reference to properly represent spatial relationships.

  • The input feature class must have 32-bit ObjectID field values. 64-bit values are not supported.

Parameters

LabelExplanationData Type
Input Feature Class

The point feature class representing locations on the network. For each feature, neighbors and weights are calculated and stored in the output spatial weights matrix file.

Feature Class
Unique ID Field

An integer field containing a unique value for each feature in the input feature class. If you don't have a field with unique ID values, you can create one by adding an integer field to your feature class table and calculating the field values to equal the FID or OBJECTID field.

Field
Output Spatial Weights Matrix File

The output network spatial weights matrix file (.swm) that will store the neighbors and weights for each input feature.

File
Input Network Data Source

The network dataset used to find neighbors of each input feature. Network datasets usually represent street networks but can also represent other kinds of transportation networks such as railroads or walking paths. The network dataset must include at least one attribute related to distance, travel time, or cost.

Network Data Source
Travel Mode

The mode of transportation for the analysis. A travel mode defines how a pedestrian, car, truck, or other medium of transportation moves through the network and represents a collection of network settings, such as travel restrictions and U-turn policies.

String
Impedance Distance Cutoff

The maximum impedance distance allowed for neighbors of a feature. Any feature whose distance is farther than this value will not be used as a neighbor. By default, no distance cutoff is used.

Linear Unit
Impedance Temporal Cutoff
(Optional)

The maximum impedance travel time allowed for neighbors of a feature. Any feature whose travel time is longer than this value will not be used as a neighbor. By default, no temporal cutoff is used.

Time Unit
Impedance Cost Cutoff
(Optional)

The maximum impedance cost allowed for neighbors of a feature. Any feature whose cost of travel is larger than this value will not be used as a neighbor. By default, no cost cutoff is used.

Double
Maximum Number of Neighbors
(Optional)

An integer reflecting the maximum number of neighbors for each feature. The actual number of neighbors used for each feature may be smaller due to impedance cutoffs.

Long
Time of Day
(Optional)

The time of day traffic conditions will be considered in the analysis. Traffic conditions can impact the distance that can be traveled over a given time. If no date or time is provided, the analysis will not consider the impact of traffic.

Instead of using a particular date, you can specify a day of the week using the following dates:

  • Today-12/30/1899
  • Sunday-12/31/1899
  • Monday-1/1/1900
  • Tuesday-1/2/1900
  • Wednesday-1/3/1900
  • Thursday-1/4/1900
  • Friday-1/5/1900
  • Saturday-1/6/1900

For example, to specify that travel should begin at 5:00 p.m. on Tuesday, specify the parameter value as 1/2/1900 5:00 PM.

Date
Time Zone
(Optional)

Specifies the time zone for the Time of Day parameter.

  • Local time at locationsThe time zone in which the Input Feature Class is located will be used. This is the default.
  • UTCCoordinated universal time (UTC) will be used.
String
Barriers
(Optional)

The features that represent blocked intersections, road closures, accident sites, or other locations where travel is blocked along the network.

Feature Layer
Search Tolerance
(Optional)

The maximum distance used to assign each input feature to a location on the network. If any of the input points do not fall exactly on a line of the network, they will be assigned to the closest location on the network for the analysis. However, if the feature is farther than the search tolerance value from any location on the network, it will not be assigned to the network and will not be included in the analysis.

Linear Unit
Conceptualization of Spatial Relationships
(Optional)

Specifies how weights will be defined for each neighbor.

  • InverseFeatures farther in distance, time, or cost will have a smaller weight than features nearby. The weights decrease by their inverse to an exponent.
  • FixedAll neighbors will be given equal weight. This is the default.
String
Exponent
(Optional)

The exponent used when Inverse option is specified for the Conceptualization of Spatial Relationships parameter. The weights assigned to each neighbor are calculated by taking the inverse distance, time, or cost to the power of the exponent. The default value is 1, and the value must be between 0.01 and 4. Weights drop off more rapidly as the exponent increases.

Double
Row Standardization
(Optional)

Specifies whether row standardization will be applied. Row standardization is recommended when the locations of the input points are potentially biased due to sampling design or an imposed aggregation scheme. It is also recommended that you standardize rows when weighting neighbors based on inverse distance, time, or cost.

  • Checked—Spatial weights will be standardized by row. Each weight is divided by its row sum. This is the default.
  • Unchecked—No standardization of spatial weights will be applied.
Boolean

arcpy.stats.GenerateNetworkSWM(Input_Feature_Class, Unique_ID_Field, Output_Spatial_Weights_Matrix_File, Input_Network_Data_Source, Travel_Mode, Impedance_Distance_Cutoff, {Impedance_Temporal_Cutoff}, {Impedance_Cost_Cutoff}, {Maximum_Number_of_Neighbors}, {Time_of_Day}, {Time_Zone}, {Barriers}, {Search_Tolerance}, {Conceptualization_of_Spatial_Relationships}, {Exponent}, {Row_Standardization})
NameExplanationData Type
Input_Feature_Class

The point feature class representing locations on the network. For each feature, neighbors and weights are calculated and stored in the output spatial weights matrix file.

Feature Class
Unique_ID_Field

An integer field containing a unique value for each feature in the input feature class. If you don't have a field with unique ID values, you can create one by adding an integer field to your feature class table and calculating the field values to equal the FID or OBJECTID field.

Field
Output_Spatial_Weights_Matrix_File

The output network spatial weights matrix file (.swm) that will store the neighbors and weights for each input feature.

File
Input_Network_Data_Source

The network dataset used to find neighbors of each input feature. Network datasets usually represent street networks but can also represent other kinds of transportation networks such as railroads or walking paths. The network dataset must include at least one attribute related to distance, travel time, or cost.

Network Data Source
Travel_Mode

The mode of transportation for the analysis. A travel mode defines how a pedestrian, car, truck, or other medium of transportation moves through the network and represents a collection of network settings, such as travel restrictions and U-turn policies.

An arcpy.na.TravelMode object and a string containing the valid JSON representation of a travel mode can also be used as input to the parameter.

String
Impedance_Distance_Cutoff

The maximum impedance distance allowed for neighbors of a feature. Any feature whose distance is farther than this value will not be used as a neighbor. By default, no distance cutoff is used.

Linear Unit
Impedance_Temporal_Cutoff
(Optional)

The maximum impedance travel time allowed for neighbors of a feature. Any feature whose travel time is longer than this value will not be used as a neighbor. By default, no temporal cutoff is used.

Time Unit
Impedance_Cost_Cutoff
(Optional)

The maximum impedance cost allowed for neighbors of a feature. Any feature whose cost of travel is larger than this value will not be used as a neighbor. By default, no cost cutoff is used.

Double
Maximum_Number_of_Neighbors
(Optional)

An integer reflecting the maximum number of neighbors for each feature. The actual number of neighbors used for each feature may be smaller due to impedance cutoffs.

Long
Time_of_Day
(Optional)

The time of day traffic conditions will be considered in the analysis. Traffic conditions can impact the distance that can be traveled over a given time. If no date or time is provided, the analysis will not consider the impact of traffic.

Instead of using a particular date, you can specify a day of the week using the following dates:

  • Today-12/30/1899
  • Sunday-12/31/1899
  • Monday-1/1/1900
  • Tuesday-1/2/1900
  • Wednesday-1/3/1900
  • Thursday-1/4/1900
  • Friday-1/5/1900
  • Saturday-1/6/1900

For example, to specify that travel should begin at 5:00 p.m. on Tuesday, specify the parameter value as 1/2/1900 5:00 PM.

Date
Time_Zone
(Optional)

Specifies the time zone for the Time_of_Day parameter.

  • LOCAL_TIME_AT_LOCATIONSThe time zone in which the Input_Feature_Class is located will be used. This is the default.
  • UTCCoordinated universal time (UTC) will be used.
String
Barriers
(Optional)

The features that represent blocked intersections, road closures, accident sites, or other locations where travel is blocked along the network.

Feature Layer
Search_Tolerance
(Optional)

The maximum distance used to assign each input feature to a location on the network. If any of the input points do not fall exactly on a line of the network, they will be assigned to the closest location on the network for the analysis. However, if the feature is farther than the search tolerance value from any location on the network, it will not be assigned to the network and will not be included in the analysis.

Linear Unit
Conceptualization_of_Spatial_Relationships
(Optional)

Specifies how weights will be defined for each neighbor.

  • INVERSEFeatures farther in distance, time, or cost will have a smaller weight than features nearby. The weights decrease by their inverse to an exponent.
  • FIXEDAll neighbors will be given equal weight. This is the default.
String
Exponent
(Optional)

The exponent used when INVERSE option is specified for the Conceptualization_of_Spatial_Relationships parameter. The weights assigned to each neighbor are calculated by taking the inverse distance, time, or cost to the power of the exponent. The default value is 1, and the value must be between 0.01 and 4. Weights drop off more rapidly as the exponent increases.

Double
Row_Standardization
(Optional)

Specifies whether row standardization will be applied. Row standardization is recommended when the locations of the input points are potentially biased due to sampling design or an imposed aggregation scheme. It is also recommended that you standardize rows when weighting neighbors based on inverse distance, time, or cost.

  • ROW_STANDARDIZATIONSpatial weights will be standardized by row. Each weight is divided by its row sum. This is the default.
  • NO_STANDARDIZATIONNo standardization of spatial weights will be applied.
Boolean

Code sample

GenerateNetworkSWM example 1 (Python window)

The following Python script demonstrates how to use the GenerateNetworkSWM function.

import arcpy

arcpy.env.workspace = "c:\Data"

# Use a network data source hosted on ArcGIS Online.
arcpy.stats.GenerateNetworkSWM(r"Data.gdb\Hospital", "MyID", 
                               "Hospital.swm", "https://www.arcgis.com/",
                               "Driving Time", None, None, None, None, None, 
                               "LOCAL_TIME_AT_LOCATIONS", None, "5000 Meters",
                               "FIXED", 1, "ROW_STANDARDIZATION")

# Use a network data source stored on a local drive.
arcpy.stats.GenerateNetworkSWM(r"Data.gdb\Hospital", "MyID", "Hospital.swm", 
                               r"Data.gdb\transportation\streets_ND",
                               "Driving Time", None, None, None, None, None, 
                               "LOCAL_TIME_AT_LOCATIONS", None, "5000 Meters", 
                               "FIXED", 1, "ROW_STANDARDIZATION")
GenerateNetworkSWM example 2 (stand-alone script)

The following Python script demonstrates how to use the GenerateNetworkSWM tool.

# Create a Spatial Weights Matrix based on Network Data

# Import system modules
import arcpy

# Set the environment property to overwrite existing output
arcpy.env.overwriteOutput = True

# Check out the ArcGIS Network Analyst extension 
arcpy.CheckOutExtension("Network")

# Local variables...
workspace = r"c:\Data"

try:
    # Set the current workspace (to avoid having to specify the full path to
    # the feature classes each time)
    arcpy.env.workspace = workspace

    # Create Spatial Weights Matrix based on Network Data
    # Process: Generate Network Spatial Weights...
    arcpy.stats.GenerateNetworkSWM(r"Data.gdb\Hospital","MyID", 
        "Hospital.swm", r"Data.gdb\Transportation\Streets_ND",
        "Driving Time", None, None, None, None, None, 
        "LOCAL_TIME_AT_LOCATIONS", None, "5000 Meters", "FIXED", 
        1,"ROW_STANDARDIZATION")

    # Create Spatial Weights Matrix based on Euclidean Distance
    # Process: Generate Spatial Weights Matrix...

    arcpy.stats.GenerateSpatialWeightsMatrix(
        r"Data.gdb\Hospital", "MyID", r"Euclidean6Neighs.swm", 
        "K_NEAREST_NEIGHBORS", "EUCLIDEAN", 1, None, 6, 
        "ROW_STANDARDIZATION", None, None, '', None, None)


    # Calculate Moran's Index of Spatial Autocorrelation for
    # average hospital visit times using Network Spatial Weights
    # Process: Spatial Autocorrelation (Morans I)...

    moransINet = arcpy.stats.SpatialAutocorrelation("Data.gdb\Hospital", 
                     "VisitTime", "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE",
                     "EUCLIDEAN_DISTANCE", "ROW", None, "Hospital.swm", None)

    # Calculate Moran's Index of Spatial Autocorrelation for
    # average hospital visit times using Euclidean Spatial Weights
    # Process: Spatial Autocorrelation (Morans I)...
    moransIEuc = arcpy.stats.SpatialAutocorrelation("Data.gdb\Hospital", 
                     "VisitTime", "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE",
                     "EUCLIDEAN_DISTANCE", "ROW", None, r"Euclidean6Neighs.swm", 
                     None)

except arcpy.ExecuteError:
    # If an error occurred when running the tool, print out the error message.
    print(arcpy.GetMessages())