PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ geography_project_geography()

Datum geography_project_geography ( PG_FUNCTION_ARGS  )

Definition at line 1032 of file geography_measurement.c.

1033{
1034 LWGEOM *lwgeom1, *lwgeom2;
1035 LWPOINT *lwp1, *lwp2, *lwp3;
1036 GSERIALIZED *g1, *g2, *g3;
1037 double distance;
1038 SPHEROID s;
1039
1040 /* Get our geometry object loaded into memory. */
1041 g1 = PG_GETARG_GSERIALIZED_P(0);
1042 g2 = PG_GETARG_GSERIALIZED_P(1);
1043
1044 if ( gserialized_get_type(g1) != POINTTYPE ||
1046 {
1047 elog(ERROR, "ST_Project(geography) is only valid for point inputs");
1048 PG_RETURN_NULL();
1049 }
1050
1051 distance = PG_GETARG_FLOAT8(2); /* Distance in meters */
1052
1053 /* Handle the zero distance case */
1054 if ( FP_EQUALS(distance, 0.0) )
1055 {
1056 PG_RETURN_POINTER(g2);
1057 }
1058
1059 lwgeom1 = lwgeom_from_gserialized(g1);
1060 lwgeom2 = lwgeom_from_gserialized(g2);
1061
1062 /* EMPTY things cannot be projected from */
1063 if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1064 {
1065 lwgeom_free(lwgeom1);
1066 lwgeom_free(lwgeom2);
1067 elog(ERROR, "ST_Project(geography) cannot project from an empty point");
1068 PG_RETURN_NULL();
1069 }
1070
1071 /* Initialize spheroid */
1072 spheroid_init_from_srid(lwgeom_get_srid(lwgeom1), &s);
1073
1074 /* Calculate the length */
1075 lwp1 = lwgeom_as_lwpoint(lwgeom1);
1076 lwp2 = lwgeom_as_lwpoint(lwgeom2);
1077 lwp3 = lwgeom_project_spheroid_lwpoint(lwp1, lwp2, &s, distance);
1078
1079 /* Something went wrong... */
1080 if ( lwp3 == NULL )
1081 {
1082 elog(ERROR, "lwgeom_project_spheroid_lwpoint returned null");
1083 PG_RETURN_NULL();
1084 }
1085
1086 /* Clean up, but not all the way to the point arrays */
1087 lwgeom_free(lwgeom1);
1088 lwgeom_free(lwgeom2);
1089 g3 = geography_serialize(lwpoint_as_lwgeom(lwp3));
1090 lwpoint_free(lwp3);
1091
1092 PG_FREE_IF_COPY(g1, 0);
1093 PG_FREE_IF_COPY(g2, 1);
1094 PG_RETURN_POINTER(g3);
1095}
char * s
Definition cu_in_wkt.c:23
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition lwgeom.c:955
void lwpoint_free(LWPOINT *pt)
Definition lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWPOINT * lwgeom_project_spheroid_lwpoint(const LWPOINT *from, const LWPOINT *to, const SPHEROID *spheroid, double distance)
Calculate the location of a point on a spheroid, give a start point, end point and distance.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define FP_EQUALS(A, B)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition lwinline.h:127
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

References distance(), FP_EQUALS, gserialized_get_type(), lwgeom_as_lwpoint(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_get_srid(), lwgeom_is_empty(), lwgeom_project_spheroid_lwpoint(), lwpoint_as_lwgeom(), lwpoint_free(), POINTTYPE, and s.

Here is the call graph for this function: