【问题标题】:Get midpoint of SDO.GEOMETRY polyline获取 SDO.GEOMETRY 折线的中点
【发布时间】:2019-12-10 06:15:06
【问题描述】:

我在 Oracle 18c 中有一个表,其中有一个带有折线的 SDO_GEOMETRY 列。

我想使用 SQL 查询折线中点的 X 和 Y 坐标。

有没有办法用 Oracle Spatial 做到这一点?

【问题讨论】:

  • 您确定没有 Oracle Spatial 吗?它是默认安装的,几天前它现在​​是free for all editions

标签: oracle geometry coordinates centroid oracle-spatial


【解决方案1】:

Oracle Spatial 有一个名为 SDO_LRSlinear referencing 包。可用于查找折线的中点坐标。

--In this case, 'sdo' is the name of the sdo_geometry column.

sdo_lrs.convert_to_std_geom(sdo_lrs.locate_pt(sdo_lrs.convert_to_lrs_geom(sdo,3)
    ,sdo_geom.sdo_length(sdo,3)/2)).sdo_point.x as midpoint_x,

sdo_lrs.convert_to_std_geom(sdo_lrs.locate_pt(sdo_lrs.convert_to_lrs_geom(sdo,3)
    ,sdo_geom.sdo_length(sdo,3)/2)).sdo_point.y as midpoint_y

奖励积分:

这就是如何将 ESRI 的 SDE.ST_GEOMETRY 转换为 SDO_GEOMETRY 以获取中点坐标:

select
    sdo_lrs.convert_to_std_geom(sdo_lrs.locate_pt(sdo_lrs.convert_to_lrs_geom(sdo,3),sdo_geom.sdo_length(sdo,3)/2)).sdo_point.x as midpoint_x,
    sdo_lrs.convert_to_std_geom(sdo_lrs.locate_pt(sdo_lrs.convert_to_lrs_geom(sdo,3),sdo_geom.sdo_length(sdo,3)/2)).sdo_point.y as midpoint_y
from
    (select
        sdo_util.from_wktgeometry(sde.st_astext(shape)) as sdo
    from
        roads)

这个答案的灵感来自 Code Review 上的一个答案:Calculate the midpoint of a polyline

【讨论】:

    【解决方案2】:

    围绕折线创建一个假缓冲区,然后获取缓冲区的中心点:

    sde.st_x(sde.st_pointonsurface(sde.st_buffer(shape, 0.05))) as x,
    sde.st_y(sde.st_pointonsurface(sde.st_buffer(shape, 0.05))) as y
    

    ST_PointOnSurface 接受 ST_Polygon 或 ST_MultiPolygon 并返回 ST_Point 保证位于其表面

    【讨论】:

    • 经过进一步测试,这似乎不是一个好方法。中点没有被放置在沿线的正确位置(尤其是曲线)。所以,我认为真正的中点计算会更好(例如:线性参考解决方案)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多