我正在使用MySQL 8并带有此表:
CREATE TABLE `country` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`geometry` multipolygon NOT NULL,
PRIMARY KEY (`id`),
SPATIAL KEY `country_geometry_index` (`geometry`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
然后从https://github.com/nvkelso/natural-earth-vector/blob/master/geojson/ne_50m_admin_0_countries.geojson处使用geometry
插入ST_GeomFromGeoJSON
数据
示例:
INSERT INTO `country`
SET
`name` = "Spain",
`geometry` = ST_GeomFromGeoJSON(geojson[spain].geometry);
现在,我想使用以下方法搜索点是否在任何国家/地区的多边形内:
select *
from `country`
where ST_Contains(`geometry`, POINT(42.000000, -8.000000))
limit 1;
但是我得到了错误:
ERROR 3033 (HY000): Binary geometry function st_contains given two geometries of different srids: 4326 and 0, which should have been identical.
有帮助吗?谢谢!
更新1:
正如@Jose Hermosilla Rodrigo所说,我需要设置SRID。现在我没有查询错误,但没有结果:
select *
from `country`
where ST_Contains(`geometry`, ST_SRID(POINT(42.000000, -8.000000), 4326))
limit 1;
明天我将检查geometry
个值:)
更新2:
正如@Jose Hermosilla Rodrigo所说,我需要反转POINT坐标:
select *
from `country`
where ST_Contains(`geometry`, ST_SRID(POINT(-8.000000, 42.000000), 4326))
limit 1;