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

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 662 of file lwgeom_functions_analytic.c.

663{
664 GSERIALIZED* geom;
665 LWGEOM* input;
666 LWBOUNDINGCIRCLE* mbc = NULL;
667 LWGEOM* lwcenter;
668 GSERIALIZED* center;
669 TupleDesc resultTupleDesc;
670 HeapTuple resultTuple;
671 Datum result;
672 Datum result_values[2];
673 bool result_is_null[2];
674 double radius = 0;
675
676 if (PG_ARGISNULL(0))
677 PG_RETURN_NULL();
678
679 geom = PG_GETARG_GSERIALIZED_P(0);
680
681 /* Empty geometry? Return POINT EMPTY with zero radius */
682 if (gserialized_is_empty(geom))
683 {
685 }
686 else
687 {
688 input = lwgeom_from_gserialized(geom);
689 mbc = lwgeom_calculate_mbc(input);
690
691 if (!(mbc && mbc->center))
692 {
693 lwpgerror("Error calculating minimum bounding circle.");
694 lwgeom_free(input);
695 PG_RETURN_NULL();
696 }
697
698 lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
699 radius = mbc->radius;
700
702 lwgeom_free(input);
703 }
704
705 center = geometry_serialize(lwcenter);
706 lwgeom_free(lwcenter);
707
708 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
709 BlessTupleDesc(resultTupleDesc);
710
711 result_values[0] = PointerGetDatum(center);
712 result_is_null[0] = false;
713 result_values[1] = Float8GetDatum(radius);
714 result_is_null[1] = false;
715
716 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
717
718 result = HeapTupleGetDatum(resultTuple);
719
720 PG_RETURN_DATUM(result);
721}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
#define LW_FALSE
Definition liblwgeom.h:94
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoint.c:151
POINT2D * center
Definition liblwgeom.h:1846
int32_t srid
Definition liblwgeom.h:460
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390

References LWBOUNDINGCIRCLE::center, gserialized_get_srid(), gserialized_is_empty(), LW_FALSE, lwboundingcircle_destroy(), lwgeom_calculate_mbc(), lwgeom_free(), lwgeom_from_gserialized(), lwpoint_construct_empty(), lwpoint_make2d(), LWBOUNDINGCIRCLE::radius, result, LWGEOM::srid, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: