对比两组经纬度,找出最相近的点,直接看代码

 两组数据作为例子,函数可直接使用。

 

import pandas as pd
from scipy.spatial.distance import cdist


data1 = {'Lat': pd.Series([50.6373473,50.63740441,50.63744285,50.63737839,50.6376054,50.6375896,50.6374239,50.6374404]),
         'Lon': pd.Series([3.075029928,3.075068636,3.074951754,3.074913884,3.0750528,3.0751209,3.0750246,3.0749554]),
         'Zone': pd.Series(['A','A','A','A','B','B','B','B'])}

data2 = {'Lat': pd.Series([50.6375524099,50.6375714407]),
         'Lon': pd.Series([3.07507914474,3.07508201591])}
# 两组数据


def closest_point(point, points):  # 根据哪列,在哪里找
    """ Find closest point from a list of points. """
    return points[cdist([point], points).argmin()]  # 前者必须是个array

def match_value(df, col1, x, col2):   # 哪里找,根据什么找,返回到哪里,找什么
    """ Match value x
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用以下步骤在MATLAB中批量对比两组经纬度坐标,并相近的坐标放在同一行输: 1. 读取两组经纬度坐标数据,假设分别存储在变量lon1、lat1和lon2、lat2中,每一行表示一个坐标点。 2. 将经纬度坐标转换为弧度制,使用MATLAB中的deg2rad函数。 3. 计算所有坐标点之间的距离矩阵,可以使用MATLAB中的pdist2函数,指定距离度量为haversine。 4. 设定一个距离阈值,到所有距离小于该阈值的坐标点对。可以使用MATLAB中的find函数和logical索引。 5. 将相近的坐标放在同一行输,可以使用MATLAB中的fprintf函数。 以下是MATLAB代码示例: ``` % 读取经纬度数据 data1 = readmatrix('coordinates1.csv'); lon1 = data1(:, 1); lat1 = data1(:, 2); data2 = readmatrix('coordinates2.csv'); lon2 = data2(:, 1); lat2 = data2(:, 2); % 将经纬度转换为弧度制 lon1_rad = deg2rad(lon1); lat1_rad = deg2rad(lat1); lon2_rad = deg2rad(lon2); lat2_rad = deg2rad(lat2); % 计算距离矩阵 dist_mat = pdist2([lat1_rad, lon1_rad], [lat2_rad, lon2_rad], @haversine); % 设定距离阈值 threshold = 0.1; % 单位为弧度 % 到距离小于阈值的坐标点对 [row, col] = find(dist_mat < threshold & dist_mat > 0); % 输相近坐标点对 for i = 1:length(row) fprintf('Coordinate %d in group 1 is close to coordinate %d in group 2\n', row(i), col(i)); end ``` 其中,coordinates1.csv和coordinates2.csv是包含经纬度数据的CSV文件,第一列为经度,第二列为纬度,每一行表示一个坐标点。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hydromonkey

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值