PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1109 of file lwgeom_functions_analytic.c.

1110 {
1111  GSERIALIZED* geom;
1112  LWGEOM* input;
1113  LWBOUNDINGCIRCLE* mbc = NULL;
1114  LWGEOM* lwcenter;
1115  GSERIALIZED* center;
1116  TupleDesc resultTupleDesc;
1117  HeapTuple resultTuple;
1118  Datum result;
1119  Datum result_values[2];
1120  bool result_is_null[2];
1121  double radius = 0;
1122 
1123  if (PG_ARGISNULL(0))
1124  PG_RETURN_NULL();
1125 
1126  geom = PG_GETARG_GSERIALIZED_P(0);
1127 
1128  /* Empty geometry? Return POINT EMPTY with zero radius */
1129  if (gserialized_is_empty(geom))
1130  {
1132  }
1133  else
1134  {
1135  input = lwgeom_from_gserialized(geom);
1136  mbc = lwgeom_calculate_mbc(input);
1137 
1138  if (!(mbc && mbc->center))
1139  {
1140  lwpgerror("Error calculating minimum bounding circle.");
1141  lwgeom_free(input);
1142  PG_RETURN_NULL();
1143  }
1144 
1145  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1146  radius = mbc->radius;
1147 
1149  lwgeom_free(input);
1150  }
1151 
1152  center = geometry_serialize(lwcenter);
1153  lwgeom_free(lwcenter);
1154 
1155  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1156  BlessTupleDesc(resultTupleDesc);
1157 
1158  result_values[0] = PointerGetDatum(center);
1159  result_is_null[0] = false;
1160  result_values[1] = Float8GetDatum(radius);
1161  result_is_null[1] = false;
1162 
1163  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1164 
1165  result = HeapTupleGetDatum(resultTuple);
1166 
1167  PG_RETURN_DATUM(result);
1168 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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
#define LW_FALSE
Definition: liblwgeom.h:94
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
POINT2D * center
Definition: liblwgeom.h:1816
int32_t srid
Definition: liblwgeom.h:460
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390

References LWBOUNDINGCIRCLE::center, gserialized_get_srid(), gserialized_is_empty(), LW_FALSE, lwboundingcircle_destroy(), lwgeom_calculate_mbc(), lwgeom_free(), lwgeom_from_gserialized(), lwpoint_construct_empty(), lwpoint_make2d(), LWBOUNDINGCIRCLE::radius, result, LWGEOM::srid, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: