1.创建测试表
CREATE TABLE zone
(
id
int(10) unsigned NOT NULL AUTO_INCREMENT,
polygongeo
geometry NOT NULL,
PRIMARY KEY (id
)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
2.插入多边形数据
insert into zone(polygongeo) values(geomfromtext(‘POLYGON((1 1,1 5,5 5,5 1,1 1))’));
1
3.判断点是否在多边形区域
测试 POINT(3, 4)
select AsText(polygongeo) from zone where MBRWithin(POLYGONFROMTEXT(‘POINT(3 4)’),polygongeo);
1
输出: POLYGON((1 1,1 5,5 5,5 1,1 1))
表示点 POINT(3, 4) 在多边形区域内
测试 POINT(6, 1)
select AsText(polygongeo) from zone where MBRWithin(POLYGONFROMTEXT(‘POINT(6 1)’),polygongeo);
1
输出: 空
表示点 POINT(6, 1) 在多边形区域外