PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_project_geography()

Datum geography_project_geography ( PG_FUNCTION_ARGS  )

Definition at line 1035 of file geography_measurement.c.

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