STLineMerge 不会让我的 MULTILINESTRING 进入 LINESTRING

STLineMerge do not make my MULTILINESTRING in to LINESTRING

这是我的多线串部分:

MULTILINESTRING((59.6338836103678 36.3408616511151,59.6336405351758 36.3410074124113),(59.648377513513 36.3329201331362,59.6481338515878 36.3326094998047,59.6478482801467 36.3322287937626))

当我在 postgresql 中执行这个命令时:

SELECT  ST_AsText(ST_LineMerge(ST_GeomFromText('MULTILINESTRING((59.6338836103678 36.3408616511151,59.6336405351758 36.3410074124113),(59.648377513513 36.3329201331362,59.6481338515878 36.3326094998047,59.6478482801467 36.3322287937626))')));

我没有得到 linestring?我仍然得到 MULTILINESTRING ?

它返回原始的多线串,st_linemerge 在无法合并时会这样做。看起来您的多线串有单独的部分,这就是它无法合并的原因。当我将它放入 QGIS 时,我得到以下结果。

这里有一些关于这个问题的更多信息:https://gis.stackexchange.com/questions/83069/cannot-st-linemerge-a-multilinestring-because-its-not-properly-ordered

我假设您希望尽可能将多线串合并为一个线串,否则合并为 N 条线串,其中 N 是尽可能少的线串数。

我添加了另一个可以合并到一个线串的多线串,以检查它是否按预期工作。

with  edges as (select ST_GeomFromText('MULTILINESTRING((59.6338836103678 36.3408616511151,59.6336405351758 36.3410074124113),
                                                        (59.648377513513 36.3329201331362,59.6481338515878 36.3326094998047,59.6478482801467 36.3322287937626))') geom
                UNION
                select ST_GeomFromText('MULTILINESTRING((0 0,1 1),
                                                        (1 1,30 20,100 120)
                                                       )') geom)

select row_number() over () id,geom, st_astext(geom)
    FROM (select distinct (st_dump(st_linemerge(geom))).geom geom
            from (select st_union(geom) geom
                    from edges e) a
         ) b;