Python中的线平滑算法? [英] line smoothing algorithm in python?

查看:445
本文介绍了Python中的线平滑算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究线归纳,将其用于获取从大比例尺地图到小比例尺地图的广义道路网络地图.我正在使用两种运算和两种算法.它是使用shapefile库以python编程语言完成的,用于2d中的矢量数据. 操作:选择和消除. 对于选择,我使用的条件是,所有道路,宽度选择超过7米,都与道路的属性相关. 与消除相同,与宽度小于5米的所有道路一样,消除. 到目前为止,这没什么大问题.

I am doing research on line generalization, which will be applied to obtain generalized Road Network map from large scale map to small scale map. I am using two operation and two algorithms. It is done in python programming language using shapefile library, it is for vector data in 2d. Operation: Selection and Elimination. For selection I am using condition like, all the roads, width more than 7 meters selected, it is connected with attribute features of the roads. Same with elimination, like all the roads, width less than 5 meter, eliminated. So far it was no much problem.

在应用选择和消除操作后,我们将获得形状文件,通过条件的道路. 我正在使用两种算法,线简化和线平滑. 为了简化线路,我使用了道格拉斯·皮克(Douglas-Peucker)的线路简化算法.它正在获取矢量数据(坐标),并基于公差删除了一些点.我正在使用Python编程语言来做.获得简化的线条后,需要进行一些编辑,例如线条平滑. 在这里,我使用的是高斯算法,但是它返回了一些我不理解的错误,因为我是编程环境中的新手.

After selection and elimination operations applied, we will have shape file, roads which passed the condition. I am using two algorithms, Line simplification and line Smoothing. For simplification of line I am using Douglas-Peucker's line simplification algorithm. it is taking vector data (coordinates) and based on tolerance removing some points. I an doing it using Python programming language. After getting simplified lines it needs some editing like line smoothing. Here, I am using Gaussian algorithm, however it is returning some error, which i don't understand, as i am new in programming environment

import numpy

 ### This is the Gaussian data smoothing function I wrote ###  

def smoothListGaussian(list1,degree):  

     window=degree*2-1  

     weight=numpy.array([1.0]*window)
     print weight

     weightGauss=[]  

     for i in range(window):  

         i=i-degree+1  

         frac=i/float(window)  

         gauss=1/(numpy.exp((4*(frac))**2))  

         weightGauss.append(gauss)  

     print weightGauss
     weight=numpy.array(weightGauss)*weight
     print weight
     print len(list1)-window


     smoothed=[0.0]*(len(list1)-window)
     print smoothed

     for i in range(len(smoothed)):  

         smoothed[i]=sum(numpy.array(list1[i:i+window])*weight)/sum(weight)  

     return smoothed


a=[[78.03881018900006, 30.315651467000066], [78.044901609000078, 30.31512798600005], [78.04927981700007, 30.312510579000048], [78.050041244000056, 30.301755415000059], [78.072646124000073, 30.281720353000082], [78.07902308000007, 30.273344651000059]]

smoothListGaussian(a,3)

任何想法,请. 或者python中是否有其他算法可以使用线中每个点的坐标来平滑矢量数据中的线

Any, ideas, please. Or if there any other algorithms in python which smooths lines in vector data using coordinates of the each point in the line

任何答案表示赞赏!

推荐答案

我猜您使用了

I guess you used the code from here. You should have paid attention that the code was for a single dimension data points not for multi-dimension data points.

我对高斯平滑算法不是很了解,但是仅在简要浏览了代码之后,我相信下面是您要尝试做的事情(我不确定它是否能给您带来结果)欲望).将代码的最后部分替换为以下代码:

I am not much aware of Gaussian smoothing algorithm but after only briefly going through your code, I believe following is what you are trying to do (I am not sure if it gives you the result you desire). Replace last portion of your code with the following code:

smoothed=[0.0,0.0]*(len(list1)-window)
print smoothed

for i in range(len(smoothed)):
    smoothing=[0.0,0.0]
    for e,w in zip(list1[i:i+window],weight):
        smoothing=smoothing+numpy.multiply(e,w)
    smoothed[i]=smoothing/sum(weight)

这篇关于Python中的线平滑算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆