PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1085 of file lwgeom_functions_analytic.c.

References LWBOUNDINGCIRCLE::center, dumpnode::geom, 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.

1086 {
1087  GSERIALIZED* geom;
1088  LWGEOM* input;
1089  LWBOUNDINGCIRCLE* mbc = NULL;
1090  LWGEOM* lwcenter;
1091  GSERIALIZED* center;
1092  TupleDesc resultTupleDesc;
1093  HeapTuple resultTuple;
1094  Datum result;
1095  Datum result_values[2];
1096  bool result_is_null[2];
1097  double radius = 0;
1098 
1099  if (PG_ARGISNULL(0))
1100  PG_RETURN_NULL();
1101 
1102  geom = PG_GETARG_GSERIALIZED_P(0);
1103 
1104  /* Empty geometry? Return POINT EMPTY with zero radius */
1105  if (gserialized_is_empty(geom))
1106  {
1108  }
1109  else
1110  {
1111  input = lwgeom_from_gserialized(geom);
1112  mbc = lwgeom_calculate_mbc(input);
1113 
1114  if (!(mbc && mbc->center))
1115  {
1116  lwpgerror("Error calculating minimum bounding circle.");
1117  lwgeom_free(input);
1118  PG_RETURN_NULL();
1119  }
1120 
1121  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1122  radius = mbc->radius;
1123 
1125  lwgeom_free(input);
1126  }
1127 
1128  center = geometry_serialize(lwcenter);
1129  lwgeom_free(lwcenter);
1130 
1131  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1132  BlessTupleDesc(resultTupleDesc);
1133 
1134  result_values[0] = PointerGetDatum(center);
1135  result_is_null[0] = false;
1136  result_values[1] = Float8GetDatum(radius);
1137  result_is_null[1] = false;
1138 
1139  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1140 
1141  result = HeapTupleGetDatum(resultTuple);
1142 
1143  PG_RETURN_DATUM(result);
1144 }
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:145
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:133
int32_t srid
Definition: liblwgeom.h:398
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
double x
Definition: liblwgeom.h:327
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * geom
#define LW_FALSE
Definition: liblwgeom.h:76
double y
Definition: liblwgeom.h:327
POINT2D * center
Definition: liblwgeom.h:1621
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
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:83

Here is the call graph for this function: