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

Definition at line 2392 of file lwgeom_functions_basic.c.

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

2393 {
2394  GSERIALIZED *geom;
2395  LWPOINT *lwpoint;
2396  POINT2D p1, p2;
2397  double result;
2398  int srid;
2399 
2400  /* Extract first point */
2401  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2402  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2403  if ( ! lwpoint )
2404  {
2405  PG_FREE_IF_COPY(geom, 0);
2406  lwerror("Argument must be POINT geometries");
2407  PG_RETURN_NULL();
2408  }
2409  srid = lwpoint->srid;
2410  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2411  {
2412  PG_FREE_IF_COPY(geom, 0);
2413  lwerror("Error extracting point");
2414  PG_RETURN_NULL();
2415  }
2416  lwpoint_free(lwpoint);
2417  PG_FREE_IF_COPY(geom, 0);
2418 
2419  /* Extract second point */
2420  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
2421  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2422  if ( ! lwpoint )
2423  {
2424  PG_FREE_IF_COPY(geom, 1);
2425  lwerror("Argument must be POINT geometries");
2426  PG_RETURN_NULL();
2427  }
2428  if ( lwpoint->srid != srid )
2429  {
2430  PG_FREE_IF_COPY(geom, 1);
2431  lwerror("Operation on mixed SRID geometries");
2432  PG_RETURN_NULL();
2433  }
2434  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2435  {
2436  PG_FREE_IF_COPY(geom, 1);
2437  lwerror("Error extracting point");
2438  PG_RETURN_NULL();
2439  }
2440  lwpoint_free(lwpoint);
2441  PG_FREE_IF_COPY(geom, 1);
2442 
2443  /* Standard return value for equality case */
2444  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2445  {
2446  PG_RETURN_NULL();
2447  }
2448 
2449  /* Compute azimuth */
2450  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2451  {
2452  PG_RETURN_NULL();
2453  }
2454 
2455  PG_RETURN_FLOAT8(result);
2456 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:180
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
POINTARRAY * point
Definition: liblwgeom.h:367
char ** result
Definition: liblwgeom.h:218
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
double x
Definition: liblwgeom.h:284
LWGEOM * geom
double y
Definition: liblwgeom.h:284
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
int32_t srid
Definition: liblwgeom.h:366
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2233

Here is the call graph for this function: