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

标签 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))

怎么了?

最佳答案

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/

相关文章:

php - Symfony Doctrine 和存储过程

json - Postgres RFC3339 日期时间格式

c - 如何在我自己的 PostgreSQL 扩展中使用内部 PostGIS 函数?

postgresql - 从 PostGIS 点获取纬度/经度

mysql - 在 Rails 中以安全的方式使用子字符串查询

ruby-on-rails - rails : `bundle open rails` command not opening rails gem folder

sql - Postgres - 插入和复合外键

postgresql - 使用 shp2pgsql 转换 shapefile

ruby-on-rails - Ruby:创建沙盒评估?

ruby-on-rails - 关于在 Ruby on Rails 中实现代理键的问题