3

我正在尝试根据输入的经纬度 GPS 坐标创建一条连续路径。有没有一个python库可以做到这一点?最终目标是进行优化,因此我需要路径可以连续微分以确定梯度。

我一直在使用 GDAL,但它似乎没有我需要的所有功能。

4

1 回答 1

2

这需要scipy.interpolate包。SciPY Cookbook中关于插值的这一页展示了如何使用这些函数splprep来确定样条结并splev在平面中的噪声数据上绘制结果曲线。

食谱示例(略微缩短):

from numpy import arange, cos, linspace, pi, sin, random
from scipy.interpolate import splprep, splev

# make ascending spiral in 3-space
t=linspace(0,1.75*2*pi,100)

x = sin(t)
y = cos(t)
z = t

# add noise
x+= random.normal(scale=0.1, size=x.shape)
y+= random.normal(scale=0.1, size=y.shape)
z+= random.normal(scale=0.1, size=z.shape)

# spline parameters
s=3.0 # smoothness parameter
k=2 # spline order
nest=-1 # estimate of number of knots needed (-1 = maximal)

# find the knot points
tckp,u = splprep([x,y,z],s=s,k=k,nest=-1)

# evaluate spline, including interpolated points
xnew,ynew,znew = splev(linspace(0,1,400),tckp)

import pylab
pylab.subplot(1,1,1)
data,=pylab.plot(x,y,'bo-',label='data')
fit,=pylab.plot(xnew,ynew,'r-',label='fit')
pylab.legend()
于 2013-07-21T20:54:25.047 回答