我的问题类似于这个问题How to create a PostgreSQL partitioned sequence?
在我的情况下,使用此代码将多边形顶点转换为点
SELECT geom, gid, path,nextval('seq_oid1') as seq_id,
rank() OVER (PARTITION BY gid ORDER BY gid) AS pos
FROM (
SELECT DISTINCT ON (geom) geom, path, gid
FROM (
SELECT (ST_DumpPoints(geom)).geom, (ST_DumpPoints(geom)).path, gid
FROM edge_snapping.polygon1
) f
ORDER BY geom, path, gid
) f
ORDER BY gid, path;
但是,无论多边形id如何,此代码都会为所有顶点生成序列ID。
我想基于多边形id分区来索引点,并且从每个多边形生成的点应该以序号id开始。我感谢任何帮助。因为我不知道在这种情况下该怎么做。
答案 0 :(得分:1)
SELECT geom, gid, path,nextval('seq_oid1') as seq_id,
rank() OVER (PARTITION BY gid ORDER BY gid) AS pos
FROM (
SELECT DISTINCT ON (geom) geom, path, gid
FROM (
SELECT (ST_DumpPoints(geom)).geom, (ST_DumpPoints(geom)).path, gid
FROM edge_snapping.polygon1
) f
ORDER BY geom, path, gid
) f
WHERE pos = 1 ORDER BY gid, path;