Pygeoda – LISA for Round Polygon

geodageopandasmoran-indexpython

I have just started to use pygeoda package and I have tried to calculate LISA .
I had originally raster which I polygonized to have polygon for each pixel:
enter image description here

I have applied MORAN I and LISA on the squared polygons, but it seems like it takes into account the null value white polygons around the "circle", so the result looks like this:

~~~

This is how I got the result:

data=pygeoda.open('shape/vectorize1.shp')

rook_w = pygeoda.rook_weights(data, order=3, include_lower_order=False, precision_threshold = 0)

crm_lisa = pygeoda.local_moran(rook_w, data['VALUE'])


fig, ax = plt.subplots(figsize = (10,10))
lisa_colors = crm_lisa.lisa_colors()
lisa_labels = crm_lisa.lisa_labels()

# attach LISA cluster indicators to geodataframe
gdf['LISA'] = crm_lisa.lisa_clusters()

for ctype, data in gdf.groupby('LISA'):
    color = lisa_colors[ctype]
    lbl = lisa_labels[ctype]
    data.plot(color = color,
        ax = ax,
        label = lbl,
        edgecolor = 'black',
        linewidth = 0.2)

My goal is to calculate MORAN I and LISA only inside the not null values. Also, I haven't seen the MORAN I value itself, but that is not the main goal of this post.

Clarification: "the null value white polygons around the "circle"" – In order to calculate LISA I have taken raster image and polygonized it. The raster was clipped, so it has null values around the "circle". I want to calculate LISA only inside the circle, e.g the pixels with values, and to ignore the null values, but it seems like the calculation is also taking into account the null values around.

Best Answer

There do not appear to be any methods to filter data in pygeoda. Therefore, you will need an additional preprocessing step to remove the polygons that you don't want to process.

In QGIS, after converting your raster to polygons, toggle editing on the new polygon layer. Select all polygons with a value of NULL, and delete them. Save your edits, then run the pygeoda script.

Related Question