gpt4 book ai didi

ruby-on-rails - st_split 返回原始行

转载 作者:行者123 更新时间:2023-11-29 11:49:08 26 4
gpt4 key购买 nike

我想用 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))

怎么了?

最佳答案

ST_Split返回通过拆分几何图形产生的几何图形集合,所以恐怕这是预期的结果,因为您的 LineString 只有两个点。

考虑以下 LineString ...

LINESTRING(18.6435 42.5412,18.8440 42.5453,18.846 42.3994)

enter image description here

.. 并运行此查询,该查询使用上述 LineString 中的第二点应用 ST_Split:

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

...返回带有两个 LineStringsGeometryCollection:

                                                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

关于ruby-on-rails - st_split 返回原始行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50775980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com