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

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

2328 {
2329  GSERIALIZED *geom;
2330  LWPOINT *lwpoint;
2331  POINT2D p1, p2;
2332  double result;
2333  int srid;
2334 
2335  /* Extract first point */
2336  geom = PG_GETARG_GSERIALIZED_P(0);
2337  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2338  if ( ! lwpoint )
2339  {
2340  PG_FREE_IF_COPY(geom, 0);
2341  lwpgerror("Argument must be POINT geometries");
2342  PG_RETURN_NULL();
2343  }
2344  srid = lwpoint->srid;
2345  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2346  {
2347  PG_FREE_IF_COPY(geom, 0);
2348  lwpgerror("Error extracting point");
2349  PG_RETURN_NULL();
2350  }
2351  lwpoint_free(lwpoint);
2352  PG_FREE_IF_COPY(geom, 0);
2353 
2354  /* Extract second point */
2355  geom = PG_GETARG_GSERIALIZED_P(1);
2356  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2357  if ( ! lwpoint )
2358  {
2359  PG_FREE_IF_COPY(geom, 1);
2360  lwpgerror("Argument must be POINT geometries");
2361  PG_RETURN_NULL();
2362  }
2363  if ( lwpoint->srid != srid )
2364  {
2365  PG_FREE_IF_COPY(geom, 1);
2366  lwpgerror("Operation on mixed SRID geometries");
2367  PG_RETURN_NULL();
2368  }
2369  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2370  {
2371  PG_FREE_IF_COPY(geom, 1);
2372  lwpgerror("Error extracting point");
2373  PG_RETURN_NULL();
2374  }
2375  lwpoint_free(lwpoint);
2376  PG_FREE_IF_COPY(geom, 1);
2377 
2378  /* Standard return value for equality case */
2379  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2380  {
2381  PG_RETURN_NULL();
2382  }
2383 
2384  /* Compute azimuth */
2385  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2386  {
2387  PG_RETURN_NULL();
2388  }
2389 
2390  PG_RETURN_FLOAT8(result);
2391 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:182
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:395
double x
Definition: liblwgeom.h:312
LWGEOM * geom
double y
Definition: liblwgeom.h:312
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:448
int32_t srid
Definition: liblwgeom.h:394
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2411

Here is the call graph for this function: