This article will introduce the method of using mysql to determine whether a point is within a specified polygon area, and provide a complete process.
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 whose storage engine is MYISAM
insert into zone(polygongeo) values(POLYGONFROMTEXT('POLYGON((1 1,1 5,5 5,5 1,1 1))'));
Test POINT(3, 4)
select AsText(polygongeo) from zone where MBRWithin(POLYGONFROMTEXT('POINT(3 4)'),polygongeo);
Output: POLYGON((1 1,1 5,5 5,5 1,1 1))
Represents point POINT(3, 4) in the polygon area Inside
Test POINT(6, 1)
select AsText(polygongeo) from zone where MBRWithin(POLYGONFROMTEXT('POINT(6 1)'),polygongeo);
Output: Empty
indicates that point POINT(6, 1) is in the polygon area External
Summary: MySQL spatial query is not very suitable for map coordinates, so querying map coordinates can be implemented using mongodb. Reference: "Mongodb method to determine whether coordinates are within a specified polygon area"
This article explains how to use mysql to determine whether a point is within a specified polygon area. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
Use imagemagick in php to achieve old photo effects
How to calculate multiple sets through php Relevant knowledge of the Cartesian product
Related content of the sharing interface developed by WeChat
The above is the detailed content of Use mysql to determine whether a point is within a specified polygon area. For more information, please follow other related articles on the PHP Chinese website!