mysql判断坐标在区域,MySQL gis 判断某个点是否在多角形中

建表:

CREATE TABLE `test` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`pnt` point DEFAULT NULL,

`pgn` polygon DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;

插入数据:

INSERT INTO `test` VALUES ('12', GeomFromText('POINT(1 1)'), null);

INSERT INTO `test` VALUES ('11', GeomFromText('POINT(1 1)'), null);

INSERT INTO `test` VALUES ('1', GeomFromText('POINT(1 1)'), null);

INSERT INTO `test` VALUES ('2', GeomFromText('POINT(1 5)'), null);

INSERT INTO `test` VALUES ('3', GeomFromText('POINT(2 2)'), null);

INSERT INTO `test` VALUES ('4', GeomFromText('POINT(2 3)'), null);

INSERT INTO `test` VALUES ('5', GeomFromText('POINT(3 2)'), null);

INSERT INTO `test` VALUES ('8', GeomFromText('POINT(2 3)'), null);

INSERT INTO `test` VALUES ('7', GeomFromText('POINT(2 2)'), null);

INSERT INTO `test` VALUES ('9', GeomFromText('POINT(12 12)'), null);

INSERT INTO `test` VALUES ('10', null, null);

INSERT INTO `test` VALUES ('13', null, GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (5 5, 7 5, 7 7, 5 7, 5 5))'));

INSERT INTO `test` VALUES ('14', null, GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'));

INSERT INTO `test` VALUES ('15', null, GeomFromText('POINT(4 4)'));

INSERT INTO `test` VALUES ('16', GeomFromText('POINT(4 4)'), null);

INSERT INTO `test` VALUES ('17', GeomFromText('POINT(4 4)'), null);

——————————————————————————————

插入点point:

INSERT INTO test VALUE ('17',GeomFromText('POINT(4 4)'),NULL);

插入点多边形:

INSERT INTO test VALUE ('14',NULL,GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0))'));

判断点在哪个多边形内:

select id from test where MBRContains(pgn, GeomFromText('Point(1 1)'));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值