Search code examples
mysqlgispostgis

ST_Buffer equivalent for Circle based searches in MySQL?


I need to search for a row with a point that is within a specified circle using MySQL GIS. Pseudocode example query is:

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

It appears that PostGIS can do this via the ST_Buffer function. Does MySQL GIS offer similar functionality?


Solution

  • As far as I know, buffer functions are not yet implemented in MySQL:

    These functions are not implemented in MySQL. They may appear in future releases.

    * 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.
    

    If I understand your question right, you may not even need a spatial function to perform this query, you could use a "regular" SQL query and the Euclidean distance:

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

    Hope this helps.


    Edit: Performance would certainly be an issue with this query.

    As for the spatial functions in MySQL, it seems that the latest snapshots include new functions like Buffer or Distance. You may want to give it a try: