1

I am trying to create a spatial weight matrix from an existing file in ArcGIS. I need to use another file, as opposed to generate the weights in Arc, because I define non-standard weights. The documentation on how to do so is a little scarce, so I am turning for advice as my attempts have failed so far. All the files can be found in the zipfile downloadable through this link in Fileshare.

My locations are a set of points in the shapefile "pointlocations.shp". My ascii weights table is "weight_table.csv". The inuque id field is "codice71". I used the tool from the toolbox "generate spatial weight matrix" in the following way (I copy-pasted the python snippet here):

arcpy.GenerateSpatialWeightsMatrix_stats(Input_Feature_Class="PATH/pointlocations.shp", Unique_ID_Field="codice71", Output_Spatial_Weights_Matrix_File="PATH/spatweight4.swm", Conceptualization_of_Spatial_Relationships="CONVERT_TABLE", Distance_Method="EUCLIDEAN", Exponent="1", Threshold_Distance="", Number_of_Neighbors="", Row_Standardization="ROW_STANDARDIZATION", Input_Table="PATH/weight_table.csv", Date_Time_Field="", Date_Time_Interval_Type="", Date_Time_Interval_Value="")

When I do this, I run into the following error:

Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\stats.py", line 1423, in GenerateSpatialWeightsMatrix     raise e ExecuteError:  Traceback (most recent call last):   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 848, in <module>     setupWeights()   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 164, in setupWeights     rowStandard = rowStandard)   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 795, in table2SWM     allMaster.remove(lastID) ValueError: list.remove(x): x not in list  Failed to execute (GenerateSpatialWeightsMatrix).

I have no clue of what is going on, and I have found little help to find a better approach using the online help in: Generate Spatial Weight and Modelling Spatial Relationships

I was trying to check whether the formatting of my table was wrong, so I tried to have one that looked closer to the one described on the page Modelling Spatial Relationships. In that attempt, instead of having the csv file "weight_table" with header codice71, nid, weight, I had the txt tab-separated file weight_table2 with just the header codice71. Doing so, I get the error:

Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\stats.py", line 1423, in GenerateSpatialWeightsMatrix     raise e ExecuteError:  Traceback (most recent call last):   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 848, in <module>     setupWeights()   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 164, in setupWeights     rowStandard = rowStandard)   File "c:\program files (x86)\arcgis\desktop10.4\ArcToolbox\Scripts\Weights.py", line 772, in table2SWM     for row in rows: RuntimeError: A column was specified that does not exist.  Failed to execute (GenerateSpatialWeightsMatrix). 

Any help on what I am doing wrong? I am also open to using other software (R or Python) to do this, bearing in mind that my goal at the end is to generate a hot-spot detection map (Local Moran stats with pseudo p-values).

  • Why do you have GWR tagged? – Jeffrey Evans Sep 7 '18 at 18:41
1

It seems as though the table must be formatted with the unique ID field in order (or at least grouped). In the Weights.py script which is throwing the error there is a function that reads the table and checks the value against a list. Every time the tool processes a new unique ID it removes it from the list. If the IDs are not grouped it will fail when trying to remove that ID because it has already been removed. I don't see this in any of the documentation so it may be a bug.

  • Thank you! This worked up to a certain point, the output weight matrix is very strange as many values are negative. – Doon_Bogan Sep 11 '18 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.