PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2399 of file lwgeom_functions_basic.c.

2400 {
2401  GSERIALIZED *geom;
2402  LWPOINT *lwpoint;
2403  POINT2D p1, p2;
2404  double result;
2405  int32_t srid;
2406 
2407  /* Extract first point */
2408  geom = PG_GETARG_GSERIALIZED_P(0);
2409  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2410  if (!lwpoint)
2411  {
2412  PG_FREE_IF_COPY(geom, 0);
2413  lwpgerror("Argument must be POINT geometries");
2414  PG_RETURN_NULL();
2415  }
2416  srid = lwpoint->srid;
2417  if (!getPoint2d_p(lwpoint->point, 0, &p1))
2418  {
2419  PG_FREE_IF_COPY(geom, 0);
2420  lwpgerror("Error extracting point");
2421  PG_RETURN_NULL();
2422  }
2423  lwpoint_free(lwpoint);
2424  PG_FREE_IF_COPY(geom, 0);
2425 
2426  /* Extract second point */
2427  geom = PG_GETARG_GSERIALIZED_P(1);
2428  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2429  if (!lwpoint)
2430  {
2431  PG_FREE_IF_COPY(geom, 1);
2432  lwpgerror("Argument must be POINT geometries");
2433  PG_RETURN_NULL();
2434  }
2435  if (lwpoint->srid != srid)
2436  {
2437  PG_FREE_IF_COPY(geom, 1);
2438  lwpgerror("Operation on mixed SRID geometries");
2439  PG_RETURN_NULL();
2440  }
2441  if (!getPoint2d_p(lwpoint->point, 0, &p2))
2442  {
2443  PG_FREE_IF_COPY(geom, 1);
2444  lwpgerror("Error extracting point");
2445  PG_RETURN_NULL();
2446  }
2447  lwpoint_free(lwpoint);
2448  PG_FREE_IF_COPY(geom, 1);
2449 
2450  /* Standard return value for equality case */
2451  if ((p1.x == p2.x) && (p1.y == p2.y))
2452  {
2453  PG_RETURN_NULL();
2454  }
2455 
2456  /* Compute azimuth */
2457  if (!azimuth_pt_pt(&p1, &p2, &result))
2458  {
2459  PG_RETURN_NULL();
2460  }
2461 
2462  PG_RETURN_FLOAT8(result);
2463 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:343
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
POINTARRAY * point
Definition: liblwgeom.h:485
int32_t srid
Definition: liblwgeom.h:486
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404

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

Here is the call graph for this function: