PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2355 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_asEWKT().

2356 {
2357  GSERIALIZED *geom;
2358  LWPOINT *lwpoint;
2359  POINT2D p1, p2;
2360  double result;
2361  int srid;
2362 
2363  /* Extract first point */
2364  geom = PG_GETARG_GSERIALIZED_P(0);
2365  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2366  if ( ! lwpoint )
2367  {
2368  PG_FREE_IF_COPY(geom, 0);
2369  lwpgerror("Argument must be POINT geometries");
2370  PG_RETURN_NULL();
2371  }
2372  srid = lwpoint->srid;
2373  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2374  {
2375  PG_FREE_IF_COPY(geom, 0);
2376  lwpgerror("Error extracting point");
2377  PG_RETURN_NULL();
2378  }
2379  lwpoint_free(lwpoint);
2380  PG_FREE_IF_COPY(geom, 0);
2381 
2382  /* Extract second point */
2383  geom = PG_GETARG_GSERIALIZED_P(1);
2384  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2385  if ( ! lwpoint )
2386  {
2387  PG_FREE_IF_COPY(geom, 1);
2388  lwpgerror("Argument must be POINT geometries");
2389  PG_RETURN_NULL();
2390  }
2391  if ( lwpoint->srid != srid )
2392  {
2393  PG_FREE_IF_COPY(geom, 1);
2394  lwpgerror("Operation on mixed SRID geometries");
2395  PG_RETURN_NULL();
2396  }
2397  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2398  {
2399  PG_FREE_IF_COPY(geom, 1);
2400  lwpgerror("Error extracting point");
2401  PG_RETURN_NULL();
2402  }
2403  lwpoint_free(lwpoint);
2404  PG_FREE_IF_COPY(geom, 1);
2405 
2406  /* Standard return value for equality case */
2407  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2408  {
2409  PG_RETURN_NULL();
2410  }
2411 
2412  /* Compute azimuth */
2413  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2414  {
2415  PG_RETURN_NULL();
2416  }
2417 
2418  PG_RETURN_FLOAT8(result);
2419 }
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:129
POINTARRAY * point
Definition: liblwgeom.h:411
double x
Definition: liblwgeom.h:328
LWGEOM * geom
double y
Definition: liblwgeom.h:328
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:347
int32_t srid
Definition: liblwgeom.h:410
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2427
Here is the call graph for this function:
Here is the caller graph for this function: