PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingCircle()

Datum ST_MinimumBoundingCircle ( PG_FUNCTION_ARGS  )

Definition at line 1186 of file lwgeom_functions_analytic.c.

1187 {
1188  GSERIALIZED* geom;
1189  LWGEOM* input;
1190  LWBOUNDINGCIRCLE* mbc = NULL;
1191  LWGEOM* lwcircle;
1192  GSERIALIZED* center;
1193  int segs_per_quarter;
1194 
1195  if (PG_ARGISNULL(0))
1196  PG_RETURN_NULL();
1197 
1198  geom = PG_GETARG_GSERIALIZED_P(0);
1199  segs_per_quarter = PG_GETARG_INT32(1);
1200 
1201  /* Empty geometry? Return POINT EMPTY */
1202  if (gserialized_is_empty(geom))
1203  {
1205  }
1206  else
1207  {
1208  input = lwgeom_from_gserialized(geom);
1209  mbc = lwgeom_calculate_mbc(input);
1210 
1211  if (!(mbc && mbc->center))
1212  {
1213  lwpgerror("Error calculating minimum bounding circle.");
1214  lwgeom_free(input);
1215  PG_RETURN_NULL();
1216  }
1217 
1218  /* Zero radius? Return a point. */
1219  if (mbc->radius == 0)
1220  lwcircle = lwpoint_as_lwgeom(lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y));
1221  else
1222  lwcircle = lwpoly_as_lwgeom(lwpoly_construct_circle(input->srid, mbc->center->x, mbc->center->y, mbc->radius, segs_per_quarter, LW_TRUE));
1223 
1225  lwgeom_free(input);
1226  }
1227 
1228  center = geometry_serialize(lwcircle);
1229  lwgeom_free(lwcircle);
1230 
1231  PG_RETURN_POINTER(center);
1232 }
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: gserialized.c:152
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
LWPOLY * lwpoly_construct_circle(int32_t srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
Definition: lwpoly.c:120
#define LW_FALSE
Definition: liblwgeom.h:108
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:311
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:326
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
POINT2D * center
Definition: liblwgeom.h:1756
int32_t srid
Definition: liblwgeom.h:446
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376

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: