Get midpoint of SDO.GEOMETRY polyline

China☆狼群 提交于 2020-01-24 12:05:28

问题


I have a table in Oracle 18c that has an SDO_GEOMETRY column with polylines.

I want to query the X and Y coordinates of the polyline midpoints using SQL.

Is there a way to do this with Oracle Spatial?


回答1:


Oracle Spatial has a linear referencing package called SDO_LRS. It can be used to find the midpoint coordinates of a polyline.

--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

For bonus points:

This is how ESRI's SDE.ST_GEOMETRY can be converted to SDO_GEOMETRY for the purpose of getting the midpoint coordinates:

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)

This answer was inspired by an answer on Code Review: Calculate the midpoint of a polyline.



来源:https://stackoverflow.com/questions/59261247/get-midpoint-of-sdo-geometry-polyline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!