我希望有一个类似于 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