【问题标题】:Distance between two Point with Latitude & Longitude in oracle DBoracle DB中经纬度两点之间的距离
【发布时间】:2020-12-03 10:37:26
【问题描述】:

我需要通过 Pl SQL Query 计算两个位置之间的距离。我尝试了一些 Qry 但没有得到它。

为此,我们在 SQL 中使用查询如下

SELECT ROUND(geography::Point(cast('19.2806118' as float),cast('72.8757395' as float) , 
4326).STDistance(geography::Point(cast('19.4482006' as float),
cast('72.7912511' as float), 4326))/1000,1) DIST

结果:20.6

为了在 ORACLE Db 中计算相同,我在互联网上找到了一个解决方案,如下所示

select sdo_geom.sdo_distance(sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),
sdo_ordinate_array( 19.2806118,72.8757395)),sdo_geometry(2001,4326, null,sdo_elem_info_array(1, 1, 
1),sdo_ordinate_array( 19.4482006,72.7912511)),1,'unit=KM') distance_km from dual

结果:1​​0.9271..

当我得到 MS SQL 时,请建议将在 KM 中产生结果的方法

【问题讨论】:

    标签: oracle geometry oracle-spatial


    【解决方案1】:

    当我得到 MS SQL 时,请建议可以在 KM 中得到结果的方法

    交换参数顺序19.2806118,72.875739572.8757395,19.2806118

    select sdo_geom.sdo_distance(
       sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),
                     sdo_ordinate_array(72.8757395,19.2806118)),
       sdo_geometry(2001,4326, null,sdo_elem_info_array(1, 1,1),
                     sdo_ordinate_array(72.7912511,19.4482006))
       ,1
       ,'unit=KM') distance_km 
    from dual;
    

    产生与 SQL Server 完全相同的结果:20.5657053685075

    db<>fiddle demo Oracle
    db<>fiddle demo SQL Server

    或者使用sdo_point:

    SELECT sdo_geom.sdo_distance(
             sdo_geometry(2001, 4326,
                    sdo_point_type(72.8757395, 19.2806118, NULL), NULL, NULL),
              sdo_geometry(2001, 4326,
                   sdo_point_type(72.7912511, 19.4482006, NULL), NULL, NULL),
                   1, 'unit=KM') distance_in_m
    from DUAL;
    

    SQL 服务器:geography::Point ( Lat, Long, SRID )

    【讨论】:

    • 感谢您的解决方案,我在其他问题中发现它相同。
    猜你喜欢
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 2011-04-11
    • 2013-10-25
    • 1970-01-01
    • 2012-01-26
    • 2015-07-16
    相关资源
    最近更新 更多