python两坐标点画平滑线,Python中的线平滑算法?

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.

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)

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

Any answers appreciated!

解决方案

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值