I am trying to implement 'pysal' in order to calculate the "Local Moran" spatial autocorrelation index of the points of a vector file .shp. This with the objective of cleaning vector data at the INLIERS level. My problem is when I have to obtain the weight matrix W, to be able to use it later as the input parameter of the Moran_local function of the pysal package.
The code I use is the following:
import pysal
import numpy as np
f = pysal.open("soja.dbf")
y = np.array(f.by_col["DryYield ("])
w = pysal.knnW_from_shapefile("soja.shp", k=6)
lm = pysal.Moran_Local(y,w)
print lm
Has anyone worked in this way and with this package on this type of data?
Thank you very much
I have already solved the problem It was a problem in my pc, I leave the code in case of doubts.
#!/usr/bin/env python
# -*- coding: utf-8
import pysal
import numpy as np
import matplotlib.pyplot as plt
w = pysal.knnW_from_shapefile("soja.shp", k=4)
f = pysal.open("soja.dbf")
y = np.array(f.by_col["DryYield ("])
lm = pysal.Moran_Local(y,w)
local_moran = lm.Is
for i in local_moran:
print i
Greetings and thank you very much.