Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
dc192a5d
Commit
dc192a5d
authored
Apr 20, 2008
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert earthdistance's only C function to v1 call convention,
to future-proof it against pass-by-value float8.
parent
7c81d795
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
contrib/earthdistance/earthdistance.c
contrib/earthdistance/earthdistance.c
+15
-12
No files found.
contrib/earthdistance/earthdistance.c
View file @
dc192a5d
/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.1
3 2006/10/19 20:08:03
tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.1
4 2008/04/20 01:05:52
tgl Exp $ */
#include "postgres.h"
#include <math.h>
#include "utils/geo_decls.h"
/* for Pt */
#include "utils/geo_decls.h"
/* for P
oin
t */
#ifndef M_PI
#define M_PI 3.14159265358979323846
...
...
@@ -14,10 +14,12 @@
PG_MODULE_MAGIC
;
/* Earth's radius is in statute miles. */
const
double
EARTH_RADIUS
=
3958
.
747716
;
const
double
TWO_PI
=
2
.
0
*
M_PI
;
static
const
double
EARTH_RADIUS
=
3958
.
747716
;
static
const
double
TWO_PI
=
2
.
0
*
M_PI
;
double
*
geo_distance
(
Point
*
pt1
,
Point
*
pt2
);
PG_FUNCTION_INFO_V1
(
geo_distance
);
Datum
geo_distance
(
PG_FUNCTION_ARGS
);
/******************************************************
...
...
@@ -45,21 +47,22 @@ degtorad(double degrees)
* x-coordinate is longitude in degrees west of Greenwich
* y-coordinate is latitude in degrees above equator
*
* returns:
double
* returns:
float8
* distance between the points in miles on earth's surface
******************************************************/
double
*
geo_distance
(
P
oint
*
pt1
,
Point
*
pt2
)
Datum
geo_distance
(
P
G_FUNCTION_ARGS
)
{
Point
*
pt1
=
PG_GETARG_POINT_P
(
0
);
Point
*
pt2
=
PG_GETARG_POINT_P
(
1
);
float8
result
;
double
long1
,
lat1
,
long2
,
lat2
;
double
longdiff
;
double
sino
;
double
*
resultp
=
palloc
(
sizeof
(
double
));
/* convert degrees to radians */
...
...
@@ -78,7 +81,7 @@ geo_distance(Point *pt1, Point *pt2)
cos
(
lat1
)
*
cos
(
lat2
)
*
sin
(
longdiff
/
2
.)
*
sin
(
longdiff
/
2
.));
if
(
sino
>
1
.)
sino
=
1
.;
*
resultp
=
2
.
*
EARTH_RADIUS
*
asin
(
sino
);
result
=
2
.
*
EARTH_RADIUS
*
asin
(
sino
);
return
resultp
;
PG_RETURN_FLOAT8
(
result
)
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment