无法将 WKB 插入 MySQL 中的 POINT 列

Cannot insert WKB to POINT column in MySQL

我正在构建一个 Node.js 应用程序来管理我所在地区的兴趣点。我通过使用 wkx 将 latlong 坐标转换为 WKB 缓冲区来插入 POI,然后将其插入 MySQL 中的 POINT 列。查询是用 Knex.js 构建的。查询如下所示:

INSERT INTO `places` (`name`, `coordinate`)
    VALUES ('Null Island', X'00000000010100000000000000000000000000000000000000')

它抛出 Cannot get geometry object from data you send to the GEOMETRY field

我修改了一下,变成了这样:

INSERT INTO `places` (`name`, `coordinate`)
    VALUES ('Null Island', UNHEX('00000000010100000000000000000000000000000000000000'))

但是还是不行。我终于通过使用 ST_GEOMFROMTEXT(0 0) 让它工作了。即使我像这样搞砸它也能正常工作:

INSERT INTO `places` (`name`, `coordinate`)
    VALUES ('Null Island', UNHEX(HEX(ST_GEOMFROMTEXT('POINT(0 0)')))

怎么了?我怎样才能让它直接从缓冲区工作? 我怀疑我的问题与 this one.

类似

来自MySQL Reference Manual on Supported Spatial Data Formats

Internally, MySQL stores geometry values in a format that is not identical to either WKT or WKB format. (Internal format is like WKB but with an initial 4 bytes to indicate the SRID.)

因此,插入 WKB 值(例如由 wkx 生成的值)不能 直接完成。相反,请按照 here.

所述使用 ST_GEOMFROMWKB()