PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2366 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_asEWKT().

2367 {
2368  GSERIALIZED *geom;
2369  LWPOINT *lwpoint;
2370  POINT2D p1, p2;
2371  double result;
2372  int srid;
2373 
2374  /* Extract first point */
2375  geom = PG_GETARG_GSERIALIZED_P(0);
2376  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2377  if ( ! lwpoint )
2378  {
2379  PG_FREE_IF_COPY(geom, 0);
2380  lwpgerror("Argument must be POINT geometries");
2381  PG_RETURN_NULL();
2382  }
2383  srid = lwpoint->srid;
2384  if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
2385  {
2386  PG_FREE_IF_COPY(geom, 0);
2387  lwpgerror("Error extracting point");
2388  PG_RETURN_NULL();
2389  }
2390  lwpoint_free(lwpoint);
2391  PG_FREE_IF_COPY(geom, 0);
2392 
2393  /* Extract second point */
2394  geom = PG_GETARG_GSERIALIZED_P(1);
2395  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2396  if ( ! lwpoint )
2397  {
2398  PG_FREE_IF_COPY(geom, 1);
2399  lwpgerror("Argument must be POINT geometries");
2400  PG_RETURN_NULL();
2401  }
2402  if ( lwpoint->srid != srid )
2403  {
2404  PG_FREE_IF_COPY(geom, 1);
2405  lwpgerror("Operation on mixed SRID geometries");
2406  PG_RETURN_NULL();
2407  }
2408  if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
2409  {
2410  PG_FREE_IF_COPY(geom, 1);
2411  lwpgerror("Error extracting point");
2412  PG_RETURN_NULL();
2413  }
2414  lwpoint_free(lwpoint);
2415  PG_FREE_IF_COPY(geom, 1);
2416 
2417  /* Standard return value for equality case */
2418  if ( (p1.x == p2.x) && (p1.y == p2.y) )
2419  {
2420  PG_RETURN_NULL();
2421  }
2422 
2423  /* Compute azimuth */
2424  if ( ! azimuth_pt_pt(&p1, &p2, &result) )
2425  {
2426  PG_RETURN_NULL();
2427  }
2428 
2429  PG_RETURN_FLOAT8(result);
2430 }
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:161
POINTARRAY * point
Definition: liblwgeom.h:413
double x
Definition: liblwgeom.h:330
LWGEOM * geom
double y
Definition: liblwgeom.h:330
int32_t srid
Definition: liblwgeom.h:412
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:2415
Here is the call graph for this function:
Here is the caller graph for this function: