PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1162 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(), PG_FUNCTION_INFO_V1(), LWBOUNDINGCIRCLE::radius, LWGEOM::srid, ST_GeometricMedian(), POINT2D::x, and POINT2D::y.

Referenced by ST_MinimumBoundingRadius().

1163 {
1164  GSERIALIZED* geom;
1165  LWGEOM* input;
1166  LWBOUNDINGCIRCLE* mbc = NULL;
1167  LWGEOM* lwcircle;
1168  GSERIALIZED* center;
1169  int segs_per_quarter;
1170 
1171  if (PG_ARGISNULL(0))
1172  PG_RETURN_NULL();
1173 
1174  geom = PG_GETARG_GSERIALIZED_P(0);
1175  segs_per_quarter = PG_GETARG_INT32(1);
1176 
1177  /* Empty geometry? Return POINT EMPTY */
1178  if (gserialized_is_empty(geom))
1179  {
1181  }
1182  else
1183  {
1184  input = lwgeom_from_gserialized(geom);
1185  mbc = lwgeom_calculate_mbc(input);
1186 
1187  if (!(mbc && mbc->center))
1188  {
1189  lwpgerror("Error calculating minimum bounding circle.");
1190  lwgeom_free(input);
1191  PG_RETURN_NULL();
1192  }
1193 
1194  /* Zero radius? Return a point. */
1195  if (mbc->radius == 0)
1196  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1197  else
1198  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1199 
1201  lwgeom_free(input);
1202  }
1203 
1204  center = geometry_serialize(lwcircle);
1205  lwgeom_free(lwcircle);
1206 
1207  PG_RETURN_POINTER(center);
1208 }
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:1099
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int32_t srid
Definition: liblwgeom.h:399
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:288
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
double x
Definition: liblwgeom.h:328
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * geom
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
double y
Definition: liblwgeom.h:328
POINT2D * center
Definition: liblwgeom.h:1643
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:303
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:100
Here is the call graph for this function:
Here is the caller graph for this function: