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

Definition at line 2363 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.

2364 {
2365  GSERIALIZED *geom;
2366  LWPOINT *lwpoint;
2367  POINT2D p1, p2;
2368  double result;
2369  int srid;
2370 
2371  /* Extract first point */
2372  geom = PG_GETARG_GSERIALIZED_P(0);
2373  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2374  if ( ! lwpoint )
2375  {
2376  PG_FREE_IF_COPY(geom, 0);
2377  lwpgerror("Argument must be POINT geometries");
2378  PG_RETURN_NULL();
2379  }
2380  srid = lwpoint->srid;
2381  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2382  {
2383  PG_FREE_IF_COPY(geom, 0);
2384  lwpgerror("Error extracting point");
2385  PG_RETURN_NULL();
2386  }
2387  lwpoint_free(lwpoint);
2388  PG_FREE_IF_COPY(geom, 0);
2389 
2390  /* Extract second point */
2391  geom = PG_GETARG_GSERIALIZED_P(1);
2392  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2393  if ( ! lwpoint )
2394  {
2395  PG_FREE_IF_COPY(geom, 1);
2396  lwpgerror("Argument must be POINT geometries");
2397  PG_RETURN_NULL();
2398  }
2399  if ( lwpoint->srid != srid )
2400  {
2401  PG_FREE_IF_COPY(geom, 1);
2402  lwpgerror("Operation on mixed SRID geometries");
2403  PG_RETURN_NULL();
2404  }
2405  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2406  {
2407  PG_FREE_IF_COPY(geom, 1);
2408  lwpgerror("Error extracting point");
2409  PG_RETURN_NULL();
2410  }
2411  lwpoint_free(lwpoint);
2412  PG_FREE_IF_COPY(geom, 1);
2413 
2414  /* Standard return value for equality case */
2415  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2416  {
2417  PG_RETURN_NULL();
2418  }
2419 
2420  /* Compute azimuth */
2421  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2422  {
2423  PG_RETURN_NULL();
2424  }
2425 
2426  PG_RETURN_FLOAT8(result);
2427 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
POINTARRAY * point
Definition: liblwgeom.h:410
double x
Definition: liblwgeom.h:327
LWGEOM * geom
double y
Definition: liblwgeom.h:327
int32_t srid
Definition: liblwgeom.h:409
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:338
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2422

Here is the call graph for this function: