Search a table for Point in Polygon using MySQL

后端 未结 2 725
梦如初夏
梦如初夏 2021-02-09 06:03

I have create a table (municipal_border), in MySQL 5.5, that holds some boundaries.

CREATE TABLE `municipal_border` (
  `boundary` polygon NOT NULL,
  `municipal         


        
2条回答
  •  灰色年华
    2021-02-09 06:55

    After a night sleep I found the following solution.

    set @p = GeomFromText('POINT(23.923739342824817 38.224714465253733)');
    select municipalID FROM ecovis.municipal_border
    where ST_Contains(municipal_border.boundary, @p);
    

    It is working for MySQL 5.6.1 where ST_ prefix function have been implemented. Although I haven't any measurments from a classical approach (x-ray algorithm) I believe that is quite fast. It needs 0.17 seconds to locate a point in 2700 polygons with some polygons having well more than 1,500 points.

提交回复
热议问题