The method of determining whether a point is within a specified polygon area by mysql
This article mainly introduces the method of mysql to judge whether the point is in the designated polygon area, the article is very detailed, has a certain reference value, interested friends must read it!
1. Create a test table CREATE TABLE `zone` (`id` int (10) unsigned NOT NULL AUTO_INCREMENT, `polygongeo` polygon NOT NULL, PRIMARY KEY (`id`)) ENGINE=MYISAM DEFAULT CHARSET=utf8
Note: spatial indexes can only be created in tables where the storage engine is MYISAM
two。 Insert polygonal data insert into zone (polygongeo) values (POLYGONFROMTEXT ('POLYGON (11-5-5-5-5-1-1); 3. Determine whether the point is in the polygonal area
Test POINT (3,4)
Select AsText (polygongeo) from zone where MBRWithin (POLYGONFROMTEXT ('POINT (3 4)'), polygongeo)
Output: POLYGON ((1, 1, 5, 5, 5, 5, 5, 1, 1))
Indicates that the point POINT (3,4) is in the polygon region.
Test POINT (6, 1)
Select AsText (polygongeo) from zone where MBRWithin (POLYGONFROMTEXT ('POINT (61)'), polygongeo)
Output: empty
Indicates that the point POINT (6, 1) is in the polygon region
The above is all the contents of mysql's method to determine whether the point is in the specified polygon area. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!