Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plsql 两点之间的距离_Plsql_Latitude Longitude - Fatal编程技术网

Plsql 两点之间的距离

Plsql 两点之间的距离,plsql,latitude-longitude,Plsql,Latitude Longitude,如果有任何指针,我都会很感激,我需要在PLSQL中找到到经度和纬度点集之间的距离。 有没有一个公式可以插入Long和Lat变量? 谢谢 Gav很久以前,我一直在寻找用坐标计算距离的方法,它帮了我很多忙: 我的测试查询: SELECT a.LATITUDE, a.LONGITUDE, a.distance FROM ( SELECT i.LATITUDE, i.LONGITUDE, calc_distance(i.LATITUDE, i.LONGITUDE, b.my

如果有任何指针,我都会很感激,我需要在PLSQL中找到到经度和纬度点集之间的距离。 有没有一个公式可以插入Long和Lat变量? 谢谢
Gav

很久以前,我一直在寻找用坐标计算距离的方法,它帮了我很多忙:

我的测试查询:

SELECT  a.LATITUDE, a.LONGITUDE, a.distance FROM
      (
        SELECT i.LATITUDE, i.LONGITUDE, calc_distance(i.LATITUDE, i.LONGITUDE, b.mylat, b.mylng) AS distance
        --https://www.google.com/maps/place/Parque+Nacional+da+Chapada+Diamantina/@-12.9838169,-42.6544937,8.13z/data=!4m5!3m4!1s0x74221bc4b6315bf:0x5b6f59531dd4b9bd!8m2!3d-12.5800309!4d-41.701355
        FROM (SELECT -12.9838169 LATITUDE, 
               -42.6544937 LONGITUDE

              FROM dual
             ) i
          JOIN (
            --https://www.google.com/maps/@-25.0814262,-48.7200207,10z
            SELECT -25.0814262 AS mylat,
                   -48.7200207 AS mylng,
                    3.1415926 AS pi, 
                    6371.4 earthradius
              FROM DUAL
          )b ON (1 = 1)

      )a
CREATE OR REPLACE FUNCTION calc_distance(
 pLat1 NUMBER,
 pLon1 NUMBER,
 pLat2 NUMBER,
 pLon2 NUMBER)
 RETURN NUMBER
IS

-- r is the spherical radius of earth in Kilometers
cSpherRad CONSTANT NUMBER := 6367;
                                                                        -- The spherical radius of earth in miles is 3956
a        NUMBER;
vLat     NUMBER;
vLat1Rad NUMBER;
vLat2Rad NUMBER;
vLon     NUMBER;
vLon1Rad NUMBER;
vLon2Rad NUMBER;

BEGIN
  /*
  Most computers require the arguments of trigonometric functions to be
  expressed in radians. To convert lon1, lat1 and lon2,lat2 from
  degrees,minutes, seconds to radians, first convert them to decimal
  degrees. To convert decimal degrees to radians, multiply the number
  of degrees by pi/180 = 0.017453293 radians/degrees.
  */

  vLat1Rad := pLat1 * 0.017453293;
  vLat2Rad := pLat2 * 0.017453293;
  vLon1Rad := pLon1 * 0.017453293;
  vLon2Rad := pLon2 * 0.017453293;

  vLon := vLon2Rad - vLon1Rad;
  vLat := vLat2Rad - vLat1Rad;

  a := POWER(SIN(vLat/2),2) + COS(vLat1Rad) * COS(vLat2Rad) *
  POWER(SIN(vLon/2),2);

  /*
  The intermediate result c is the great circle distance in radians.
  Inverse trigonometric functions return results expressed in radians.
  To express c in decimal degrees, multiply the number of radians by
   180/pi = 57.295780 degrees/radian.
  The great circle distance d will be in the same units as r.
  */

  RETURN ROUND(cSpherRad * 2 * ATAN2(SQRT(a), SQRT(1-a)),1);
EXCEPTION
  WHEN OTHERS THEN
    RETURN 999;
END calc_distance;
我不知道它是否适用于任何坐标,但在我的测试中,距离是精确的。 要验证:

链接中的函数:

SELECT  a.LATITUDE, a.LONGITUDE, a.distance FROM
      (
        SELECT i.LATITUDE, i.LONGITUDE, calc_distance(i.LATITUDE, i.LONGITUDE, b.mylat, b.mylng) AS distance
        --https://www.google.com/maps/place/Parque+Nacional+da+Chapada+Diamantina/@-12.9838169,-42.6544937,8.13z/data=!4m5!3m4!1s0x74221bc4b6315bf:0x5b6f59531dd4b9bd!8m2!3d-12.5800309!4d-41.701355
        FROM (SELECT -12.9838169 LATITUDE, 
               -42.6544937 LONGITUDE

              FROM dual
             ) i
          JOIN (
            --https://www.google.com/maps/@-25.0814262,-48.7200207,10z
            SELECT -25.0814262 AS mylat,
                   -48.7200207 AS mylng,
                    3.1415926 AS pi, 
                    6371.4 earthradius
              FROM DUAL
          )b ON (1 = 1)

      )a
CREATE OR REPLACE FUNCTION calc_distance(
 pLat1 NUMBER,
 pLon1 NUMBER,
 pLat2 NUMBER,
 pLon2 NUMBER)
 RETURN NUMBER
IS

-- r is the spherical radius of earth in Kilometers
cSpherRad CONSTANT NUMBER := 6367;
                                                                        -- The spherical radius of earth in miles is 3956
a        NUMBER;
vLat     NUMBER;
vLat1Rad NUMBER;
vLat2Rad NUMBER;
vLon     NUMBER;
vLon1Rad NUMBER;
vLon2Rad NUMBER;

BEGIN
  /*
  Most computers require the arguments of trigonometric functions to be
  expressed in radians. To convert lon1, lat1 and lon2,lat2 from
  degrees,minutes, seconds to radians, first convert them to decimal
  degrees. To convert decimal degrees to radians, multiply the number
  of degrees by pi/180 = 0.017453293 radians/degrees.
  */

  vLat1Rad := pLat1 * 0.017453293;
  vLat2Rad := pLat2 * 0.017453293;
  vLon1Rad := pLon1 * 0.017453293;
  vLon2Rad := pLon2 * 0.017453293;

  vLon := vLon2Rad - vLon1Rad;
  vLat := vLat2Rad - vLat1Rad;

  a := POWER(SIN(vLat/2),2) + COS(vLat1Rad) * COS(vLat2Rad) *
  POWER(SIN(vLon/2),2);

  /*
  The intermediate result c is the great circle distance in radians.
  Inverse trigonometric functions return results expressed in radians.
  To express c in decimal degrees, multiply the number of radians by
   180/pi = 57.295780 degrees/radian.
  The great circle distance d will be in the same units as r.
  */

  RETURN ROUND(cSpherRad * 2 * ATAN2(SQRT(a), SQRT(1-a)),1);
EXCEPTION
  WHEN OTHERS THEN
    RETURN 999;
END calc_distance;

我尝试过这个方法,但没有成功…ACOS(弧度(90-51.332005))*COS(弧度(90-51.289372))+SIN(弧度(90-51.332005))*SIN(弧度(90-51.289372))*COS(弧度(-0.56482702--0.59724349)),作为ACOSTEST*6371,因为Distbweented也提到了这一点。。。SDO_几何体SDO_距离(MDSYS.SDO_几何体(2001,8307,MDSYS.SDO_点类型(52.332005,-0.56582702,NULL),NULL,NULL),MDSYS.SDO_几何体(2001,8307,MDSYS.SDO_点类型(52.289372,-0.59824349,NULL),NULL),1,'MILE')作为距离您是否使用哈弗森公式?dlon=lon2-lon1;dlat=lat2-lat1;a=(sin(dlat/2))^2+cos(lat1)*cos(lat2)*(sin(dlon/2))^2;c=2*atan2(sqrt(a),sqrt(1-a));d=R*c(其中R是地球的半径)};当你说“我尝试过,但没有成功”时,你是什么意思?它编译了吗?它跑了吗?你有什么结果吗?你有什么错误吗?嗨,我想它不像弧度。。。ORA-00904:“弧度”:无效标识符00904。00000-%s:无效标识符