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

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 730 of file lwgeom_functions_analytic.c.

731{
732 GSERIALIZED* geom;
733 LWGEOM* input;
734 LWBOUNDINGCIRCLE* mbc = NULL;
735 LWGEOM* lwcircle;
736 GSERIALIZED* center;
737 int segs_per_quarter;
738
739 if (PG_ARGISNULL(0))
740 PG_RETURN_NULL();
741
742 geom = PG_GETARG_GSERIALIZED_P(0);
743 segs_per_quarter = PG_GETARG_INT32(1);
744
745 /* Empty geometry? Return POINT EMPTY */
746 if (gserialized_is_empty(geom))
747 {
749 }
750 else
751 {
752 input = lwgeom_from_gserialized(geom);
753 mbc = lwgeom_calculate_mbc(input);
754
755 if (!(mbc && mbc->center))
756 {
757 lwpgerror("Error calculating minimum bounding circle.");
758 lwgeom_free(input);
759 PG_RETURN_NULL();
760 }
761
762 /* Zero radius? Return a point. */
763 if (mbc->radius == 0)
764 lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
765 else
766 lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
767
769 lwgeom_free(input);
770 }
771
772 center = geometry_serialize(lwcircle);
773 lwgeom_free(lwcircle);
774
775 PG_RETURN_POINTER(center);
776}
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.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
#define LW_FALSE
Definition liblwgeom.h:94
LWPOLY * lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition lwpoly.c:120
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
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition lwgeom.c:357
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, LW_TRUE, lwboundingcircle_destroy(), lwgeom_calculate_mbc(), lwgeom_free(), lwgeom_from_gserialized(), lwpoint_as_lwgeom(), lwpoint_construct_empty(), lwpoint_make2d(), lwpoly_as_lwgeom(), lwpoly_construct_circle(), LWBOUNDINGCIRCLE::radius, LWGEOM::srid, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: