PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1137 of file lwgeom_functions_analytic.c.

1138 {
1139  GSERIALIZED* geom;
1140  LWGEOM* input;
1141  LWBOUNDINGCIRCLE* mbc = NULL;
1142  LWGEOM* lwcircle;
1143  GSERIALIZED* center;
1144  int segs_per_quarter;
1145 
1146  if (PG_ARGISNULL(0))
1147  PG_RETURN_NULL();
1148 
1149  geom = PG_GETARG_GSERIALIZED_P(0);
1150  segs_per_quarter = PG_GETARG_INT32(1);
1151 
1152  /* Empty geometry? Return POINT EMPTY */
1153  if (gserialized_is_empty(geom))
1154  {
1156  }
1157  else
1158  {
1159  input = lwgeom_from_gserialized(geom);
1160  mbc = lwgeom_calculate_mbc(input);
1161 
1162  if (!(mbc && mbc->center))
1163  {
1164  lwpgerror("Error calculating minimum bounding circle.");
1165  lwgeom_free(input);
1166  PG_RETURN_NULL();
1167  }
1168 
1169  /* Zero radius? Return a point. */
1170  if (mbc->radius == 0)
1171  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1172  else
1173  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1174 
1176  lwgeom_free(input);
1177  }
1178 
1179  center = geometry_serialize(lwcircle);
1180  lwgeom_free(lwcircle);
1181 
1182  PG_RETURN_POINTER(center);
1183 }
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
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.
Definition: g_serialized.c:179
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
#define LW_FALSE
Definition: liblwgeom.h:77
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:320
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
POINT2D * center
Definition: liblwgeom.h:1650
int32_t srid
Definition: liblwgeom.h:402
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References LWBOUNDINGCIRCLE::center, geometry_serialize(), 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: