PostGIS  3.4.0dev-r@@SVN_REVISION@@
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1177 of file lwgeom_functions_analytic.c.

1178 {
1179  GSERIALIZED* geom;
1180  LWGEOM* input;
1181  LWBOUNDINGCIRCLE* mbc = NULL;
1182  LWGEOM* lwcircle;
1183  GSERIALIZED* center;
1184  int segs_per_quarter;
1185 
1186  if (PG_ARGISNULL(0))
1187  PG_RETURN_NULL();
1188 
1189  geom = PG_GETARG_GSERIALIZED_P(0);
1190  segs_per_quarter = PG_GETARG_INT32(1);
1191 
1192  /* Empty geometry? Return POINT EMPTY */
1193  if (gserialized_is_empty(geom))
1194  {
1196  }
1197  else
1198  {
1199  input = lwgeom_from_gserialized(geom);
1200  mbc = lwgeom_calculate_mbc(input);
1201 
1202  if (!(mbc && mbc->center))
1203  {
1204  lwpgerror("Error calculating minimum bounding circle.");
1205  lwgeom_free(input);
1206  PG_RETURN_NULL();
1207  }
1208 
1209  /* Zero radius? Return a point. */
1210  if (mbc->radius == 0)
1211  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1212  else
1213  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1214 
1216  lwgeom_free(input);
1217  }
1218 
1219  center = geometry_serialize(lwcircle);
1220  lwgeom_free(lwcircle);
1221 
1222  PG_RETURN_POINTER(center);
1223 }
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)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
LWPOLY * lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
#define LW_FALSE
Definition: liblwgeom.h:94
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:329
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
POINT2D * center
Definition: liblwgeom.h:1816
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: