Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A method of calculating Spatial Local autocorrelation by using Python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "using Python to calculate local autocorrelation in space". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Local spatial autocorrelation import esda import numpy as npimport pandas as pdimport libpysal as lpsimport geopandas as gpdimport contextily as ctximport matplotlib.pyplot as pltfrom geopandas import GeoDataFramefrom shapely.geometry import Pointfrom pylab import figure, scatter Showfrom splot.esda import moran_scatterplotfrom esda.moran import Moran_Localfrom splot.esda import plot_moranfrom splot.esda import lisa_clusterfrom splot.esda import plot_local_autocorrelation%matplotlib inlineroot_dir= "/ home/lighthouse/Learning/pysal/" gdf = gpd.read_file (root_dir+'data/.shp') # read data profile gdf.columns.values # Field name array (['CODE',' COUNT', 'SUM_AREA',' FIRST_ANAM', 'OID_',' CODE_1' 'DATAFLAG',' TOTPOP', 'TOTPOP_10K',' RURPOP_10K', 'TOWNPOP_10',' AGRPRODUCT', 'AGRLBR_10K',' AGRSTOTGDP', 'FSTGDPRATE',' SCNDGDPRAT', 'THRDGDPRAT',' Province', 'geometry'], dtype=object) gdf.head (1) calculates local spatial autocorrelation LISA

The proportion of primary industry in GDP FSTGDPRATE is a variable

Ax=gdf.plot (figsize= (8, 8), column= "FSTGDPRATE", scheme='Quantiles', Know5, cmap='GnBu', legend=True,) ax.set_axis_off () calculates the spatial weight matrix

In the local autocorrelation calculation in pysal, every element of the weight matrix is required to have adjacent elements.

Y = gdf ['FSTGDPRATE']. Valuesw = lps.weights.distance.Kernel.from_dataframe (gdf, fixed=False, Kai15) w.transform =' r'

Local Moral calculation

Moran_loc = Moran_Local (y, w)

Local Moral scatter plot

Fig, ax = moran_scatterplot (moran_loc, paired 0.05) ax.set_xlabel ('FSTGDPRATE') ax.set_ylabel (' Spatial Lag of FSTGDPRATE') plt.show ()

Spatial distribution of agglomeration area

Lisa_cluster (moran_loc, gdf, paired 0.05, figsize = (9)) plt.show ()

According to the results of the above picture, we can see that the central and western part of the map is a high-value clustering area, and the eastern part is a low-value clustering area. The proportion of the primary industrial output value of the high-value agglomeration area is relatively high, while that of the low-value agglomeration area is relatively low, which can reflect the spatial heterogeneity of the regional economic development level and the imbalance of regional development.

Draw a combination diagram of the results

Plot_local_autocorrelation (moran_loc, gdf, 'FSTGDPRATE') plt.show ()

This is the end of the content of "using Python to calculate the local autocorrelation of space". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report