PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geography_azimuth()

Datum geography_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 1006 of file geography_measurement.c.

1007 {
1008  LWGEOM *lwgeom1 = NULL;
1009  LWGEOM *lwgeom2 = NULL;
1010  GSERIALIZED *g1 = NULL;
1011  GSERIALIZED *g2 = NULL;
1012  double azimuth;
1013  SPHEROID s;
1014  uint32_t type1, type2;
1015 
1016  /* Get our geometry object loaded into memory. */
1017  g1 = PG_GETARG_GSERIALIZED_P(0);
1018  g2 = PG_GETARG_GSERIALIZED_P(1);
1019 
1020  /* Only return for points. */
1021  type1 = gserialized_get_type(g1);
1022  type2 = gserialized_get_type(g2);
1023  if ( type1 != POINTTYPE || type2 != POINTTYPE )
1024  {
1025  elog(ERROR, "ST_Azimuth(geography, geography) is only valid for point inputs");
1026  PG_RETURN_NULL();
1027  }
1028 
1029  lwgeom1 = lwgeom_from_gserialized(g1);
1030  lwgeom2 = lwgeom_from_gserialized(g2);
1031 
1032  /* EMPTY things cannot be used */
1033  if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1034  {
1035  lwgeom_free(lwgeom1);
1036  lwgeom_free(lwgeom2);
1037  elog(ERROR, "ST_Azimuth(geography, geography) cannot work with empty points");
1038  PG_RETURN_NULL();
1039  }
1040 
1041  /* Initialize spheroid */
1042  spheroid_init_from_srid(fcinfo, gserialized_get_srid(g1), &s);
1043 
1044  /* Calculate the direction */
1045  azimuth = lwgeom_azumith_spheroid(lwgeom_as_lwpoint(lwgeom1), lwgeom_as_lwpoint(lwgeom2), &s);
1046 
1047  /* Clean up */
1048  lwgeom_free(lwgeom1);
1049  lwgeom_free(lwgeom2);
1050 
1051  PG_FREE_IF_COPY(g1, 0);
1052  PG_FREE_IF_COPY(g2, 1);
1053 
1054  /* Return NULL for unknown (same point) azimuth */
1055  if( isnan(azimuth) )
1056  {
1057  PG_RETURN_NULL();
1058  }
1059 
1060  PG_RETURN_FLOAT8(azimuth);
1061 }
char * s
Definition: cu_in_wkt.c:23
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
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:2156
unsigned int uint32_t
Definition: uthash.h:78

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: