Constructs a spatial weights matrix (.swm) file to represent the spatial relationships among features in a dataset.
Learn more about how Generate Spatial Weights Matrix works
Constructs a spatial weights matrix (.swm) file to represent the spatial relationships among features in a dataset.
Learn more about how Generate Spatial Weights Matrix works
This tool honors the Environment output coordinate system. Feature geometry is projected to the output coordinate system prior to analysis, so values entered for the Threshold Distance parameter use the same units as those specified in the output coordinate system. All mathematical computations are based on the output coordinate system. Consequently, if the output coordinate system does not match the input feature class spatial reference, either make sure, for all analyses using the spatial weights matrix file, that the output coordinate system matches the settings used when the spatial weights matrix file was created. Alternatively, project the feature class so that its spatial reference matches the spatial reference associated with the spatial weights matrix file.
Whenever using a distancebased Conceptualization of Spatial Relationships, you should project your data using a Projected Coordinate System (rather than a Geographic Coordinate System based on degrees, minutes, and seconds) prior to analysis. To avoid confusion, this projection should match the Environment output coordinate system settings.
The Unique ID field is used to relate features to one another (the relationship or weight between features 1 and 5, for example). Consequently, the Unique ID field values must be unique for every feature and typically should be a permanent field that will remain with the feature class. If you don't have a unique ID field, you can easily create one by adding a new integer field to your feature class table, and calculating the field values to be equal to the FID/OID field. You cannot use the FID/OID field directly for the Unique ID parameter.
The Polygon Contiguity Conceptualizations of Spatial Relationships are only valid for polygon features. These options are available with the ArcInfo license only.
The Number of Neighbors parameter may override the Threshold Distance parameter for Inverse or Fixed Distance Conceptualizations of Spatial Relationships. If you specify a threshold distance of 10 miles and 3 for the number of neighbors, all features will receive a minimum of 3 neighbors even if the threshold has to be increased to find them.
Whenever 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. This can lead to unexpected results.
Parameter  Explanation  Datatype 

Input Feature Class (Required) 
The feature class for which spatial relationships of features will be assessed.

Feature Class 
Unique ID Field (Required) 
An integer field containing a different value for every feature in the Input Feature Class.

Field 
Output Spatial Weights Matrix File (Required) 
The full pathname for the spatial weights matrix file (.swm) you want to create.

File 
Conceptualization of Spatial Relationships (Required) 
Specifies how spatial relationships among features are conceptualized.
Note: Polygon Contiguity methods are only available with an ArcInfo license.

String 
Distance Method (Optional) 
Specifies how distances among features are calculated.

String 
Exponent (Optional) 
Parameter for inverse distance calculation. Typical values are 1 or 2.

Double 
Threshold Distance (Optional) 
Specifies a cutoff distance for Inverse Distance and Fixed Distance conceptualizations of spatial relationships. Enter this value using the units specified in the environment output coordinate system. A value of zero indicates that no threshold distance is applied. When this parameter is left blank, a default threshold value is computed based on output feature class extent and the number of features.

Double 
Number of Neighbors (Optional) 
An integer reflecting either the minimum or the exact number of neighbors. For K_NEAREST_NEIGHBORS, each feature will have exactly this specified number of neighbors. For INVERSE_DISTANCE or FIXED_DISTANCE each feature will have at least this many neighbors (the threshold distance will be extended to ensure this many neighbors, if necessary). When there are island polygons and one of the CONTIGUITY Conceptualizations of Spatial Relationships is selected, then this specified number of nearest polygons will be associated with those island polygons.

Integer 
Row Standardization (Optional) 
Row standardization is recommended whenever feature distribution is potentially biased due to sampling design or to an imposed aggregation scheme.

Boolean 
Input Table (Optional) 
A table containing numeric weights relating every feature to every other feature in the input feature class. Required fields are <input feature class Unique ID field>, NID (neighbor ID), and WEIGHT.

File 
# Create a Spatial Weights Matrix based on kNearest Neighbors and use # it to analyze the spatial distribution of per capita incomes in US # counties in 1969 and 2002 # Import system modules import arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(9.3) gp.OverwriteOutput = 1 # Local variables... workspace = "C:\Data\USCounties\US" try: # 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 (Can be based off input or output FC) # Process: Generate Spatial Weights Matrix... swm = gp.GenerateSpatialWeightsMatrix("USCounties.shp", "MYID", "euclidean6Neighs.swm", "K_NEAREST_NEIGHBORS", "#", "#", "#", 6) # Calculate Moran's Index of Spatial Autocorrelation for # per capita incomes in 1969 using a SWM File. # Process: Spatial Autocorrelation (Morans I)... moransI69 = gp.SpatialAutocorrelation("USCounties.shp", "PCR1969", "false", "Get Spatial Weights From File", "Euclidean Distance", "None", "#", "euclidean6Neighs.swm") # Calculate Moran's Index of Spatial Autocorrelation for # per capita incomes in 2002 using a SWM File. # Process: Spatial Autocorrelation (Morans I)... moransI02 = gp.SpatialAutocorrelation("USCounties.shp", "PCR2002", "false", "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 gp.GetMessages()