Python坐標(biāo)線性插值應(yīng)用實(shí)現(xiàn)
一、背景
在野外布設(shè)700米的測(cè)線,點(diǎn)距為10米,用GPS每隔50米測(cè)量一個(gè)坐標(biāo),再把測(cè)線的頭和為測(cè)量一個(gè)坐標(biāo)?,F(xiàn)在需使用線性插值的方法求取每?jī)蓚€(gè)坐標(biāo)之間的其他4個(gè)點(diǎn)的值。

二、插值原理
使用等比插值的方法
起始值為 a
終止值為 b
步長(zhǎng)值為 (a-b)/5
后面的數(shù)分別為 a+n, a+2n, a+3n, a+4n
三、代碼實(shí)習(xí)對(duì) x 插值
interx.py
import numpy as np
f = np.loadtxt('datax.txt')
a = f[:, 0]
b = f[:, 1]
for j in np.arange(len(a)):
aa = a[j]*1000 # np.arrange()會(huì)自動(dòng)去掉小數(shù)
bb = b[j]*1000
n = (bb-aa) / 5
x = np.arange(6)
x[0] = aa
print(x[0]/1000)
for i in range(1, 5, 1):
x[i] = x[i-1]+n
print(x[i]/1000)
i = i+1
# print(bb/1000)
# print("\n")
datax.txt
514873.536 514883.939 514883.939 514894.358 514894.358 514903.837 514903.837 514903.807 514903.807 514907.179 514907.179 514911.356 514911.356 514913.448 514913.448 514913.315 514913.315 514917.344 514917.344 514923.684 514923.684 514924.801 514924.801 514929.697 514929.697 514916.274
對(duì) y 插值
intery.py
import numpy as np
f = np.loadtxt('datay.txt')
a = f[:, 0]
b = f[:, 1]
for j in np.arange(len(a)):
aa = (a[j] - 2820000)*1000 # 數(shù)據(jù)太長(zhǎng)會(huì)溢出
bb = (b[j]-2820000)*1000
n = (bb-aa) / 5
x = np.arange(6)
x[0] = aa
print(x[0]/1000+2820000)
for i in range(1, 5, 1):
x[i] = x[i-1]+n
print(x[i]/1000+2820000)
i = i+1
# print(bb/1000)
# print("\n")
datay.txt
2820617.820 2820660.225 2820660.225 2820693.988 2820693.988 2820819.199 2820819.199 2820831.510 2820831.510 2820858.666 2820858.666 2820973.487 2820973.487 2821017.243 2821017.243 2821019.518 2821019.518 2821058.223 2821058.223 2821097.575 2821097.575 2821144.436 2821144.436 2821173.356 2821173.356 2821218.889
四、最終成果
手動(dòng)把兩次插值結(jié)果復(fù)制到dataxy中
dataxy.txt
514873.536 2820617.819 514875.616 2820626.300 514877.696 2820634.781 514879.776 2820643.262 514881.856 2820651.743 514883.939 2820660.225 514886.022 2820666.977 514888.105 2820673.729 514890.188 2820680.481 514892.271 2820687.233 514894.358 2820693.987 514896.253 2820719.029 514898.148 2820744.071 514900.043 2820769.113 514901.938 2820794.155 514903.837 2820819.199 514903.831 2820821.661 514903.825 2820824.123 514903.819 2820826.585 514903.813 2820829.047 514903.807 2820831.509 514904.481 2820836.940 514905.155 2820842.371 514905.829 2820847.802 514906.503 2820853.233 514907.179 2820858.666 514908.014 2820881.630 514908.849 2820904.594 514909.684 2820927.558 514910.519 2820950.522 514911.356 2820973.487 514911.774 2820982.238 514912.192 2820990.989 514912.610 2820999.740 514913.028 2821008.491 514913.448 2821017.242 514913.421 2821017.697 514913.394 2821018.152 514913.367 2821018.607 514913.340 2821019.062 514913.315 2821019.518 514914.120 2821027.259 514914.925 2821035.000 514915.730 2821042.741 514916.535 2821050.482 514917.344 2821058.223 514918.612 2821066.093 514919.880 2821073.963 514921.148 2821081.833 514922.416 2821089.703 514923.684 2821097.575 514923.907 2821106.947 514924.130 2821116.319 514924.353 2821125.691 514924.576 2821135.063 514924.801 2821144.436 514925.780 2821150.219 514926.759 2821156.002 514927.738 2821161.785 514928.717 2821167.568 514929.697 2821173.356 514927.012 2821182.462 514924.327 2821191.568 514921.642 2821200.674 514918.957 2821209.780

五、畫圖對(duì)比
dataxy.py
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
# 解決中文字體顯示不出來
mpl.rcParams["font.sans-serif"]=["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
a = np.loadtxt("datax.txt")
b = np.loadtxt('datay.txt')
c = np.loadtxt('dataxy.txt')
x = a[: ,0]
y = b[: ,0]
xx = c[:,0]
yy = c[:,1]
plt.plot(x,y,color = 'orange',
label = '插值線段')
plt.scatter(xx,yy,marker='o',
c = 'deepskyblue',
alpha = 0.6,
label = '實(shí)測(cè)點(diǎn)位')
plt.legend()
plt.title('Python坐標(biāo)插值')
plt.grid()
# 保存高清圖片,dpi表示分辨率
plt.savefig('out.png',dpi = 600)
plt.show()

文件結(jié)構(gòu)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)統(tǒng)計(jì)英文單詞個(gè)數(shù)及字符串分割代碼
這篇文章主要介紹了Python實(shí)現(xiàn)統(tǒng)計(jì)英文單詞個(gè)數(shù)及字符串分割方法,本文分別給出代碼實(shí)例,需要的朋友可以參考下2015-05-05
pandas數(shù)據(jù)探索之合并數(shù)據(jù)示例詳解
這篇文章主要為大家介紹了pandas數(shù)據(jù)探索之合并數(shù)據(jù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10
python3+PyQt5 自定義窗口部件--使用窗口部件樣式表的方法
今天小編就為大家分享一篇python3+PyQt5 自定義窗口部件--使用窗口部件樣式表的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
解決Python安裝cryptography報(bào)錯(cuò)問題
這篇文章主要介紹了解決Python安裝cryptography報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09
python pygame實(shí)現(xiàn)五子棋小游戲
這篇文章主要為大家詳細(xì)介紹了python pygame實(shí)現(xiàn)五子棋小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06
Python查詢Mysql時(shí)返回字典結(jié)構(gòu)的代碼
MySQLdb默認(rèn)查詢結(jié)果都是返回tuple,輸出時(shí)候不是很方便,必須按照0,1這樣讀取,無意中在網(wǎng)上找到簡(jiǎn)單的修改方法,就是傳遞一個(gè)cursors.DictCursor就行2012-06-06
python實(shí)現(xiàn)word 2007文檔轉(zhuǎn)換為pdf文件
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)word 2007文檔轉(zhuǎn)換為pdf文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03

