PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2511 of file lwgeom_functions_basic.c.

2512 {
2513  GSERIALIZED *geom;
2514  LWPOINT *lwpoint;
2515  POINT2D p1, p2;
2516  double result;
2517  int32_t srid;
2518 
2519  /* Extract first point */
2520  geom = PG_GETARG_GSERIALIZED_P(0);
2521  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2522  if (!lwpoint)
2523  {
2524  PG_FREE_IF_COPY(geom, 0);
2525  lwpgerror("Argument must be POINT geometries");
2526  PG_RETURN_NULL();
2527  }
2528  srid = lwpoint->srid;
2529  if (!getPoint2d_p(lwpoint->point, 0, &p1))
2530  {
2531  PG_FREE_IF_COPY(geom, 0);
2532  lwpgerror("Error extracting point");
2533  PG_RETURN_NULL();
2534  }
2535  lwpoint_free(lwpoint);
2536  PG_FREE_IF_COPY(geom, 0);
2537 
2538  /* Extract second point */
2539  geom = PG_GETARG_GSERIALIZED_P(1);
2540  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
2541  if (!lwpoint)
2542  {
2543  PG_FREE_IF_COPY(geom, 1);
2544  lwpgerror("Argument must be POINT geometries");
2545  PG_RETURN_NULL();
2546  }
2547  if (lwpoint->srid != srid)
2548  {
2549  PG_FREE_IF_COPY(geom, 1);
2550  lwpgerror("Operation on mixed SRID geometries");
2551  PG_RETURN_NULL();
2552  }
2553  if (!getPoint2d_p(lwpoint->point, 0, &p2))
2554  {
2555  PG_FREE_IF_COPY(geom, 1);
2556  lwpgerror("Error extracting point");
2557  PG_RETURN_NULL();
2558  }
2559  lwpoint_free(lwpoint);
2560  PG_FREE_IF_COPY(geom, 1);
2561 
2562  /* Standard return value for equality case */
2563  if ((p1.x == p2.x) && (p1.y == p2.y))
2564  {
2565  PG_RETURN_NULL();
2566  }
2567 
2568  /* Compute azimuth */
2569  if (!azimuth_pt_pt(&p1, &p2, &result))
2570  {
2571  PG_RETURN_NULL();
2572  }
2573 
2574  PG_RETURN_FLOAT8(result);
2575 }
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:2509
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:486
int32_t srid
Definition: liblwgeom.h:487
double y
Definition: liblwgeom.h:405
double x
Definition: liblwgeom.h:405

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: