代码之家  ›  专栏  ›  技术社区  ›  jsight TaherT

MySQL中基于圆的搜索的ST_缓冲区等价物?

  •  4
  • jsight TaherT  · 技术社区  · 16 年前

    我需要使用MySQL GIS搜索一个点位于指定圆内的行。伪代码示例查询为:

    select * from gistable g where isInCircle(g.point, circleCenterPT, radius)
    

    ST_Buffer

    3 回复  |  直到 16 年前
        1
  •  3
  •   amercader    16 年前

    据我所知,缓冲区函数是 not yet implemented

    这些功能是 不 在MySQL中。他们可能

    * Buffer(g,d)
    
      Returns a geometry that represents all points whose distance from the geometry value g is less than or equal to a distance of d.
    

    Euclidean distance :

    select * 
    from gistable g 
    where SQRT(POW(circleCenterPT.x - point.x,2) + POW(circleCenterPT.y - point.y,2)) < radius
    


    编辑:

    至于MySQL中的空间函数,最新的快照似乎包含了缓冲区或距离等新函数。 您可能想尝试一下:

        2
  •  1
  •   Community Mohan Dere    6 年前

    即使使用PostGIS,也不需要使用 ST_Buffer 功能,但是 ST_Expand 执行与此等效的操作(伪代码):

    -- expand bounding box with 'units' in each direction
    envelope.xmin -= units;
    envelope.ymin -= units;
    envelope.xmax += units;
    envelope.ymax += units;
    -- also Z coordinate can be expanded this way
    

    SELECT AsText(geom) FROM mypoints
    WHERE
      -- operator && triggers use of spatial index, for better performance
      geom && ST_Expand(ST_GeometryFromText('POINT(10 20)', 1234), 5) 
    AND
      -- and here is the actual filter condition
      Distance(geom, ST_GeometryFromText('POINT(10 20)', 1234)) < 5
    

    发现 Buffer vs Expand postgis用户邮件列表中的说明。

    ST_Expand 功能。

    下面是如何模仿 功能:

    CONCAT('POLYGON((',
        X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',',
        X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',',
        X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',',
        X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',',
        X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, '))'
    );
    

    然后将此结果与如下查询组合:

    SELECT AsText(geom) FROM mypoints
    WHERE
      -- AFAIK, this should trigger use of spatial index in MySQL
      -- replace XXX with the of expanded point as result of CONCAT above
      Intersects(geom, GeomFromText( XXX ) )
    AND 
      -- test condition
      Distance(geom, GeomFromText('POINT(10 20)')) < 5
    

    amercader 使用基于SQRT的计算。

        3
  •  -1
  •   Brad Kent    6 年前


    ST_Distance_sphere(g1, g2[, radius])

    返回球体上两点和/或多点之间的最小球面距离(以米为单位),如果任何几何参数为NULL或为空,则返回NULL

    计算使用球形地球和可配置的半径。可选半径参数应以米为单位。如果省略,默认半径为6370986米。如果半径参数存在但不为正,则会发生ER_错误参数错误

    SELECT *
    FROM gistable g
    WHERE ST_Distance_Sphere(g.point, circleCenterPT) <= radius