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

1220
1
09-21-2011 12:19 AM
ChrisWeston
New Contributor
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
0 Kudos
1 Reply
HarryMoultrie
New Contributor

Thank you! Very helpful.

0 Kudos