PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2386 of file lwgeom_functions_basic.c.

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

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

Here is the call graph for this function: