PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ geography_azimuth()

Datum geography_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 1107 of file geography_measurement.c.

1108 {
1109  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
1110  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
1111  LWGEOM *lwgeom1 = NULL;
1112  LWGEOM *lwgeom2 = NULL;
1113  double azimuth;
1114  SPHEROID s;
1115  uint32_t type1, type2;
1116 
1117  /* Only return for points. */
1118  type1 = gserialized_get_type(g1);
1119  type2 = gserialized_get_type(g2);
1120  if ( type1 != POINTTYPE || type2 != POINTTYPE )
1121  {
1122  elog(ERROR, "ST_Azimuth(geography, geography) is only valid for point inputs");
1123  PG_RETURN_NULL();
1124  }
1125 
1126  lwgeom1 = lwgeom_from_gserialized(g1);
1127  lwgeom2 = lwgeom_from_gserialized(g2);
1128 
1129  /* EMPTY things cannot be used */
1130  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1131  {
1132  lwgeom_free(lwgeom1);
1133  lwgeom_free(lwgeom2);
1134  elog(ERROR, "ST_Azimuth(geography, geography) cannot work with empty points");
1135  PG_RETURN_NULL();
1136  }
1137 
1138  /* Initialize spheroid */
1139  spheroid_init_from_srid(gserialized_get_srid(g1), &s);
1140 
1141  /* Calculate the direction */
1142  azimuth = lwgeom_azumith_spheroid(lwgeom_as_lwpoint(lwgeom1), lwgeom_as_lwpoint(lwgeom2), &s);
1143 
1144  /* Clean up */
1145  lwgeom_free(lwgeom1);
1146  lwgeom_free(lwgeom2);
1147 
1148  PG_FREE_IF_COPY(g1, 0);
1149  PG_FREE_IF_COPY(g2, 1);
1150 
1151  /* Return NULL for unknown (same point) azimuth */
1152  if( !isfinite(azimuth) )
1153  {
1154  PG_RETURN_NULL();
1155  }
1156 
1157  PG_RETURN_FLOAT8(azimuth);
1158 }
char * s
Definition: cu_in_wkt.c:23
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
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
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid)
Calculate the bearing between two points on a spheroid.
Definition: lwgeodetic.c:2170
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

References gserialized_get_srid(), gserialized_get_type(), lwgeom_as_lwpoint(), lwgeom_azumith_spheroid(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), POINTTYPE, and s.

Here is the call graph for this function: