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.
Recommended related mysql video tutorials: "mysql tutorial"
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
Test POINT(6, 1)
select AsText(polygongeo) from zone where MBRWithin(POLYGONFROMTEXT('POINT(6 1)'),polygongeo);
Output: Empty
Indicates point POINT(6, 1) outside the polygon area
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 determine whether a point is within a specified polygon area through mysql. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
How to call php imagemagick to achieve the effect of old photos
Explanation on calculating the Cartesian product of multiple sets in PHP
About the use and performance analysis of php file containing directory configuration open_basedir
The above is the detailed content of How to determine whether a point is within a specified polygon area through mysql. For more information, please follow other related articles on the PHP Chinese website!