Generate Spatial Weights Matrix (Spatial Statistics)

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


Illustration

Spatial Weights based on Polygon Contiguity.

Usage tips

Syntax

GenerateSpatialWeightsMatrix_stats (Input_Feature_Class, Unique_ID_Field, Output_Spatial_Weights_Matrix_File, Conceptualization_of_Spatial_Relationships, Distance_Method, Exponent, Threshold_Distance, Number_of_Neighbors, Row_Standardization, Input_Table)
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.

  • Inverse Distance—The impact of one feature on another feature decreases with distance.
  • Fixed Distance—Everything within a specified critical distance of each feature is included in the analysis; everything outside the critical distance is excluded.
  • K Nearest Neighbors—The closest "k" features are included in the analysis; k is a specified numeric parameter.
  • Polygon Contiguity (Edges Only)—Polygon features that share a boundary are neighbors.
  • Polygon Contiguity (Edges and Corners)—Polygon features that share a boundary and/or share a node are neighbors.
  • Delaunay Triangulation—A mesh of non-overlapping triangles is created from feature centroids; features associated with triangle nodes that share edges are neighbors.
  • Convert Table—Spatial relationships are defined in a table.

Note: Polygon Contiguity methods are only available with an ArcInfo license.

String
Distance Method (Optional)

Specifies how distances among features are calculated.

  • Euclidean (as the crow flies)—The straight-line distance between two points.
  • Manhattan (city block)—The distance between two points measured along axes at right angles. Calculated by summing the (absolute) differences between point coordinates.

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.

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

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
Data types for geoprocessing tool parameters

Script Example

# Create a Spatial Weights Matrix based on k-Nearest 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()

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 Network Spatial Weights (Spatial Statistics)