简体   繁体   English

mysql GIS(多边形内点和点附近)

[英]mysql GIS (point within polygon and near by points)

I've seen this question: See if lat / long falls within a polygon using mysql 我已经看到了这个问题: 看看lat / long是否属于使用mysql的多边形

Which states that the mysql GIS extensions aren't fully implemented yet. 这表明mysql GIS扩展尚未完全实现。 Can someone clear this up for me - does this mean if I have a polygon stored and want to detect if a point falls within a certain polygon, it won't be 100% accurate? 有人可以为我清除这个 - 这是否意味着如果我存储了一个多边形并想要检测一个点是否落在某个多边形内,它将不会100%准确? If so, how accurate will it be? 如果是这样,它会有多准确?

Also, the SQL required for this, off the top of my head, would it be something along the lines of: 此外,这需要的SQL,在我的头顶,它将是这样的东西:

SELECT * WHERE WITHIN(POINT(_LAT_ _LONG_), `polygon`)

(Where polygon is a table column and the point is constructed from given lat and long values.) (其中polygon是一个表列,并且该点是根据给定的lat和long值构造的。)

If the accuracy is sufficient, how would you find points close to a given Lat and Long? 如果精度足够,你会如何找到接近给定Lat和Long的点? There's differing opinions regarding using COS/SQRT or built in DISTANCE functions, which is best and/or what's the best method of doing? 关于使用COS / SQRT或内置DISTANCE功能有不同的意见,这是最好的和/或最好的方法吗?

Essentially: 实质上:

  • 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). mySQL GIS扩展是否适用于检测点是否在多边形内(必须相当准确,多边形不是定义的形状或大小)。
  • If they are, what is the best method for detecting this, and additionally want is the best method for finding points near a given Lat and Long 如果是,那么检测这个的最佳方法是什么,另外想要的是找到给定Lat和Long附近的点的最佳方法

According to the docs , all functions except Distance() and Related() only test MBR relationships. 根据文档 ,除Distance()和Related()之外的所有函数仅测试MBR关系。

Currently, MySQL does not implement these functions according to the specification. 目前,MySQL没有根据规范实现这些功能。 Those that are implemented return the same result as the corresponding MBR-based functions. 实现的那些返回与相应的基于MBR的函数相同的结果。 This includes functions in the following list other than Distance() and Related(). 这包括除Distance()和Related()之外的以下列表中的函数。

It's impossible to say whether accuracy of MBR tests is sufficient as this depends a lot on the shape of your polygons. 不可能说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)?" “mySQL GIS扩展是否适用于检测点是否在多边形内(必须相当准确,多边形不是定义的形状或大小)?”

No. 没有。

Use PostGIS if you can. 如果可以,请使用PostGIS。

An alternative could be to implement a Ray Casting algorithm for the Point-in-Polygon problem . 替代方案可以是针对多边形点问题实现Ray Casting算法

It seems that it is fully implemented in the MySQL5.6.1 and above ( Docs ). 它似乎完全在MySQL5.6.1及更高版本( Docs )中实现。

MySQL originally implemented these functions such that they used object bounding rectangles and returned the same result as the corresponding MBR-based functions. MySQL最初实现了这些函数,使得它们使用对象边界矩形并返回与相应的基于MBR的函数相同的结果。 As of MySQL 5.6.1, corresponding versions are available that use precise object shapes. 从MySQL 5.6.1开始,可以使用相应的版本来使用精确的对象形状。 These versions are named with an ST_ prefix. 这些版本以ST_前缀命名。 For example, Contains() uses object bounding rectangles, whereas ST_Contains() uses object shapes. 例如,Contains()使用对象边界矩形,而ST_Contains()使用对象形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM