我有一个代表长岛的多边形。我想计算从长岛内的一个地址(由一个点表示)到海岸上最近的点(由该多边形的周长表示)之间的距离。
下面是我编写的查询,但它返回的距离为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
答案 0 :(得分:0)
我希望能够按照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