Label | Explanation | Data Type |
Input Feature Class | The point feature class for which network spatial relationships among features will be assessed. | Feature Class |
Unique ID Field | An integer field containing a different value for every feature in the input feature class. If you don't have a Unique ID field, 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 (.swm) file. | File |
Input Network | The network dataset for which spatial relationships among features in the input feature class will be defined. Network datasets most often represent street networks but may represent other kinds of transportation networks as well. The network dataset needs at least one time-based and one distance-based cost attribute. | Network Dataset Layer |
Impedance Attribute | The type of cost units to use as impedance in the analysis. | String |
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. | Double |
Maximum Number of Neighbors (Optional) | An integer reflecting the maximum number of neighbors to find for each feature. | Long |
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 Layer |
U-turn Policy (Optional) | Specifies optional U-turn restrictions.
| String |
Restrictions (Optional) | A list of restrictions. Check the restrictions to be honored in spatial relationship computations. | String |
Use Hierarchy in Analysis (Optional) | Specifies whether to use a hierarchy in the analysis.
| Boolean |
Search Tolerance (Optional) | 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 (Optional) | Specifies how the weighting associated with each spatial relationship is specified.
| String |
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. | Double |
Row Standardization (Optional) | Specifies whether row standardization is applied. Row standardization is recommended whenever feature distribution is potentially biased due to sampling design or to an imposed aggregation scheme.
| Boolean |
Travel Mode
(Optional) | The mode of transportation for the analysis. Custom is always a choice. For other travel modes to appear, they must be present in the network dataset specified in the Network Dataset parameter. A travel mode is defined on a network dataset and provides override values for parameters that model car, truck, pedestrian, or other modes of travel. | String |
Time of Day
(Optional) | Specifies whether travel times should consider traffic conditions. Especially in urbanized areas, traffic conditions can significantly impact the area covered within a specified travel time. If no date or time is specified, the distance covered during a specified travel time will not be impacted by traffic. | Date |
Available with Network Analyst license.
Summary
Constructs a spatial weights matrix file (.swm) using a Network dataset, defining feature spatial relationships in terms of the underlying network structure.
Legacy:
This is a deprecated tool. A new tool has been created with enhancements and new functionality including accepting networks from portal services. See the updated Generate Network Spatial Weights Matrix tool.
Illustration
Usage
-
Output from this tool is a spatial weights matrix file (.swm). Tools that require you to specify a Conceptualization of Spatial Relationships option will accept a spatial weights matrix file; select GET_SPATIAL_WEIGHTS_FROM_FILE for the Conceptualization of Spatial Relationships parameter and, for the Weights Matrix File parameter, specify the full path to the spatial weights file created using this tool.
-
This tool is designed to work with point Input Feature Class data only.
-
A spatial weights matrix quantifies the spatial relationships that exist among the features in your dataset. Many tools in the Spatial Statistics toolbox evaluate each feature within the context of its neighboring features. The spatial weights matrix file defines those neighbor relationships. For this tool, neighbor relationships are based on the time or distance between features, in the case where travel is restricted to a network. For more information about spatial weights and spatial weights matrix files, see Spatial weights.
-
The Unique ID field is linked to feature relationships derived from running this tool. Consequently, the Unique ID values must be unique for every feature and typically should be in a permanent field that remains with the feature class. If you don't have a unique ID field, you can create one by adding a new integer field (Add Field) to your feature class table and calculating the field values to be equal to the FID or OBJECTID field (Calculate 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 parameter.
-
The Maximum Number of Neighbors parameter specifies the exact number of neighbors that will be associated with each feature. The Impedance Cutoff overrides the number of neighbors parameter, so some features may have fewer neighbors if the number of neighbors specified cannot be found within the cutoff distance or time.
-
You can define spatial relationships using the hierarchy in the network dataset, if it has one, using the Use Hierarchy in Analysis parameter. 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.
If you are using prebuilt network datasets from Street Map Premium for ArcGIS that use a travel mode, some parameter options may be prepopulated and cannot be changed.
-
This tool does not honor the output coordinate system environment setting. All feature geometry is projected to match the spatial reference associated with the network dataset prior to analysis. The resultant spatial weights matrix file created by this tool will reflect spatial relationships defined using the Network Dataset spatial reference. It is recommended that when performing analyses using a network spatial weights matrix file, the input feature class be projected to match the coordinate system of the network dataset used to create the network SWM.
Tip:
Many organizations maintain their own street network datasets that you may already have access to. As an alternative, Street Map Premium for ArcGIS includes prebuilt network datasets in SDC format that include North America, Latin America, Europe, the Middle East Africa, Japan, Australia, and New Zealand. These network datasets can be used directly by this tool.
Caution:
When using shapefiles, keep in mind that they cannot store null values. Tools or other procedures that create shapefiles from nonshapefile inputs may store or interpret null values as zero. In some cases, nulls are stored as very large negative values in shapefiles. This can lead to unexpected results. See Geoprocessing considerations for shapefile output for more information.
Parameters
arcpy.stats.GenerateNetworkSpatialWeights(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}, {Travel_Mode}, {Time_of_Day})
Name | Explanation | Data Type |
Input_Feature_Class | The point feature class for which network spatial relationships among features will be assessed. | Feature Class |
Unique_ID_Field | An integer field containing a different value for every feature in the input feature class. If you don't have a Unique ID field, 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 (.swm) file. | File |
Input_Network | The network dataset for which spatial relationships among features in the input feature class will be defined. Network datasets most often represent street networks but may represent other kinds of transportation networks as well. The network dataset needs at least one time-based and one distance-based cost attribute. | Network Dataset Layer |
Impedance_Attribute | The type of cost units to use as impedance in the analysis. | String |
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. | Double |
Maximum_Number_of_Neighbors (Optional) | An integer reflecting the maximum number of neighbors to find for each feature. | Long |
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 Layer |
U-turn_Policy (Optional) | Specifies optional U-turn restrictions.
| String |
Restrictions [Restriction,...] (Optional) | A list of restrictions. Check the restrictions to be honored in spatial relationship computations. | String |
Use_Hierarchy_in_Analysis (Optional) | Specifies whether to use a hierarchy in the analysis.
| Boolean |
Search_Tolerance (Optional) | 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 (Optional) | Specifies how the weighting associated with each spatial relationship is specified.
| String |
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. | Double |
Row_Standardization (Optional) | Specifies whether row standardization is applied. Row standardization is recommended whenever feature distribution is potentially biased due to sampling design or to an imposed aggregation scheme.
| Boolean |
Travel_Mode (Optional) | The mode of transportation for the analysis. Custom is always a choice. For other travel modes to appear, they must be present in the network dataset specified in the Network Dataset parameter. A travel mode is defined on a network dataset and provides override values for parameters that model car, truck, pedestrian, or other modes of travel. | String |
Time_of_Day (Optional) | Specifies whether travel times should consider traffic conditions. Especially in urbanized areas, traffic conditions can significantly impact the area covered within a specified travel time. If no date or time is specified, the distance covered during a specified travel time will not be impacted by traffic. | Date |
Code sample
The following Python window script demonstrates how to use the GenerateNetworkSpatialWeights tool.
import arcpy
arcpy.env.workspace = "c:/data"
arpcy.GenerateNetworkSpatialWeights_stats("Hospital.shp", "MyID",
"network6Neighs.swm", "Streets_ND",
"MINUTES", 10, 6, "#", "ALLOW_UTURNS",
"#", "USE_HIERARCHY", "#", "INVERSE",
1, "ROW_STANDARDIZATION")
The following stand-alone Python script demonstrates how to use the GenerateNetworkSpatialWeights 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 (required for the Generate Network Spatial Weights tool)
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...
nwm = arcpy.GenerateNetworkSpatialWeights_stats("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 = arcpy.GenerateSpatialWeightsMatrix_stats("Hospital.shp", "MYID",
"euclidean6Neighs.swm",
"K_NEAREST_NEIGHBORS",
"#", "#", "#", 6)
# Calculate Moran's Index of Spatial Autocorrelation for
# average hospital visit times using Network Spatial Weights
# Process: Spatial Autocorrelation (Morans I)...
moransINet = arcpy.SpatialAutocorrelation_stats("Hospital.shp", "VisitTime",
"NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE",
"EUCLIDEAN_DISTANCE", "NONE", "#",
"network6Neighs.swm")
# Calculate Moran's Index of Spatial Autocorrelation for
# average hospital visit times using Euclidean Spatial Weights
# Process: Spatial Autocorrelation (Morans I)...
moransIEuc = arcpy.SpatialAutocorrelation_stats("Hospital.shp", "VisitTime",
"NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE",
"EUCLIDEAN_DISTANCE", "NONE", "#",
"euclidean6Neighs.swm")
except:
# If an error occurred when running the tool, print out the error message.
print arcpy.GetMessages()
Environments
Licensing information
- Basic: Requires Network Analyst
- Standard: Requires Network Analyst
- Advanced: Requires Network Analyst