使用 man ascii 来查看 ASCII 表。

地理位置过滤盒模型精准度的问题

Elasticsearch | 作者 code4j | 发布于2018年08月27日 | 阅读数:2005

使用盒模型进行地理位置过滤,感觉精准度差的有点大。
 
用户给定一个坐标点和过滤的距离,例如查询坐标(100,50)附近5km的用户,我们先计算出这个点为中心的矩形的左上右下角坐标:
Double latitude = lat;
Double longitude = lon;
Double degree = (24901 * 1609) / 360.0;
double raidusMile = raidus;

Double dpmLat = 1 / degree; // 一米距离对应纬度的变化值
Double radiusLat = dpmLat * raidusMile;
Double bottomRightLat = latitude - radiusLat;
Double topLeftLat = latitude + radiusLat;

Double mpdLng = degree * Math.cos(latitude * (Math.PI / 180));
Double dpmLng = 1 / mpdLng; // //一米距离对应经度的变化值

Double radiusLng = dpmLng * raidusMile;
Double topLeftLon = longitude - radiusLng;
Double bottomRightLon = longitude + radiusLng;
return new double[]{topLeftLat, topLeftLon, bottomRightLat, bottomRightLon};

 
 
然后把这四个点带入盒模型公式:
 
double[] cube = getAround(lon,lat,distance);
boundingBoxQueryBuilder.topLeft(cube[0],cube[1]).bottomRight(cube[2],cube[3]);

这样计算出来,会有一些超过5KM的用户被过滤到,但也有少数用户距离6km甚至更多 也能被过滤到,这个差距感觉有点大。
 
想了解下盒模型的精准度到底能差多少,我理解的盒模型实际是用正方形代替圆形,把一个变长为原来圆形直径的正方形盖到圆形上,这样超出圆形四角的点就会被过滤出来,极端的盒模型四个顶点的距离是最远的,误差也是最大的。也就是说半径越大误差也会越大。
 
不知道我理解的对不对。如果盒模型本质上就是存在这样的问题,那就考虑用其他的方式了
 
 
已邀请:

kennywu76 - Wood

赞同来自: rochy

Geo Bounding Box的精度问题官方文档有比较清楚的说明: notes_on_precision


 
Notes on Precisionedit

Geopoints have limited precision and are always rounded down during index time. During the query time, upper boundaries of the bounding boxes are rounded down, while lower boundaries are rounded up. As a result, the points along on the lower bounds (bottom and left edges of the bounding box) might not make it into the bounding box due to the rounding error. At the same time points alongside the upper bounds (top and right edges) might be selected by the query even if they are located slightly outside the edge. The rounding error should be less than 4.20e-8 degrees on the latitude and less than 8.39e-8 degrees on the longitude, which translates to less than 1cm error even at the equator.


 
意思是说,Geopoints在索引的时候是“下舍入”,  而查询的时候,盒子右上边是“下舍入”, 左下边是“上舍入”。  由于舍入引入的误差,左下边附近的点可能被盒子漏选,而右上边的点可能被误选中。  误差范围 经度8.39e-8度, 纬度 4.20e-8度, 在赤道附近误差应该小于1公里。

rochy - rochy_he

赞同来自:

ES直接支持类似 5KM 之内的过滤:Geo Distance Query
 
https://www.elastic.co/guide/e ... query

要回复问题请先登录注册