代码之家  ›  专栏  ›  技术社区  ›  Ben

St_Split返回原始行

  •  2
  • Ben  · 技术社区  · 6 年前

    我想用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 回复  |  直到 6 年前
        1
  •  1
  •   Jim Jones    6 年前
    LineString

    LINESTRING(18.6435 42.5412,18.8440 42.5453,18.846 42.3994)
    

    enter image description here

    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