查找点的x距离附近有多少个(googlemap)多边形 [英] Find how many (googlemap) polygons near x distance of a point

查看:159
本文介绍了查找点的x距离附近有多少个(googlemap)多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MYSQL/PHP系统,其中包含以下内容:

I'm working on a MYSQL/PHP system where I have the following:

-以(lat,lng)形式存储的一组经度和纬度,以文本格式存储:(lat1,lng1)#(lat2,lng2)#(lat3,lng3)等,基本上是绘制的多边形在存储在数据库中的googlemap实例上.

-- a set of latitude, longitude in the form of (lat,lng) stored as text format : (lat1,lng1)#(lat2,lng2)#(lat3,lng3) etc. which is basically a polygon drawn over a googlemap instance stored in the database.

-在一个字段中存储的表-点的坐标P(plat,plng)基本上是设备所在的点

-- a table which stores in a field - a point's coordinates P(plat,plng) which is basically a point where a device is stationed

我需要使用MYSQL找出第一个表中距P点X公里以内X公里内有多少个多边形.

I need to figure out how many polygons from the first table are within a distance of X kilometers from the point P essentially using MYSQL.

我已经遇到了很多与此相关的Google Map库,但是我打算通过最快的方法来解决这个问题-我认为这是通过MYSQL查询来实现的.

I have come across quite a few Google Map libraries regarding this already, but I intend to resolve this by the quickest method possible - which I assume is via a MYSQL query.

任何人都可以请对此有所帮助吗?

Can anyone please please shed some light regarding this?

到目前为止,我已经参考了一些有关地理空间查询的示例-并提出了以下建议:

I've so far consulted a few examples on geospatial querying - and come up with this :

    SELECT user_id, latitude, longitude, 
      GeomFromText( "POINT(CONCAT_WS(' ',latitude,longitude))" ) AS point,
      Contains( GeomFromText( 'POLYGON(-26.167918065075458 28.10680389404297, 
    - 26.187020810321858 28.091354370117188, -26.199805575765794 28.125,-26.181937320958628 28.150405883789062, -26.160676690299308 28.13220977783203, -26.167918065075458 28.10680389404297)' ) , 
      GEOMFromText( "POINT(CONCAT_WS(' ',latitude,longitude))" ) ) 
   FROM user_location

但是问题在于它还显示了一条记录,该记录的纬度为-26.136230,长为:28.338850,这超出了多边形的边界.有人可以指导吗?

But the problem is it shows a record with lat: -26.136230, long: 28.338850 as well which is way off the polygon's boundaries. Can anyone please guide?

推荐答案

好的,做到了-而且有效-可能会帮助某人:

Okay, did this - and it works - might help someone:

SELECT user_id,latitude,longitude,
   Contains(
          PolyFromText( 'POLYGON((-26.167918065075458 28.10680389404297, -26.187020810321858 28.091354370117188, -26.199805575765794 28.125,-26.181937320958628  28.150405883789062, -26.160676690299308 28.13220977783203, -26.167918065075458 28.10680389404297))' ),
          PointFromText(concat("POINT(",latitude," ",longitude,")"))
   ) as contains
FROM user_location

=====

尽管我同意专家的观点,但PostGIS可能是更好的选择.

Although I agree on expert's views that PostGIS could be a better option.

这篇关于查找点的x距离附近有多少个(googlemap)多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆