MySQL 中的空间索引 - 错误 - 无法从发送到 GEOMETRY 字段的数据中获取几何对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5875327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spatial Index in MySQL - ERROR - Cannot get geometry object from data you send to the GEOMETRY field
提问by jisaacstone
I am new to the whole 'spatial index' thing, but it seems to be the best solution for filtering based on latitude/longitude. So I added a column to my table:
我是整个“空间索引”的新手,但它似乎是基于纬度/经度过滤的最佳解决方案。所以我在表中添加了一列:
So I created a geometry
field:
所以我创建了一个geometry
字段:
ALTER TABLE `addresses` ADD `point` POINT NOT NULL
And then I tried to add an index:
然后我尝试添加一个索引:
ALTER TABLE `addresses` ADD SPATIAL INDEX ( `point` )
But I get an error:
但我收到一个错误:
#1416 - Cannot get geometry object from data you send to the GEOMETRY field
What am I doing wrong here?
我在这里做错了什么?
回答by jisaacstone
OK I found the solution: Can't create a spatial index if some of the column fields contain no data. After running
好的,我找到了解决方案:如果某些列字段不包含数据,则无法创建空间索引。运行后
UPDATE `addresses` SET `point` = POINT( lng, lat )
Everything worked fine.
一切正常。
回答by Mike Graf
I had this same error (Cannot get geometry object from data you send to the GEOMETRY field) but when trying to import spatial data from a mysql dump. I found that some rows had "null" (X is null or Y is null) spatial data even though the column was "NOT NULL"..
我有同样的错误(无法从发送到 GEOMETRY 字段的数据中获取几何对象)但是在尝试从 mysql 转储导入空间数据时。我发现一些行有“空”(X 为空或 Y 为空)空间数据,即使列是“NOT NULL”..
Check if you have the same problem as I'm describing with this SQL:
检查您是否遇到与我使用此 SQL 描述的问题相同的问题:
SELECT id FROM locations WHERE X(coordinates) IS NULL OR Y(coordinates) IS NULL;
SELECT id FROM location WHERE X(coordinates) IS NULL OR Y(coordinates) IS NULL;
If you have some rows then this is what worked for me:
如果您有一些行,那么这对我有用:
UPDATE locations SET coordinates = POINT(0,0) WHERE X(coordinates) IS NULL OR Y(coordinates) IS NULL;
更新位置 SET 坐标 = POINT(0,0) WHERE X(coordinates) IS NULL OR Y(coordinates) IS NULL;
Then try your mysqldump (or from phpmyadmin) and import again.
然后尝试您的 mysqldump(或来自 phpmyadmin)并再次导入。