PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2377 of file lwgeom_functions_basic.c.

2378 {
2379  GSERIALIZED *geom;
2380  LWPOINT *lwpoint;
2381  POINT2D p1, p2;
2382  double result;
2383  int srid;
2384 
2385  /* Extract first point */
2386  geom = PG_GETARG_GSERIALIZED_P(0);
2387  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2388  if ( ! lwpoint )
2389  {
2390  PG_FREE_IF_COPY(geom, 0);
2391  lwpgerror("Argument must be POINT geometries");
2392  PG_RETURN_NULL();
2393  }
2394  srid = lwpoint->srid;
2395  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2396  {
2397  PG_FREE_IF_COPY(geom, 0);
2398  lwpgerror("Error extracting point");
2399  PG_RETURN_NULL();
2400  }
2401  lwpoint_free(lwpoint);
2402  PG_FREE_IF_COPY(geom, 0);
2403 
2404  /* Extract second point */
2405  geom = PG_GETARG_GSERIALIZED_P(1);
2406  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2407  if ( ! lwpoint )
2408  {
2409  PG_FREE_IF_COPY(geom, 1);
2410  lwpgerror("Argument must be POINT geometries");
2411  PG_RETURN_NULL();
2412  }
2413  if ( lwpoint->srid != srid )
2414  {
2415  PG_FREE_IF_COPY(geom, 1);
2416  lwpgerror("Operation on mixed SRID geometries");
2417  PG_RETURN_NULL();
2418  }
2419  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2420  {
2421  PG_FREE_IF_COPY(geom, 1);
2422  lwpgerror("Error extracting point");
2423  PG_RETURN_NULL();
2424  }
2425  lwpoint_free(lwpoint);
2426  PG_FREE_IF_COPY(geom, 1);
2427 
2428  /* Standard return value for equality case */
2429  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2430  {
2431  PG_RETURN_NULL();
2432  }
2433 
2434  /* Compute azimuth */
2435  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2436  {
2437  PG_RETURN_NULL();
2438  }
2439 
2440  PG_RETURN_FLOAT8(result);
2441 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2417
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:348
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
POINTARRAY * point
Definition: liblwgeom.h:414
int32_t srid
Definition: liblwgeom.h:413
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References azimuth_pt_pt(), getPoint2d_p(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwpoint_free(), LWPOINT::point, LWPOINT::srid, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: