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

◆ geography_azimuth()

Datum geography_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 1104 of file geography_measurement.c.

1105{
1106 GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
1107 GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
1108 LWGEOM *lwgeom1 = NULL;
1109 LWGEOM *lwgeom2 = NULL;
1110 double azimuth;
1111 SPHEROID s;
1112 uint32_t type1, type2;
1113
1114 /* Only return for points. */
1115 type1 = gserialized_get_type(g1);
1116 type2 = gserialized_get_type(g2);
1117 if ( type1 != POINTTYPE || type2 != POINTTYPE )
1118 {
1119 elog(ERROR, "ST_Azimuth(geography, geography) is only valid for point inputs");
1120 PG_RETURN_NULL();
1121 }
1122
1123 lwgeom1 = lwgeom_from_gserialized(g1);
1124 lwgeom2 = lwgeom_from_gserialized(g2);
1125
1126 /* EMPTY things cannot be used */
1127 if ( lwgeom_is_empty(lwgeom1) || lwgeom_is_empty(lwgeom2) )
1128 {
1129 lwgeom_free(lwgeom1);
1130 lwgeom_free(lwgeom2);
1131 elog(ERROR, "ST_Azimuth(geography, geography) cannot work with empty points");
1132 PG_RETURN_NULL();
1133 }
1134
1135 /* Initialize spheroid */
1136 spheroid_init_from_srid(gserialized_get_srid(g1), &s);
1137
1138 /* Calculate the direction */
1139 azimuth = lwgeom_azumith_spheroid(lwgeom_as_lwpoint(lwgeom1), lwgeom_as_lwpoint(lwgeom2), &s);
1140
1141 /* Clean up */
1142 lwgeom_free(lwgeom1);
1143 lwgeom_free(lwgeom2);
1144
1145 PG_FREE_IF_COPY(g1, 0);
1146 PG_FREE_IF_COPY(g2, 1);
1147
1148 /* Return NULL for unknown (same point) azimuth */
1149 if( !isfinite(azimuth) )
1150 {
1151 PG_RETURN_NULL();
1152 }
1153
1154 PG_RETURN_FLOAT8(azimuth);
1155}
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)...
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,...
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#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.
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

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: