我在尝试保存已格式化为 GeoJSON 的多边形时遇到问题,问题是我将多边形作为坐标数组数组,但 postgres 多边形字段需要一个元组数组,但 javascript 没有支持元组,因此我不知道如何将数据插入 Postgres。
postgres 如何获取数据的示例:
INSERT INTO table VALUES(default, '[(x,y), (x,y)]');
我拥有的数据示例:
"coordinates": [
[
[
49.5703125,
59.5343180010956
],
[
54.84375,
54.77534585936447
],
[
63.28125,
59.5343180010956
],
[
54.84375,
61.77312286453146
],
[
49.5703125,
60.930432202923335
],
[
49.5703125,
59.5343180010956
]
]
]
Run Code Online (Sandbox Code Playgroud)
尝试将数组保存到 postgres 时遇到的错误:
{
"message": "invalid input syntax for type polygon: \"{{\"-64.1892249612655\",\"-31.4212119274207\"},{\"-64.1896863245919\",\"-31.4223122073094\"},{\"-64.1900957427429\",\"-31.423283040535\"},{\"-64.1901970936061\",\"-31.4235231632172\"},{\"-64.190677427225\",\"-31.4246610035708\"},{\"-64.1892249612655\",\"-31.4212119274207\"}}\"",
"name": "QueryFailedError",
"length": 353,
"severity": "ERROR",
"code": "22P02",
"file": "float.c",
"line": "542",
"routine": "float8in_internal",
"query": "INSERT INTO \"zones\"(\"title\", \"boundary_points\", \"created_at\", \"updated_at\", \"iconFileId\", …Run Code Online (Sandbox Code Playgroud)