Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of determining whether a point is within a specified polygon area by mysql

Shulou Source: shulou.com Published: 2022-06-01 02:39:21 09月29日 Update

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!

Tags: Polygon region test method content output value interest buddy partner engine data more knowledge space article index industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux OPPO Reno MariaDB Microsoft