Generate Spatial Weights Matrix (Spatial Statistics)

License Level:BasicStandardAdvanced

Summary

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
Spatial relationships based on polygon contiguity, Queen's case: shared edges or nodes.

Usage

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}, {Date_Time_Field}, {Date_Time_Interval_Type}, {Date_Time_Interval_Value})
ParameterExplanationData Type
Input_Feature_Class

The feature class for which spatial relationships of features will be assessed.

Feature Class
Unique_ID_Field

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

Field
Output_Spatial_Weights_Matrix_File

The full path for the spatial weights matrix file (SWM) you want to create.

File
Conceptualization_of_Spatial_Relationships

Specifies how spatial relationships among features are conceptualized.

  • INVERSE_DISTANCEThe impact of one feature on another feature decreases with distance.
  • FIXED_DISTANCEEverything within a specified critical distance of each feature is included in the analysis; everything outside the critical distance is excluded.
  • K_NEAREST_NEIGHBORSThe closest k features are included in the analysis; k is a specified numeric parameter.
  • CONTIGUITY_EDGES_ONLYPolygon features that share a boundary are neighbors.
  • CONTIGUITY_EDGES_CORNERSPolygon features that share a boundary and/or share a node are neighbors.
  • DELAUNAY_TRIANGULATIONA mesh of nonoverlapping triangles is created from feature centroids; features associated with triangle nodes that share edges are neighbors.
  • SPACE_TIME_WINDOWFeatures within a specified critical distance and specified time interval of each other are neighbors.
  • CONVERT_TABLESpatial relationships are defined in a table.

Note: Polygon Contiguity methods are only available with an ArcGIS for Desktop Advanced license.

String
Distance_Method
(Optional)

Specifies how distances are calculated from each feature to neighboring features.

  • EUCLIDEANThe straight-line distance between two points (as the crow flies)
  • MANHATTANThe distance between two points measured along axes at right angles (city block); calculated by summing the (absolute) difference between the x- and y-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. Defines the size of the Space window for the Space Time Window conceptualization of spatial relationships.

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 temporarily 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.

Long
Row_Standardization
(Optional)

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

  • ROW_STANDARDIZATIONSpatial weights are standardized by row. Each weight is divided by its row sum.
  • NO_STANDARDIZATIONNo 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 the Input Feature Class Unique ID field, NID (neighbor ID), and WEIGHT.

Table
Date_Time_Field
(Optional)

A date field with a timestamp for each feature.

Field
Date_Time_Interval_Type
(Optional)

The units to use for measuring time.

  • SECONDSSeconds
  • MINUTESMinutes
  • HOURSHours
  • DAYSDays
  • WEEKSWeeks
  • MONTHSMonths
  • YEARSYears
String
Date_Time_Interval_Value
(Optional)

An Integer reflecting the number of time units comprising the time window.

For example, if you select HOURS for the Date/Time Interval Type and 3 for the Date/Time Interval Value, the time window would be 3 hours; features within the specified space window and within the specified time window would be neighbors.

Long

Code Sample

GenerateSpatialWeightsMatrix example 1 (Python window)

The following Python window script demonstrates how to use the GenerateSpatialWeightsMatrix tool.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.GenerateSpatialWeightsMatrix_stats("911Count.shp", "MYID","euclidean6Neighs.swm","K_NEAREST_NEIGHBORS","#", "#", "#", 6,"NO_STANDARDIZATION")
GenerateSpatialWeightsMatrix example 2 (stand-alone Python script)

The following stand-alone Python script demonstrates how to use the GenerateSpatialWeightsMatrix tool.

# Analyze the spatial distribution of 911 calls in a metropolitan area
# using the Hot-Spot Analysis Tool (Local Gi*)

# Import system modules
import arcpy

# Set geoprocessor object property to overwrite existing output, by default
arcpy.gp.overwriteOutput = True

# Local variables...
workspace = "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

    # Copy the input feature class and integrate the points to snap
    # together at 500 feet
    # Process: Copy Features and Integrate
    cf = arcpy.CopyFeatures_management("911Calls.shp", "911Copied.shp",
                         "#", 0, 0, 0)

    integrate = arcpy.Integrate_management("911Copied.shp #", "500 Feet")

    # Use Collect Events to count the number of calls at each location
    # Process: Collect Events
    ce = arcpy.CollectEvents_stats("911Copied.shp", "911Count.shp", "Count", "#")

    # Add a unique ID field to the count feature class
    # Process: Add Field and Calculate Field
    af = arcpy.AddField_management("911Count.shp", "MyID", "LONG", "#", "#", "#", "#",
                     "NON_NULLABLE", "NON_REQUIRED", "#",
                     "911Count.shp")
    
    cf = arcpy.CalculateField_management("911Count.shp", "MyID", "[FID]", "VB")

    # Create Spatial Weights Matrix for Calculations
    # Process: Generate Spatial Weights Matrix... 
    swm = arcpy.GenerateSpatialWeightsMatrix_stats("911Count.shp", "MYID",
                        "euclidean6Neighs.swm",
                        "K_NEAREST_NEIGHBORS",
                        "#", "#", "#", 6,
                        "NO_STANDARDIZATION") 

    # Hot Spot Analysis of 911 Calls
    # Process: Hot Spot Analysis (Getis-Ord Gi*)
    hs = arcpy.HotSpots_stats("911Count.shp", "ICOUNT", "911HotSpots.shp", 
                     "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

Output Coordinate System

Feature geometry is projected to the Output Coordinate System prior to analysis, so values entered for the Threshold Distance parameter should match those specified in the Output Coordinate System. All mathematical computations are based on the spatial reference of the Output Coordinate System. When the Output Coordinate System is based on degrees, minutes, and seconds, geodesic distances are estimated using chordal distances in meters.

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
8/26/2014