【空间分析之二】点数据集加权平均中心统计(weighed Mean Center)

点数据集描述性空间统计之二——加权平均中心统计(weighed Mean Center)原理及python实现

1.原理

一个点数据集中,例如每个点所处的小区人口有多有少,或则到某个固定地点的距离有长有短,考虑这些权重因素的情况下,求得的点数据集的平均中心,就是权重平均中心。

2.公式

X ‾ = ∑ i = 1 N W i X i ∑ i = 1 N W i \overline{X}= \dfrac{\sum_{i=1}^{N}W_{i}X_{i}}{\sum_{i=1}^{N}W_{i}} X=i=1NWii=1NWiXi
Y ‾ = ∑ i = 1 N W i Y i ∑ i = 1 N W i \overline{Y}= \dfrac{\sum_{i=1}^{N}W_{i}Y_{i}}{\sum_{i=1}^{N}W_{i}} Y=i=1NWii=1NWiYi

3.python实现

SSDataObject.SSDataObject("c:/General Sample Data/BALTPOP_export.shp")
#  得到图层中要素的总数
mycount = arcpy.management.GetCount("c:/General Sample Data/BALTPOP_export.shp")
# 通过游标读取数据
ftClass = "c:/General Sample Data/BALTPOP_export.shp"
searchCursor = arcpy.da.SearchCursor(ftClass, ["SHAPE@xy", "FID", "TOTPOP"])
# 分别将每个点的X、Y值写入到list列表中,并算出平均中心
listPOP = []
weightX = []
weightY = []
for row in searchCursor:
   x, y = row[0]
   listPOP.append(row[2])
   weightX.append(x*row[2])
   weightY.append(y*row[2])
# 求出权重平均中心
WMeanCenterX = sum(weightX)/sum(listPOP)
WMeanCenterY = sum(weightY)/sum(listPOP)
# 生成权重平均中心图层
out_path = "c:/General Sample Data/"
out_name = "wmeanCenter_test.shp"
geometry_type = "POINT"
template = "study_quads.shp"
has_m = "DISABLED"
has_z = "DISABLED"

env.workspace = out_path
env.overwriteOutput = True

MClyr = arcpy.CreateFeatureclass_management(out_path, out_name, geometry_type, None, has_m, has_z)
# 向图层中写入权重中心这个点要素
inCursor = arcpy.da.InsertCursor(out_name, ["SHAPE@"])
wMCpnt = arcpy.Point(WMeanCenterX, WMeanCenterY)
inCursor.insertRow([wMCpnt])
del inCursor
del searchCursor

你可能感兴趣的:(arcpy,空间分析,python)