Postgis St_Project calculation method

I`m trying to implement postgis St_Project analog on C++ (calculation method is taken from here - http://www.movable-type.co.uk/scripts/latlong.html):

``````#include <cmath>

struct GeoPoint
{
double longitude;
double latitude;
};

static const double EARTH_RADIUS = 6378137.0;
static double degToRad(double deg) { return (deg * M_PI) / 180.0; }
static GeoPoint projectGeoPoint(const GeoPoint& gpt, double distance, double bearing)
{
double angular = distance / EARTH_RADIUS;

double lat = std::asin(std::sin(latRad) * std::cos(angular) +

}

int main()
{
GeoPoint gp = {0, 0};
GeoPoint gp_new = MapsMath::projectGeoPoint(gp, 100000, 45);
std::cout.precision(14);
std::cout << "longitude_new - " << gp_new.longitude << " latitude_new - " << gp_new.latitude << std::endl;
}
``````

Result is: longitude_new - 0.63523085373227 latitude_new - 0.6351918164606

I expect that postgis St_Project function will give exatcly same result:

``````select st_astext(st_project(st_makepoint(0,0,4326), 100000, radians(45)))
``````

However, this query issues different result: longitude_new - 0.635231029125537 latitude_new - 0.639472334729198

What I`m doing wrong and how achieve exactly same result akin postgis St_Project?

• ST_Project seems to take geography as input postgis.net/docs/ST_Project.html so I believe that it knows that Earth is somewhat flat while your formula probably does not because it has only one constant postgis.net/docs/ST_Project.html. The difference is in sixth decimal place and thus about ten centimeters which is not huge for 100 kilometer distance if you have some practical implementation in your mind. Sep 1, 2016 at 13:48
• It could also be the difference between a great circle and a geodesic. Sep 1, 2016 at 19:06
• The second paragraph on the linked page basically says it all. The calculations do not take into account that the world is not a perfect sphere, but a wee bit flattened (an oblate ellipsoid). The other page from the same site may provide a better method Sep 4, 2016 at 21:51
• Digging a little deeper it appears that PostGIS uses this library Sep 4, 2016 at 22:03