将坐标匹配到最接近的起始纬度/经度对

时间:2018-07-09 15:39:52

标签: algorithm sqlite maps coordinates gis

我正在尝试将纬度和经度对与具有起点和终点的纬度和经度的路段进行匹配。我已经找到的所有公式都可以通过最接近单个纬度(而不是一对经纬度)的查询来查询。我想一种选择是获取线段的平均值或中心,但这并不理想。我正在SQLLite中查询此数据,因为我的数据是GeoPackage格式,但是如果有人甚至可以使用公式,我也可以将其转换为SQLLite。

Here is a poorly drawn example of the segmentation of the roads, each line has its own start and end latitude/longitude coordiantes

谢谢!

1 个答案:

答案 0 :(得分:0)

嗯,很有趣。从概念上讲,如果不考虑性能,是否可以进行以下工作? (考虑此未经测试的伪):

SELECT
    MIN(ABS(lon_field - :lon1)) AS start_lon,
    MIN(ABS(lat_field - :lat1)) AS start_lat,
    MIN(ABS(lon_field - :lon2)) as end_lon,
    MIN(ABS(lat_field - :lat2)) AS end_lat;