supabase-js插入几何对象
我正在尝试将几何对象插入我的supabase Postgres表中。
有以下几何列:
列名称 | 数据类型 |
---|---|
点点 | line_string |
linestring | polygon |
polygon | 我 |
我尝试了多种插入点对象的方法(我还没有进入线文或多边形,看到它们更复杂)。
const geometry = { x: -123, y: -123 }
const point = `(${geometry.x}, ${geometry.y})`; // Try number 1
const point = `point(${geometry.x},${geometry.y})`; // Try number 2
const point = `ST_SetSRID(ST_MakePoint(${geometry.y}, ${geometry.x}), 4326)`; // Try number 3
const { data, error } = await supabase.from('geometries').upsert({ point });
这三个都给出了相同的错误:
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"(0" <-- parse error at position 2 within geometry'
}
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"point(0, 0" <-- parse error at position 10 within geometry'
}
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"ST" <-- parse error at position 2 within geometry'
}
如何插入/UPSERT点对象?衬里?多边形?
I'm trying to insert geometry objects into my supabase postgres table.
I have the following geometry columns:
Column name | Data type |
---|---|
point | POINT |
line_string | LINESTRING |
polygon | POLYGON |
I have tried multiple ways to insert POINT objects (I haven't gotten to the linestrings or polygons, seeing that they are more complicated).
const geometry = { x: -123, y: -123 }
const point = `(${geometry.x}, ${geometry.y})`; // Try number 1
const point = `point(${geometry.x},${geometry.y})`; // Try number 2
const point = `ST_SetSRID(ST_MakePoint(${geometry.y}, ${geometry.x}), 4326)`; // Try number 3
const { data, error } = await supabase.from('geometries').upsert({ point });
All three gave the same error:
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"(0" <-- parse error at position 2 within geometry'
}
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"point(0, 0" <-- parse error at position 10 within geometry'
}
{
message: 'parse error - invalid geometry',
code: 'XX000',
details: null,
hint: '"ST" <-- parse error at position 2 within geometry'
}
How do I insert/upsert point objects? Linestrings? Polygons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于
点
,您必须删除坐标值之间的逗号。让我知道这是怎么回事!
For
point
, you have to remove the comma between the coordinates values.Let me know how it goes with this!
如书面在这里
关于精确度的二进制数据(字节数组)的便携式,完整的表述,我们可以读取在这里:
几何可以用
wkb
使用openlayers转换。这样,我们就不需要在查询中使用PostGIS功能。基于 documentation> WKB。As written here:
Concerning precision we can read here:
Geometries can be transformed in
WKB
with OpenLayers. This way we don't need to use PostGIS functions in our query. Based on the documentation I managed to update/insert geometries as WKB.