PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1134 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().

1135 {
1136  GSERIALIZED* geom;
1137  LWGEOM* input;
1138  LWBOUNDINGCIRCLE* mbc = NULL;
1139  LWGEOM* lwcircle;
1140  GSERIALIZED* center;
1141  int segs_per_quarter;
1142 
1143  if (PG_ARGISNULL(0))
1144  PG_RETURN_NULL();
1145 
1146  geom = PG_GETARG_GSERIALIZED_P(0);
1147  segs_per_quarter = PG_GETARG_INT32(1);
1148 
1149  /* Empty geometry? Return POINT EMPTY */
1150  if (gserialized_is_empty(geom))
1151  {
1153  }
1154  else
1155  {
1156  input = lwgeom_from_gserialized(geom);
1157  mbc = lwgeom_calculate_mbc(input);
1158 
1159  if (!(mbc && mbc->center))
1160  {
1161  lwpgerror("Error calculating minimum bounding circle.");
1162  lwgeom_free(input);
1163  PG_RETURN_NULL();
1164  }
1165 
1166  /* Zero radius? Return a point. */
1167  if (mbc->radius == 0)
1168  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1169  else
1170  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1171 
1173  lwgeom_free(input);
1174  }
1175 
1176  center = geometry_serialize(lwcircle);
1177  lwgeom_free(lwcircle);
1178 
1179  PG_RETURN_POINTER(center);
1180 }
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:1128
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int32_t srid
Definition: liblwgeom.h:401
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:311
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:330
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:330
POINT2D * center
Definition: liblwgeom.h:1611
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:326
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:
Here is the caller graph for this function: