See if lat / long falls within a polygon using mysql

后端 未结 4 1284
名媛妹妹
名媛妹妹 2020-12-01 03:53

I have the created the table below

CREATE TABLE geom (g GEOMETRY);

and have inserted many rows, example below:

INSERT INTO          


        
4条回答
  •  無奈伤痛
    2020-12-01 04:34

    MySQL as of v5.1 only supports operations on the minimum bounding rectangles (MBR). While there is a "Contains" function which would do what you need, it is not fully implemented and falls back to using MBRContains

    From the relevant manual page

    Currently, MySQL does not implement these functions according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions. This includes functions in the following list other than Distance() and Related().

    These functions may be implemented in future releases with full support for spatial analysis, not just MBR-based support.

    What you could do is let MySQL give you an approximate result based on MBR, and then post process it to perform a more accurate test. Alternatively, switch to PostGIS!

    (Update May 2012 - thanks Mike Toews)

    MySQL 5.6.1+ offers functions which use object shapes rather than MBR

    MySQL originally implemented these functions such that they used object bounding rectangles and returned the same result as the corresponding MBR-based functions. As of MySQL 5.6.1, corresponding versions are available that use precise object shapes. These versions are named with an ST_ prefix. For example, Contains() uses object bounding rectangles, whereas ST_Contains() uses object shapes.

提交回复
热议问题