PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2394 of file lwgeom_functions_basic.c.

2395 {
2396  GSERIALIZED *geom;
2397  LWPOINT *lwpoint;
2398  POINT2D p1, p2;
2399  double result;
2400  int32_t srid;
2401 
2402  /* Extract first point */
2403  geom = PG_GETARG_GSERIALIZED_P(0);
2404  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2405  if (!lwpoint)
2406  {
2407  PG_FREE_IF_COPY(geom, 0);
2408  lwpgerror("Argument must be POINT geometries");
2409  PG_RETURN_NULL();
2410  }
2411  srid = lwpoint->srid;
2412  if (!getPoint2d_p(lwpoint->point, 0, &p1))
2413  {
2414  PG_FREE_IF_COPY(geom, 0);
2415  lwpgerror("Error extracting point");
2416  PG_RETURN_NULL();
2417  }
2418  lwpoint_free(lwpoint);
2419  PG_FREE_IF_COPY(geom, 0);
2420 
2421  /* Extract second point */
2422  geom = PG_GETARG_GSERIALIZED_P(1);
2423  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2424  if (!lwpoint)
2425  {
2426  PG_FREE_IF_COPY(geom, 1);
2427  lwpgerror("Argument must be POINT geometries");
2428  PG_RETURN_NULL();
2429  }
2430  if (lwpoint->srid != srid)
2431  {
2432  PG_FREE_IF_COPY(geom, 1);
2433  lwpgerror("Operation on mixed SRID geometries");
2434  PG_RETURN_NULL();
2435  }
2436  if (!getPoint2d_p(lwpoint->point, 0, &p2))
2437  {
2438  PG_FREE_IF_COPY(geom, 1);
2439  lwpgerror("Error extracting point");
2440  PG_RETURN_NULL();
2441  }
2442  lwpoint_free(lwpoint);
2443  PG_FREE_IF_COPY(geom, 1);
2444 
2445  /* Standard return value for equality case */
2446  if ((p1.x == p2.x) && (p1.y == p2.y))
2447  {
2448  PG_RETURN_NULL();
2449  }
2450 
2451  /* Compute azimuth */
2452  if (!azimuth_pt_pt(&p1, &p2, &result))
2453  {
2454  PG_RETURN_NULL();
2455  }
2456 
2457  PG_RETURN_FLOAT8(result);
2458 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret)
Compute the azimuth of segment AB in radians.
Definition: measures.c:2461
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:349
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:121
POINTARRAY * point
Definition: liblwgeom.h:457
int32_t srid
Definition: liblwgeom.h:458
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376

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

Here is the call graph for this function: