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

Definition at line 1092 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.

1093 {
1094  GSERIALIZED* geom;
1095  LWGEOM* input;
1096  LWBOUNDINGCIRCLE* mbc = NULL;
1097  LWGEOM* lwcircle;
1098  GSERIALIZED* center;
1099  int segs_per_quarter;
1100 
1101  if (PG_ARGISNULL(0))
1102  PG_RETURN_NULL();
1103 
1104  geom = PG_GETARG_GSERIALIZED_P(0);
1105  segs_per_quarter = PG_GETARG_INT32(1);
1106 
1107  /* Empty geometry? Return POINT EMPTY */
1108  if (gserialized_is_empty(geom))
1109  {
1111  }
1112  else
1113  {
1114  input = lwgeom_from_gserialized(geom);
1115  mbc = lwgeom_calculate_mbc(input);
1116 
1117  if (!(mbc && mbc->center))
1118  {
1119  lwpgerror("Error calculating minimum bounding circle.");
1120  lwgeom_free(input);
1121  PG_RETURN_NULL();
1122  }
1123 
1124  /* Zero radius? Return a point. */
1125  if (mbc->radius == 0)
1126  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1127  else
1128  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1129 
1131  lwgeom_free(input);
1132  }
1133 
1134  center = geometry_serialize(lwcircle);
1135  lwgeom_free(lwcircle);
1136 
1137  PG_RETURN_POINTER(center);
1138 }
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:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:319
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
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:1643
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:334
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
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:99

Here is the call graph for this function: