Search a table for Point in Polygon using MySQL

后端 未结 2 724
梦如初夏
梦如初夏 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:51

    Solution of Pavlos Papanikolaou is wonderfull. In my case Table : TestPoly and column : pol Insert Query

    SET @g = 'POLYGON((22.367582117085913 70.71181669186944, 22.225161442616514 70.65582486840117, 22.20736264867434 70.83229276390898, 22.18701840565626 70.9867880031668, 22.22452581029355 71.0918447658621, 22.382709129816103 70.98884793969023, 22.40112042636022 70.94078275414336, 22.411912121843205 70.7849142238699, 22.367582117085913 70.71181669186944))';
    INSERT INTO TestPoly (pol) VALUES (ST_GeomFromText(@g))
    

    Select Query

    set @p = GeomFromText('POINT(22.4053386588057 70.86240663480157)');
    select * FROM TestPoly where ST_Contains(pol, @p);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题