# Accurate Algorithms for Spatial Operations on the Spheroid in a Spatial Database Management System
###### Abstract
Any geometric calculation using map projections must take into account that the particular type of projection and defining parameters [12] entail several limitations, chiefly:  
* a limited, non-universal, area of use;
* scale distortions, leading to different scale factors for different points in the area;
* angle distortions: even for the case of conformal projections, that is those preserving angles, the angle preservation at every point A is fulfilled between the tangents to the original geodetic lines on the ellipsoid at A and the tangents to the projected lines at A, which are not straight lines on the map but curved lines. If the straight segments, or chords, joining line ends are considered, the original angle is not preserved;
* area distortions: even for the case of equal-area projections, the area of figures enclosed by geodetic lines is not preserved as the area in the map enclosed by the straight segments connecting the extreme points. Hence, there is no projection that helps to accurately solve the geometric calculations for a large area. In recent years, the most powerful spatial analysis software solutions (Oracle, Google Earth Engine, PostgreSQL + PostGIS, etc.) have implemented some geometric calculations directly on the spheroid. In this way, these software can offer high accuracy over large areas (countries or even continents). Operations A and B above can be accurately calculated on the ellipsoid. They are known as the direct and inverse problems of geodesy and allow the calculation of distances and angles (azimuths) between two points on the ellipsoid. The calculation involves numerical integrations and an iterative approach. There is a large number of algorithms both efficient and accurate, even considering long distances, which provide an accuracy close to the machine precision, such as GeographicLib [13; 14], since the idea that the software tools developed should provide the user with the highest possible accuracy (close to machine precision) has become more and more prevalent in recent times. For more than a decade now, the geospatial analysis software products (GIS Desktop, Spatial Databases, and computational geometric libraries) have incorporated quite good implementations on the ellipsoid of operations A and B with high accuracy (e.g., the methods ST_Azimuth, ST_Project and ST_Distance in PostGIS [15]). More recently even the operation C has been addressed [16; 17]. The problem appears with the operations D and E. Currently very few products implement these operations on the ellipsoid and the calculations are not performed precisely but roughly (the errors depending on the distance and the software used can easily reach meters). We will demonstrate this in the next section. To do so, an algorithm introduced by the authors in a previous article [18] for solving operation E, has needed to be improved. The main goals of this research are:  
* To test the current geospatial solutions and check that they give approximate results when talking about ellipsoid calculations. * To present two new algorithms to solve operations D and E accurately in a spatial database (PL/SQL) and with Java as a library, so that anyone can easily use it. * To verify the results of the proposed algorithms (within the desired accuracy of 100 nm). * To encourage the spatial analysis software vendors to implement the algorithms on the ellipsoid so that accurate results can be achieved.