【问题标题】:Using Oracle SQL spatial functions to calculate the distance between a point and the perimeter of the polygon that surrounds that point?使用 Oracle SQL 空间函数计算点与围绕该点的多边形周长之间的距离?
【发布时间】:2018-10-04 04:41:49
【问题描述】:

我有一个代表长岛的多边形。我想计算从长岛内的一个地址(由一个点表示)到海岸上最近的点(由该多边形的周长表示)的距离。

以下是我编写的查询,但它返回距离 0,因为该点位于多边形内。在这种情况下,我是否需要使用其他功能或任何其他方式来解决此问题?

select /*+ ordered */ 
 sdo_nn_distance (1) distance 
from ABPROD.ABT_COASTLINE_SHAPE_DATA CSD 
where sdo_nn (CSD_LOC_GEO,sdo_geometry(2001,8307,sdo_point_type(-73.1,40.8, null),null, null),'unit=mile',1) = 'TRUE' 
and CSD_LOC_ID = '166'
and rownum = 1 

【问题讨论】:

    标签: sql oracle geospatial


    【解决方案1】:

    我希望有一个类似于 sdo_nn_distance 函数的简单解决方案,但我没有这样的运气,所以我不得不依靠一些解决方法。我使用纽约岛多边形进行了测试,它的执行速度相当快。当我切换到北美大陆多边形时,我仍然需要看看它返回的速度。

    select * from 
    (select 
    sdo_geom.sdo_distance(sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),sdo_ordinate_array(/*selected coordinates*/-72.883398, 40.895885)),
                          sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),sdo_ordinate_array(X,Y)),1,'unit=Mile') distance_mile
    from 
     ABPROD.ABT_COASTLINE_SHAPE_DATA             CSD,
        --Above line identifies the table that contains all of the polygons
    table(SDO_UTIL.GETVERTICES(CSD.CSD_LOC_GEO)) t
        --Above line creates a list of all of the coordinates (X,Y) that make up the polygon that the selected coordinates fall within
    
    where 
        SDO_RELATE(CSD_LOC_GEO, sdo_geometry(2001,8307,sdo_point_type(/*selected coordinates*/-72.883398, 40.895885, null),null, null), 'mask=touch+contains') = 'TRUE'
        --Above line finds the polygon that the selected coordinates fall within
    
    and CSD_LEVEL_NBR = 1
        --Above line limits results to land shapes, rivers and lakes are excluded
    
    order by 1 asc
        --Above line orders results by distance_mile so that row #1 is the closest distance
    )
    where rownum = 1
        --Above line limits results to only the closest distance
    

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 2020-03-28
      • 2017-02-21
      • 2023-03-25
      • 2017-06-04
      • 1970-01-01
      • 2017-01-08
      • 2014-11-29
      相关资源
      最近更新 更多