PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_azimuth()

Datum LWGEOM_azimuth ( PG_FUNCTION_ARGS  )

Definition at line 2505 of file lwgeom_functions_basic.c.

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