简体   繁体   English

Mysql函数MBRContains不准确

[英]Mysql function MBRContains is not accurate

I have the following POLYGON (in the image you can see the area it covers) 我有以下POLYGON(在图像中你可以看到它覆盖的区域)

多边形区域

POLYGON((-74.05100448502202 4.7239278424321,-74.05092938316898 4.7241416902206,-74.04830618275201 4.7237460717602,-74.04643668306903 4.7234306460692,-74.04635688735101 4.7234105978214,-74.04636526925401 4.7233310730989,-74.046191260944 4.72327293317,-74.04579027069599 4.7232007594583,-74.04141290558402 4.7214258184083,-74.03746201170497 4.7197791822891,-74.03565688503801 4.7189879401666,-74.033484295736 4.7180897723398,-74.03098447693401 4.7170526009038,-74.028731840457 4.7161167561787,-74.02852820211899 4.7150714370973,-74.026398371001 4.6877232674918,-74.02558060109601 4.6874859863574,-74.02454587610401 4.686797564651,-74.024665108676 4.6863189291555,-74.025470986757 4.6857975214267,-74.02585246812498 4.6846813784365,-74.02580479605103 4.6834369175226,-74.01962984798399 4.684922743491,-74.028472839649 4.6765444849623,-74.032273278366 4.6775012677607,-74.03825980124901 4.6799297676049,-74.048215993474 4.6850422042295,-74.05718496514402 4.6867981911917,-74.05100448502202 4.7239278424321))

When I execute MBRIntersect , MBRContains and Within functions they return that the green marker is inside of the polygon, but it is not (as you can see in the image). 当我执行MBRIntersectMBRContainsWithin函数时,它们返回绿色标记位于多边形内部,但它不是(如图中所示)。 I'm executing the next sentence to get that: 我正在执行下一句话来得到它:

SET @g1 = ST_GeomFromText('POLYGON((-74.05100448502202 4.7239278424321,-74.05092938316898 4.7241416902206,-74.04830618275201 4.7237460717602,-74.04643668306903 4.7234306460692,-74.04635688735101 4.7234105978214,-74.04636526925401 4.7233310730989,-74.046191260944 4.72327293317,-74.04579027069599 4.7232007594583,-74.04141290558402 4.7214258184083,-74.03746201170497 4.7197791822891,-74.03565688503801 4.7189879401666,-74.033484295736 4.7180897723398,-74.03098447693401 4.7170526009038,-74.028731840457 4.7161167561787,-74.02852820211899 4.7150714370973,-74.026398371001 4.6877232674918,-74.02558060109601 4.6874859863574,-74.02454587610401 4.686797564651,-74.024665108676 4.6863189291555,-74.025470986757 4.6857975214267,-74.02585246812498 4.6846813784365,-74.02580479605103 4.6834369175226,-74.01962984798399 4.684922743491,-74.028472839649 4.6765444849623,-74.032273278366 4.6775012677607,-74.03825980124901 4.6799297676049,-74.048215993474 4.6850422042295,-74.05718496514402 4.6867981911917,-74.05100448502202 4.7239278424321))', 4326);
SELECT MBRContains(@g1, ST_PointFromText('POINT(-74.051585 4.680108)', 4326)) g1, 
st_distance(ST_PointFromText('POINT(-74.051585 4.680108)', 4326), @g1) distance

and I'm getting 而且我正在

g1      distance
1   |   0.005489581062607619

But I was expecting 但我在期待

g1      distance
0   |   0.005489581062607619

I have try the following cases: 我试过以下情况:

  • Save geometry assigning 4326 SRID. 保存几何图形,分配4326 SRID。
  • Using other functions, getting same response. 使用其他功能,获得相同的响应。

I'm Using 5.7.14 MySQL version 我正在使用5.7.14 MySQL版本

What am I doing wrong? 我究竟做错了什么?

I worked around this issue just validating that there's no distance. 我解决了这个问题,只是验证了没有距离。 But, why am I getting this result from that functions? 但是,为什么我从这些函数中得到这个结果呢?

I don't have a MySQL to play with right now. 我现在没有MySQL可以使用。 So i first try to duplicate your query in a SQL Server Spatial. 所以我首先尝试在SQL Server Spatial中复制您的查询。

DECLARE @g1 geometry
DECLARE @h1 geometry
SET @g1= geometry::STGeomFromText('POLYGON((-74.05100448502202 4.7239278424321,-74.05092938316898 4.7241416902206,-74.04830618275201 4.7237460717602,-74.04643668306903 4.7234306460692,-74.04635688735101 4.7234105978214,-74.04636526925401 4.7233310730989,-74.046191260944 4.72327293317,-74.04579027069599 4.7232007594583,-74.04141290558402 4.7214258184083,-74.03746201170497 4.7197791822891,-74.03565688503801 4.7189879401666,-74.033484295736 4.7180897723398,-74.03098447693401 4.7170526009038,-74.028731840457 4.7161167561787,-74.02852820211899 4.7150714370973,-74.026398371001 4.6877232674918,-74.02558060109601 4.6874859863574,-74.02454587610401 4.686797564651,-74.024665108676 4.6863189291555,-74.025470986757 4.6857975214267,-74.02585246812498 4.6846813784365,-74.02580479605103 4.6834369175226,-74.01962984798399 4.684922743491,-74.028472839649 4.6765444849623,-74.032273278366 4.6775012677607,-74.03825980124901 4.6799297676049,-74.048215993474 4.6850422042295,-74.05718496514402 4.6867981911917,-74.05100448502202 4.7239278424321))', 4326);
SET @h1 = geometry::STGeomFromText('POINT(-74.051585 4.680108)', 4326)
SELECT @g1.STContains(@h1) contain, @g1.STDistance(@h1) distance

And the result is what you may expect: 结果就是你所期望的:

contain      distance
0   |   0.005489581062607675

Here is the reason behind this: 这背后的原因是:

I am using STContains not MBRContains based on your description of what you are looking for. 我根据您对所需内容的描述使用STContains而不是MBRContains MBRContains function first create a Minimal Bounding Rectangle over your polygon, and use that new polygon feature do the contain judegement. MBRContains函数首先在多边形上创建一个Minimal Bounding Rectangle,然后使用新的多边形特征来包含judegement。 In your example, the point does fall into the MBR of your polygon so thats why your MySQL result is not what you expect. 在您的示例中,该点确实属于多边形的MBR,因此您的MySQL结果不符合您的预期。 And STContains is the right function you are looking for. STContains是您正在寻找的合适功能。

Official reference: Mysql spatial Link 官方参考: Mysql空间链接

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

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