我看过这个问题:See if lat / long falls within a polygon using mysql
其中指出 mysql GIS 扩展尚未完全实现。有人能帮我解决这个问题吗——这是否意味着如果我存储了一个多边形并想检测一个点是否落在某个多边形内,它就不会 100% 准确?如果是这样,它的准确度如何?
此外,在我的脑海中,为此所需的 SQL 是否符合以下内容:
SELECT * WHERE WITHIN(POINT(_LAT_ _LONG_), `polygon`)
(其中多边形是一个表列,点是根据给定的纬度和经度值构造的。)
如果精度足够,您将如何找到接近给定纬度和经度的点?对于使用 COS/SQRT 或内置 DISTANCE 函数,存在不同意见,哪个是最好的和/或最好的方法是什么?
本质上:
- mySQL GIS 扩展是否能够检测点是否在多边形内(必须相当准确,多边形不是定义的形状或大小)。
- 如果是,检测这个的最佳方法是什么,另外想要的是找到给定纬度和经度附近点的最佳方法
最佳答案
根据docs ,除 Distance() 和 Related() 之外的所有函数仅测试 MBR 关系。
Currently, MySQL does not implement these functions according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions. This includes functions in the following list other than Distance() and Related().
不可能说 MBR 测试的准确性是否足够,因为这在很大程度上取决于多边形的形状。
"Are the mySQL GIS extensions up to the job for detecting if a point is within a polygon (has to be fairly accurate, polygon is not a defined shape or size)?"
没有。
如果可以,请使用 PostGIS。
另一种方法是实现 Ray Casting algorithm for the Point-in-Polygon problem .
关于mysql GIS(多边形内的点和点附近),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4970026/