How to convert .dbf to a spatial weights matrix .swm; quick and dirty

Discussion created by chrisweston11 on Sep 21, 2011
Latest reply on Mar 15, 2018 by Harrydoc
If you are trying to personalize your spatial weights matrix so that you can modify adjacency relationships (i.e. to modify LISA satistics) here is how you do it. 

Perform the usual spatial weights matrix generation with Spatial Statistics tool.

Run the following Python script (you'll have some cleanup to do after pasting this) in the embedded Python window to create a seperate .dbf that represents your spatial weights relationships.  The file paths below are as they are on my cpu; adjust them for your cpu.  My .swm file was called "invasive_spatilweightsmatrix", as you can see.

>>> import arcpy
... arcpy.env.workspace = "c:/thesis/spatial weights matrices/invasive_spatialweightsmatrix"
... arcpy.ConvertSpatialWeightsMatrixtoTable_stats("invasive_spatialweightsmatrix.swm","invasive_spatialweightsmatrix.dbf")

After you do this, rightclick/export the file that gets added to your ArcGIS Table of Contents.  Export it as a .dbf file.

Then add the .dbf file (that you created in the previous step) to your ArcGIS Table of Contents, and open it.

Delete any columns other than the following four fields:  OID, "Unique ID Field", NID, and WEIGHT.  I had to delete a field called "Field1".

You will be left with four columns: OID, "UNIQUE ID FIELD", NID, and WEIGHT.

Start the Editor and manually change the weights as you want them to be.  This is the "dirty" part of the job, assuming you have to hunt down each feature weight that you want to modify.

Save your edits and stop editor.

Generate a new spatial weights matrix with the Convert_Table option in the Spatial Statistics Toolkit.  Select your newly saved .dbf as the Input Table.  ***Important, if your original .swm was created with row standardization, then you should NOT select row standardization when you create your new .swm in this current step.  Your Input Table would already be row standardized if you selected row standardized in the initial creation of your .swm.  You will undo any of your weight adjustments if you check that box during this current step.***

Now you can select this new .swm for runs in Local Moran or anything that is derived from a spatial weights matrix table and gives you the option of selecting a .swm file (in ArcGIS anyways).

This was much easier than I made it out to be.  I just threw a few extra details in for anybody who might need them.

Good luck,

Chris Weston