mysql - 使用 mysql 查看纬度/经度是否落在多边形内

标签 mysql gis polygon point

我已经创建了下表

CREATE TABLE geom (g GEOMETRY);

并插入了很多行,示例如下:

INSERT INTO geom (g)
VALUES(PolygonFromText('POLYGON((
9.190586853 45.464518970,
9.190602686 45.463993916,
9.191572471 45.464001929,
9.191613325 45.463884676,
9.192136130 45.463880767,
9.192111509 45.464095594,
9.192427961 45.464117804,
9.192417811 45.464112862,
9.192509035 45.464225851,
9.192493139 45.464371079,
9.192448471 45.464439002,
9.192387444 45.464477861,
9.192051402 45.464483037,
9.192012814 45.464643592,
9.191640825 45.464647090,
9.191622331 45.464506215,
9.190586853 45.464518970))')
);

现在我想搜索所有数据并返回我所拥有的纬度/经度落在任何多边形内的条目。

如何使用 mysql 完成此操作?还是有人知道任何可以为我指明正确方向的链接?

最佳答案

自 v5.1 起的 MySQL 仅支持对 minimum bounding rectangles (MBR) 的操作.虽然有一个“Contains ”函数可以满足您的需要,但它并未完全实现并退回到使用 MBRContains

来自relevant manual page

Currently, MySQL does not implement these functions according to the specification. Those that are implemented return the same result as the corresponding MBR-based functions. This includes functions in the following list other than Distance() and Related().

These functions may be implemented in future releases with full support for spatial analysis, not just MBR-based support.

你可以做的是让MySQL根据MBR给你一个大概的结果,然后进行后处理来进行更准确的测试。或者,切换到 PostGIS !

(2012 年 5 月更新 - 感谢 Mike Toews)

MySQL 5.6.1+ 提供 functions which use object shapes而不是MBR

MySQL originally implemented these functions such that they used object bounding rectangles and returned the same result as the corresponding MBR-based functions. As of MySQL 5.6.1, corresponding versions are available that use precise object shapes. These versions are named with an ST_ prefix. For example, Contains() uses object bounding rectangles, whereas ST_Contains() uses object shapes.

关于mysql - 使用 mysql 查看纬度/经度是否落在多边形内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1078386/

相关文章:

mysql - SQL 检查表中是否不存在该值

mysql - 如何从表中获取未在另一个表中提及的行

java - 使用java更新单列的mysql数据

gis - Java 地理信息库

python - GeoAlchemy2:从几何列中提取地理属性

java - 使用java从mysql数据库检索图像以存储在本地磁盘上时出现问题

r - 在 R 中,如何将 SpatialPolygons* 转换为映射对象

r - 如何获得 glm 系数的阴影置信区间带?

geometry - 扫描线多边形三角剖分 : How to find edge left to current vertex?

algorithm - 如何找到给定顶点的所有多边形形状?