#include "postgres.h"#include <math.h>#include "utils/geo_decls.h"
Go to the source code of this file.
Defines | |
| #define | M_PI 3.14159265358979323846 |
Functions | |
| static double | degtorad (double degrees) |
| static double | geo_distance_internal (Point *pt1, Point *pt2) |
| double * | geo_distance (Point *pt1, Point *pt2) |
Variables | |
| PG_MODULE_MAGIC | |
| static const double | EARTH_RADIUS = 3958.747716 |
| static const double | TWO_PI = 2.0 * M_PI |
| #define M_PI 3.14159265358979323846 |
Definition at line 10 of file earthdistance.c.
Referenced by geo_distance_internal().
| static double degtorad | ( | double | degrees | ) | [static] |
Definition at line 31 of file earthdistance.c.
References TWO_PI.
Referenced by geo_distance_internal().
Definition at line 121 of file earthdistance.c.
References geo_distance_internal(), and palloc().
{
double *resultp = palloc(sizeof(double));
*resultp = geo_distance_internal(pt1, pt2);
return resultp;
}
Definition at line 50 of file earthdistance.c.
References degtorad(), EARTH_RADIUS, M_PI, TWO_PI, Point::x, and Point::y.
Referenced by geo_distance().
{
double long1,
lat1,
long2,
lat2;
double longdiff;
double sino;
/* convert degrees to radians */
long1 = degtorad(pt1->x);
lat1 = degtorad(pt1->y);
long2 = degtorad(pt2->x);
lat2 = degtorad(pt2->y);
/* compute difference in longitudes - want < 180 degrees */
longdiff = fabs(long1 - long2);
if (longdiff > M_PI)
longdiff = TWO_PI - longdiff;
sino = sqrt(sin(fabs(lat1 - lat2) / 2.) * sin(fabs(lat1 - lat2) / 2.) +
cos(lat1) * cos(lat2) * sin(longdiff / 2.) * sin(longdiff / 2.));
if (sino > 1.)
sino = 1.;
return 2. * EARTH_RADIUS * asin(sino);
}
const double EARTH_RADIUS = 3958.747716 [static] |
Definition at line 17 of file earthdistance.c.
Referenced by geo_distance_internal().
Definition at line 14 of file earthdistance.c.
const double TWO_PI = 2.0 * M_PI [static] |
Definition at line 18 of file earthdistance.c.
Referenced by degtorad(), and geo_distance_internal().
1.7.1