PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1153 of file lwgeom_functions_analytic.c.

References LWBOUNDINGCIRCLE::center, dumpnode::geom, 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.

1154 {
1155  GSERIALIZED* geom;
1156  LWGEOM* input;
1157  LWBOUNDINGCIRCLE* mbc = NULL;
1158  LWGEOM* lwcircle;
1159  GSERIALIZED* center;
1160  int segs_per_quarter;
1161 
1162  if (PG_ARGISNULL(0))
1163  PG_RETURN_NULL();
1164 
1165  geom = PG_GETARG_GSERIALIZED_P(0);
1166  segs_per_quarter = PG_GETARG_INT32(1);
1167 
1168  /* Empty geometry? Return POINT EMPTY */
1169  if (gserialized_is_empty(geom))
1170  {
1172  }
1173  else
1174  {
1175  input = lwgeom_from_gserialized(geom);
1176  mbc = lwgeom_calculate_mbc(input);
1177 
1178  if (!(mbc && mbc->center))
1179  {
1180  lwpgerror("Error calculating minimum bounding circle.");
1181  lwgeom_free(input);
1182  PG_RETURN_NULL();
1183  }
1184 
1185  /* Zero radius? Return a point. */
1186  if (mbc->radius == 0)
1187  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1188  else
1189  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1190 
1192  lwgeom_free(input);
1193  }
1194 
1195  center = geometry_serialize(lwcircle);
1196  lwgeom_free(lwcircle);
1197 
1198  PG_RETURN_POINTER(center);
1199 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:145
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:133
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:252
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
double x
Definition: liblwgeom.h:327
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * geom
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
double y
Definition: liblwgeom.h:327
POINT2D * center
Definition: liblwgeom.h:1621
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:98
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
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:83

Here is the call graph for this function: