PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1069 of file lwgeom_functions_analytic.c.

1070 {
1071  GSERIALIZED* geom;
1072  LWGEOM* input;
1073  LWBOUNDINGCIRCLE* mbc = NULL;
1074  LWGEOM* lwcenter;
1075  GSERIALIZED* center;
1076  TupleDesc resultTupleDesc;
1077  HeapTuple resultTuple;
1078  Datum result;
1079  Datum result_values[2];
1080  bool result_is_null[2];
1081  double radius = 0;
1082 
1083  if (PG_ARGISNULL(0))
1084  PG_RETURN_NULL();
1085 
1086  geom = PG_GETARG_GSERIALIZED_P(0);
1087 
1088  /* Empty geometry? Return POINT EMPTY with zero radius */
1089  if (gserialized_is_empty(geom))
1090  {
1092  }
1093  else
1094  {
1095  input = lwgeom_from_gserialized(geom);
1096  mbc = lwgeom_calculate_mbc(input);
1097 
1098  if (!(mbc && mbc->center))
1099  {
1100  lwpgerror("Error calculating minimum bounding circle.");
1101  lwgeom_free(input);
1102  PG_RETURN_NULL();
1103  }
1104 
1105  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1106  radius = mbc->radius;
1107 
1109  lwgeom_free(input);
1110  }
1111 
1112  center = geometry_serialize(lwcenter);
1113  lwgeom_free(lwcenter);
1114 
1115  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1116  BlessTupleDesc(resultTupleDesc);
1117 
1118  result_values[0] = PointerGetDatum(center);
1119  result_is_null[0] = false;
1120  result_values[1] = Float8GetDatum(radius);
1121  result_is_null[1] = false;
1122 
1123  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1124 
1125  result = HeapTupleGetDatum(resultTuple);
1126 
1127  PG_RETURN_DATUM(result);
1128 }
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
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
LWPOINT * lwpoint_make2d(int srid, double x, double y)
Definition: lwpoint.c:163
#define LW_FALSE
Definition: liblwgeom.h:77
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
POINT2D * center
Definition: liblwgeom.h:1650
int32_t srid
Definition: liblwgeom.h:402
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References LWBOUNDINGCIRCLE::center, geometry_serialize(), 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, LWGEOM::srid, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: