Select to view content in your preferred language

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

1655
4
09-21-2011 12:19 AM
ChrisWeston
Emerging 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
4 Replies
HarryMoultrie
Emerging Contributor

Thank you! Very helpful.

0 Kudos
deryolr
New Contributor

Hi Chris. I am working with a customized .dbf file. I have ArcGIS pro 3.5.3 and there is no tool to convert a .dbf file to spatial weight matrix file as you described above. I would like to customize the swm file so there is no island. There is no "Convert_Table" option in the Spatial Statistics Toolkit. How can I do it with this newest version of the ArcGIS pro? Thank you!

0 Kudos
EricKrause
Esri Regular Contributor

Hi @deryolr ,

You can convert a .dbf (or any other ArcGIS table) to a spatial weights matrix using the Generate Spatial Weights Matrix tool.  The Conceptualization of Spatial Relationships parameter has a "Convert table" option that will allow you to provide your dbf.

Making a custom SWM usually involves first making a template SWM using Generate Spatial Weights Matrix tool. You then convert it to a table using Convert Spatial Weights Matrix to Table tool, and manually edit the table.  Finally, you convert it back to a SWM using Generate Spatial Weights Matrix.

Before trying to convert your dbf to a SWM, I would try to add it to a map and make sure it displays as a table layer in the Contents pane.  That will verify that it is configured such that ArcGIS Pro recognizes it as a valid table.

-Eric Krause

0 Kudos
deryolr
New Contributor

Thank you so much!

0 Kudos