gpt4 book ai didi

mysql - 插入到 mysql 中的地理空间字段

转载 作者:行者123 更新时间:2023-11-29 09:24:06 25 4
gpt4 key购买 nike

我有一个 string 对象,它代表十六进制的多边形,我想将其保存到 mysql 数据库中。我按照描述使用了``here 。这是我用来生成多边形的方法:

func GetPolygon(coordinates [][]geom.Coord) (string, error) {
unitSquare := geom.NewPolygon(geom.XY).MustSetCoords(coordinates)

polygon, err := wkb.Marshal(unitSquare, wkb.NDR)
if err != nil {
fmt.Printf("wkb marshal error: %s\n", err.Error())
return "", err
}

polygonHex := hex.Dump(polygon)
return polygonHex, nil
}

这就是我生成查询的方式:

insertQuery := fmt.Sprintf(`INSERT INTO my_table (polygon) VALUE (ST_GeomFromWKB(X'%v'))`, poly)

但是当我执行查询时,我得到:

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'X'00000000  01 03 00 00 00 01 00 00  00 92 00 00 00 ff ff ff  |................|' at line 1

最佳答案

要在 Golang 中从字节数组创建十六进制字符串,必须使用以下命令:

s := hex.EncodeToString(b)

Dump 命令生成 xxd 类似的输出。

关于mysql - 插入到 mysql 中的地理空间字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59917043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com