# null means aBA, aDC are not used
### Minimum Distance from Point to Geodesic
WITH PX (geom) AS (  
SELECT STX_GeodesicMinDistance ('POINT(29 42)';'POINT(-70 -35)', POINT(-22 64)')  
) SELECT ST_AsLatLonText (geom, 'D\"M\"S.SSSSSSSSS\") as PX,  
ST_Distance (geom, 'POINT (-22 64)\"::geography) as dXP,  
degrees (ST_Azimuth (geom, 'POINT (29 42)\"::geography) -  
ST_Azimuth (geom, 'POINT (-22 64)\"::geography) ) \"aXA-aXP\"  
FROM PX;  
Query output:  
px | dxp | aXA-aXP  
3758'41.223640784\"  
18 deg20'56.627934277\" | 3928422.73531622 | 90.000000000001  
**Scheme 10. ** Testing the minimum distance with the new SQL function. To check the errors, we use slightly different tests A and B. The test A is similar to test A in the previous algorithm but considering now that the azimuth \(\alpha_{\text{XP}}\) must differ in 90 degrees with respect to the azimuths \(\alpha_{\text{XA}}\) and \(\alpha_{\text{XB}}\), and, in addition, \(\alpha_{\text{AX}}=\alpha_{\text{AB}}\). Test A formula is: Maximum ( \(\alpha_{\text{AX}}-\alpha_{\text{AB}}\), \(\mid\alpha_{\text{XP}}-\alpha_{\text{XA}}\pm 90^{\circ}\), \(\mid\alpha_{\text{XP}}-\alpha_{\text{XB}}\pm 90^{\circ}\) ). To perform test B, we calculate the deviation distance \(\mathcal{X}^{\prime}\mathcal{X}^{\prime\prime}\), plus a second deviation distance PP\". If an azimuth \(\alpha_{\mathcal{X}^{\prime}\mathcal{A}}\pm 90^{\circ}\) is applied from the point \(\mathcal{X}^{\prime}\) plus a distance X\({}^{\prime}\)P (the distance X\({}^{\prime}\)X\" is close to zero), we will obtain a point P\" that must coincide with the point P. If the distance PP\" is zero, it is guaranteed that the perpendicular to the geodesic through the point X crosses point P. Test B formula is: Maximum (X\({}^{\prime}\)X\", PP\"), Figure 4. Table 5 shows the coordinates of the three examples used to test the algorithm whereas the column deviation of Table 6 shows the result of both tests. Figure 4: Distance deviations (X\({}^{\prime}\)X” and PP”). The largest difference of test B obtained for the 3 cases is 0.0041 \(\upmu\)m. The computation coordinates of X are exact up to the ninth decimal place of arc seconds units, which represents a maximum of 0.03 \(\upmu\)m. The minimum distance obtained can be correctly represented with up to the eighth decimal place (meters). We run these tests with Maxima, source code in tests/maxima_tests_minimumMDistance.mac available at [25]. Regarding to the running time, the operation E is approximately twice as fast as operation D, obtaining 40,000 times per second in cases 2 and 3 (four iterations to converge) and 60,000 times per second in case 1 (three iterations). Table 7 shows the minimum distance differences obtained between the software products and the results from Table 6.  
We can see that ArcGIS is the only studied software with deviations of 1 cm or less, although the distance PP\" (test B) happens to lie up to several meters off (0.05 m for Case 1, 2.5 m for Case 2 and 4.2 m for Case 3), which means the point X on the geodesic is indeed not well calculated. Unlike operation D, Oracle and Google implement different algorithms. The deviations in cases 2 and 3 reach up to 5000 m.  
Scheme 11 shows some additional special cases: polar, transpolar, 180\({}^{\circ}\) long geodesics, etc.