current position:Home>Using the python library geopy method calculating the distance between the multiple sets of longitude and latitude
Using the python library geopy method calculating the distance between the multiple sets of longitude and latitude
2022-08-06 07:06:10【Mortal Leaf Maple】
Calculations are sometimes used in daily workgnssThe positioning accuracy of the positioning module,It is necessary to compare the latitude and longitude coordinates of the device under test and the true value device,Since the latitude and longitude coordinates want to calculate the difference,It needs to involve the transformation of the coordinate system,计算方法比较复杂,geopyThe library solves this problem nicely,A large number of methods are integrated,There are a lot of things that can be done with geographic coordinates,One of them is to calculate the distance between two coordinate points.
Below is what I wrote to calculate the distance between a series of coordinate pointspython脚本,Can provide you with reference.
Sort out the output of the two devicesgps的utctime and latitude,Write in the following formattxt文本中,脚本读取txt文本,Do a full second latitude and longitude comparison,Output the positioning error at a certain point in time,单位为m.
locationA.txt
1641541189000 38.018449 119.205511
1641541190000 38.018492 119.205554
1641541191000 38.018551 119.205591
1641541192000 38.018589 119.205625
1641541193000 38.018629 119.205657
1641541194000 38.018660 119.205693
locationB.txt
1641541189000 33.018449 119.205511
1641541190000 33.018492 114.205554
1641541191000 38.018551 116.205591
1641541192000 38.018589 116.205625
1641541193000 38.018629 119.205657
1641541194000 38.018660 119.205693
diff.txt
1641541189000 1.0
1641541190000 2.0
1641541191000 3.0
1641541192000 3.0
1641541193000 4.0
1641541194000 1.0
postion.py
# -*- coding:utf-8 -*-
#!/usr/bin/python3
from geopy.distance import distance
import time
dictpostionA = {
}
dictpostionB = {
}
dictdiff = {
}
#转换时间戳 dt为字符串
def datetime_timestamp(dt):
#中间过程,一般都需要将字符串转化为时间数组
time.strptime(dt, '%Y/%m/%d %H:%M:%S')
s = time.mktime(time.strptime(dt, '%Y/%m/%d %H:%M:%S'))
return int(s)
def saveATempData(filename):
with open(filename, "w") as f:
for time, pos in dictpostionA.items():
data = str(time) + "\t" + pos[0] + "\t" + pos[1] + "\n"
#print(data)
f.write(data)
#读取excel数据转成txt
def readAData(filename):
with open(filename, "r") as f:
for line in f.readlines():
line = line.strip('\n')
#print(line)
poslist = line.split()
#print(poslist[0])
#print(poslist[1])
#print(poslist[2])
#print(poslist[3])
#print(poslist[4])
#print(poslist[5])
dt = poslist[0]+' '+poslist[1]+':'+poslist[2]+':'+poslist[3]
#print(dt)
index = datetime_timestamp(dt) * 1000
#print(index)
sublist = poslist[4:6]
#print(sublist)
dictpostionA[index] = tuple(sublist)
def readBData(filename):
with open(filename, "r") as f:
for line in f.readlines():
line = line.strip('\n')
#print(line)
poslist = line.split()
#print(poslist[0])
#print(poslist[1])
#print(poslist[2])
sublist = poslist[1:3]
#print(sublist)
index = int(poslist[0])
dictpostionB[index] = tuple(sublist)
def processData():
for timeA, posA in dictpostionA.items():
for timeB, posB in dictpostionB.items():
#print(timeA, timeB)
if timeA == timeB:
d = distance(posA, posB).m # m是单位
print(timeA, d)
dictdiff[timeA] = d
continue
def saveDiffData(filename):
with open(filename, "w") as f:
for time, diff in dictdiff.items():
data = str(time) + "\t" + str(diff) + "\n"
#print(data)
f.write(data)
#读取数据
readAData("locationA.txt")
saveATempData("locationA_temp.txt")
readBData("locationB.txt")
#处理数据
processData()
#保存数据
saveDiffData("diff.txt")
copyright notice
author[Mortal Leaf Maple],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/218/202208060638528846.html
The sidebar is recommended
- Get the input and output information of the onnx model Python script
- Common parameters of python matplotlib and drawing examples
- python axessubplot_ use matplotlib's savefig to save plots generated from python pandas (AxesSubPlot)
- Qixi Festival_A Python program that moves the mouse to play the confession balloon (available in August 2022)
- Python knowledge points: Python variables, data types
- Python open virtual environment
- Python uses Hive to query data
- python+opencv study notes
- python--log processing logging.handlers.TimedRotatingFileHandler
- The problem that yum is unavailable after python upgrade
guess what you like
Application of bubbling method in program thought in advanced scl programming in python and 1200PLC
Tensorflow C++ deployment practice - python environment establishment on linux platform (2)
Python graduation design works based on django framework personal blog system completed finished product (7) mid-term inspection report
Python graduation design works based on django framework personal blog system completed design (8) graduation design thesis template
Python graduation design works are based on the django framework enterprise company website. The finished product (1) Development overview
Application of bubbling method in program thought in advanced scl programming in python and 1200PLC
python get all characters before or after a specified character
[Python | Word Cloud] Draw a super beautiful word cloud from chat records (Happy Qixi Festival, classmate Zeng)
Python data visualization-----make a global earthquake scatter plot
Python. Iterator object iter() (Based on the iterator feature, dismantle the complicated single-line "forced code", and understand the "secret method" for selecting fixed-length elements of the sequence.)
Random recommended
- Python's common modules of threading and Thread modules The first stage of thread implementation
- Blender Python Programming: Creating Emitting Materials
- Python multiprocessing
- How does python implement image edge detection
- Django paging method
- django regex
- How does Python represent time?2 modules, 3 ways, 1 text to understand~
- Modify column name and row index in pandas DataFrame
- [python pandas groupby]
- Python Daily Practice (New Question Bank of Niu Ke) - Day 20: Dictionary Practice
- [LeetCode brush questions] Hash table - some questions are implemented with built-in functions (with Python code)
- [LeetCode brush questions] Linked list topic (1) (with Python code)
- [Small case of python learning] Simulation system invasion to enhance interest
- Getting Started with Python Basics - Essential Knowledge for Getting Started
- How does Python represent time?2 modules, 3 ways, 1 text to get it~
- Python office software automation, master openpyxl operation in 5 minutes
- Introduction to Python Basics - Variables, Strings
- [python2] remove the u in front of the unicode string
- How to use the Python Color class to draw text
- How to use Asyncio Python web programming
- 27 Python artificial intelligence libraries have been sorted out, it is recommended to collect!
- [Python] Word2Vec predicts what will be left if I subtract 'love' from my 'life'
- When I export a pandas package, there is a problem. If I don't import it, there is no problem. Is this not enough memory?
- Python version 3.7.4 How can I install locust successfully?
- How does python use pyinstaller to package music into exe, that is, play background music when running the packaged program?
- Python use pyinstaller how to wrap up music exe, is to run a packaged program play background music?
- Rescue 007 of graph traversal application, detailed analysis of python version
- 27 Python artificial intelligence libraries have been sorted out, it is recommended to collect~
- pandas DataFrame data filtering (2)
- Python is how to represent time?- two modules, three ways, complete the ~ 1
- The definition of pycharm writing python code
- Problems defining functions in Python
- Python Socket Network Programming
- Django server running error
- Python image processing notes - image matching based on Harris corners (skimage)
- (Thirteen--1) Concurrent programming of python (thread, queue, process, coroutine, process thread coroutine comparison)
- (12) Python's memory management mechanism
- Python crawler entry case day07: Hippopx
- Django reports an error ModuleNotFoundError: No module named 'mysqlclient'
- Python study notes