首页 > 解决方案 > 具有数据集点的 Ramer-Douglas-Peucker 算法

问题描述

在rdp算法的实现中:

from rdp import rdp

rdp([[1, 1], [2, 2], [3, 3], [4, 4]])

这些点是硬编码的。

我有一个数据集,我想从每个点读取 lon、lat,然后运行算法。

Python代码:

#returns the lon/lat
def load_data_from_file():
    # load the point data
    df = pd.read_csv('/home/repos/master/testdat.csv')
    coordinates = df.as_matrix(columns=['LON', 'LAT'])
    return coordinates

if __name__ == "__main__":
    coordinates_of_file =  load_data_from_file()
    print " \n Initial coordinates pairs:", number_of_initial_points(coordinates_of_file),"\n"

    number_of_pairs = number_of_initial_points(coordinates_of_file)

如果我执行一个循环来收集点的纬度/经度来执行算法,那么该算法适用于每一对而不是所有对。

for i in range((number_of_pairs)):
    print "\n rdp (Insight Lab) results: ", rdp([coordinates_of_file[i]],
                                                epsilon=0.05), "\n"

我想知道如何才能为数据集中的所有点运行算法。

标签: pythonalgorithmrdp

解决方案


推荐阅读