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

Definition at line 1024 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.

1025 {
1026  GSERIALIZED* geom;
1027  LWGEOM* input;
1028  LWBOUNDINGCIRCLE* mbc = NULL;
1029  LWGEOM* lwcenter;
1030  GSERIALIZED* center;
1031  TupleDesc resultTupleDesc;
1032  HeapTuple resultTuple;
1033  Datum result;
1034  Datum result_values[2];
1035  bool result_is_null[2];
1036  double radius = 0;
1037 
1038  if (PG_ARGISNULL(0))
1039  PG_RETURN_NULL();
1040 
1041  geom = PG_GETARG_GSERIALIZED_P(0);
1042 
1043  /* Empty geometry? Return POINT EMPTY with zero radius */
1044  if (gserialized_is_empty(geom))
1045  {
1047  }
1048  else
1049  {
1050  input = lwgeom_from_gserialized(geom);
1051  mbc = lwgeom_calculate_mbc(input);
1052 
1053  if (!(mbc && mbc->center))
1054  {
1055  lwpgerror("Error calculating minimum bounding circle.");
1056  lwgeom_free(input);
1057  PG_RETURN_NULL();
1058  }
1059 
1060  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1061  radius = mbc->radius;
1062 
1064  lwgeom_free(input);
1065  }
1066 
1067  center = geometry_serialize(lwcenter);
1068  lwgeom_free(lwcenter);
1069 
1070  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1071  BlessTupleDesc(resultTupleDesc);
1072 
1073  result_values[0] = PointerGetDatum(center);
1074  result_is_null[0] = false;
1075  result_values[1] = Float8GetDatum(radius);
1076  result_is_null[1] = false;
1077 
1078  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1079 
1080  result = HeapTupleGetDatum(resultTuple);
1081 
1082  PG_RETURN_DATUM(result);
1083 }
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:1137
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
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:178
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:1643
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:99

Here is the call graph for this function: