Python中的线平滑算法?

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

应用选择和消除操作后,我们将获得形状文件,通过条件的道路。我正在使用两种算法,线简化和线平滑。为了简化线路,我使用了道格拉斯·皮克(Douglas-

Peucker)的线路简化算法。它正在获取矢量数据(坐标)并基于公差删除了一些点。我正在使用Python编程语言来做。获得简化的线条后,需要进行一些编辑,例如线条平滑。在这里,我正在使用高斯算法,但是它返回了一些我不理解的错误,因为我是编程环境中的新手

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中还有其他算法可以使用线中每个点的坐标来平滑矢量数据中的线

任何答案表示赞赏!

回答:

我猜您使用了这里的代码。您应该注意,该代码是针对一维数据点的,而不是针对多维数据点的。

我不是太了解高斯平滑算法但毕竟

短暂地经历你的代码,我相信以下是你正在尝试做的(我不知道,如果它给你你想要的结果)。用以下代码替换代码的最后一部分:

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中的线平滑算法? 的全部内容, 来源链接: utcz.com/qa/408838.html

回到顶部