St_split返回原始行

时间:2018-06-09 15:48:20

标签: ruby-on-rails postgresql postgis

我想用postgis拆分一个线串。

我的功能:

  @distance_b_to_a = Track.find_by_sql(
  ["SELECT
    ST_Split(line, ST_Closestpoint(pta,line))  AS dst_line
    FROM (
      SELECT
        'SRID=4326;LINESTRING(1.391991 46.441430,1.506078 46.556788)'::geometry line,
        'SRID=4326;POINT(1.396636962890625 46.442352066959174)'::geometry pta,
    ) data"
  ])

和我的节目:

  <p>Test : <%= @distance_b_to_a.first.dst_line %></p>

返回我的原始线串:

Test : GEOMETRYCOLLECTION (LINESTRING (1.391991 46.44143, 1.506078 46.556788))

怎么了?

1 个答案:

答案 0 :(得分:1)

ST_Split返回通过拆分几何图形得到的几何图形集合,所以我担心这是预期的结果,因为LineString只有两个点。

考虑以下LineString ...

LINESTRING(18.6435 42.5412,18.8440 42.5453,18.846 42.3994)

enter image description here

..然后运行此查询,使用上述ST_Split中的第二个点应用LineString

WITH j AS (
SELECT 
    'SRID=4326;POINT(18.8440 42.5453)'::GEOMETRY AS pta,
    'SRID=4326;LINESTRING(18.6435 42.5412,18.8440 42.5453,18.846 42.3994)'::GEOMETRY AS line
)
SELECT 
  ST_AsText(
  ST_Split(line,
    ST_ClosestPoint(pta,line))) FROM j

...使用两个GeometryCollection返回LineStrings

                                                st_astext                                                 
----------------------------------------------------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(18.6435 42.5412,18.844 42.5453),LINESTRING(18.844 42.5453,18.846 42.3994))
(1 Zeile)

enter image description here enter image description here