yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Quintiq file version 2.0
#parent: #root
Function CalcATCFDistance
{
  TextBody:
  [*
    // tyg2 Mar-31-2016 (created)
    
    /*
    see http://mathworld.wolfram.com/GreatCircle.html
    */
    value := 0.0;
    
    earthRadius := 6378
    
    orileg := guard( this.AsOriginStockingPointLeg().StockingPoint_MP().GIS_StockingPointAddress().GIS_StockingPointGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) );
    destleg := guard( this.AsDestinationStockingPointLeg().StockingPoint_MP().GIS_StockingPointAddress().GIS_StockingPointGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) );
    
    if( not ( isnull( orileg ) or isnull( destleg ) ) )
    {
    
      unitlat := pi * orileg.Y() / 180.0
      unitlong := pi * orileg.X() / 180.0
      splat := pi * destleg.Y() / 180.0
      splong := pi * destleg.X() / 180.0
    
      theCos := cos( splat ) * cos( unitlat )* cos( splong  - unitlong )  + sin( splat ) * sin ( unitlat )
    
      // round-off errors.
      // M AF Putting the 1.0 as the first parameter causes trouble, submited rfc
      theCos := maxvalue( theCos,  -1.0 )
      theCos := minvalue( theCos,  1.0 )
    
      angle :=  acos( theCos )
    
      value := angle * earthRadius;
    }
    
    this.ATCFDistance( value );
  *]
}