PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2513 of file lwgeom_functions_basic.c.

2514 {
2515  GSERIALIZED *geom;
2516  LWPOINT *lwpoint;
2517  POINT2D p1, p2;
2518  double result;
2519  int32_t srid;
2520 
2521  /* Extract first point */
2522  geom = PG_GETARG_GSERIALIZED_P(0);
2523  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2524  if (!lwpoint)
2525  {
2526  PG_FREE_IF_COPY(geom, 0);
2527  lwpgerror("Argument must be POINT geometries");
2528  PG_RETURN_NULL();
2529  }
2530  srid = lwpoint->srid;
2531  if (!getPoint2d_p(lwpoint->point, 0, &p1))
2532  {
2533  PG_FREE_IF_COPY(geom, 0);
2534  lwpgerror("Error extracting point");
2535  PG_RETURN_NULL();
2536  }
2537  lwpoint_free(lwpoint);
2538  PG_FREE_IF_COPY(geom, 0);
2539 
2540  /* Extract second point */
2541  geom = PG_GETARG_GSERIALIZED_P(1);
2542  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2543  if (!lwpoint)
2544  {
2545  PG_FREE_IF_COPY(geom, 1);
2546  lwpgerror("Argument must be POINT geometries");
2547  PG_RETURN_NULL();
2548  }
2549  if (lwpoint->srid != srid)
2550  {
2551  PG_FREE_IF_COPY(geom, 1);
2552  lwpgerror("Operation on mixed SRID geometries");
2553  PG_RETURN_NULL();
2554  }
2555  if (!getPoint2d_p(lwpoint->point, 0, &p2))
2556  {
2557  PG_FREE_IF_COPY(geom, 1);
2558  lwpgerror("Error extracting point");
2559  PG_RETURN_NULL();
2560  }
2561  lwpoint_free(lwpoint);
2562  PG_FREE_IF_COPY(geom, 1);
2563 
2564  /* Standard return value for equality case */
2565  if ((p1.x == p2.x) && (p1.y == p2.y))
2566  {
2567  PG_RETURN_NULL();
2568  }
2569 
2570  /* Compute azimuth */
2571  if (!azimuth_pt_pt(&p1, &p2, &result))
2572  {
2573  PG_RETURN_NULL();
2574  }
2575 
2576  PG_RETURN_FLOAT8(result);
2577 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:2462
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:342
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
POINTARRAY * point
Definition: liblwgeom.h:471
int32_t srid
Definition: liblwgeom.h:472
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390

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: