PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2509 of file lwgeom_functions_basic.c.

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