反距离权重IDW插值法

  • Post author:
  • Post category:其他


在这里插入图片描述

def interpolation(lon, lat, lst):
	#lon, lat分别为徐插值点的坐标,lst为已有点构成的列表[[x,y,f],[x1,y1,f1]]
    p0 = [lon, lat]
    sum0 = 0
    sum1 = 0
    temp = []

    for point in lst:
        if lon == point[0] and lat == point[1]:
            return point[2]
        Di = distance(p0, point)

        ptn = copy.deepcopy(point)
        ptn = list(ptn)
        ptn.append(Di)
        temp.append(ptn)

    temp1 = sorted(temp, key=lambda point: point[3])

    for point in temp1[0:15]:
        sum0 += point[2] / math.pow(point[3], 2)
        sum1 += 1 / math.pow(point[3], 2)
    return sum0 / sum1


def distance(p, pi):
    dis = (p[0] - pi[0]) * (p[0] - pi[0]) + (p[1] - pi[1]) * (p[1] - pi[1])
    m_result = math.sqrt(dis)
    return m_result



版权声明:本文为qq_24591139原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。