PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1066 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(), PG_FUNCTION_INFO_V1(), LWBOUNDINGCIRCLE::radius, LWGEOM::srid, ST_MinimumBoundingCircle(), POINT2D::x, and POINT2D::y.

Referenced by point_in_multipolygon().

1067 {
1068  GSERIALIZED* geom;
1069  LWGEOM* input;
1070  LWBOUNDINGCIRCLE* mbc = NULL;
1071  LWGEOM* lwcenter;
1072  GSERIALIZED* center;
1073  TupleDesc resultTupleDesc;
1074  HeapTuple resultTuple;
1075  Datum result;
1076  Datum result_values[2];
1077  bool result_is_null[2];
1078  double radius = 0;
1079 
1080  if (PG_ARGISNULL(0))
1081  PG_RETURN_NULL();
1082 
1083  geom = PG_GETARG_GSERIALIZED_P(0);
1084 
1085  /* Empty geometry? Return POINT EMPTY with zero radius */
1086  if (gserialized_is_empty(geom))
1087  {
1089  }
1090  else
1091  {
1092  input = lwgeom_from_gserialized(geom);
1093  mbc = lwgeom_calculate_mbc(input);
1094 
1095  if (!(mbc && mbc->center))
1096  {
1097  lwpgerror("Error calculating minimum bounding circle.");
1098  lwgeom_free(input);
1099  PG_RETURN_NULL();
1100  }
1101 
1102  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1103  radius = mbc->radius;
1104 
1106  lwgeom_free(input);
1107  }
1108 
1109  center = geometry_serialize(lwcenter);
1110  lwgeom_free(lwcenter);
1111 
1112  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1113  BlessTupleDesc(resultTupleDesc);
1114 
1115  result_values[0] = PointerGetDatum(center);
1116  result_is_null[0] = false;
1117  result_values[1] = Float8GetDatum(radius);
1118  result_is_null[1] = false;
1119 
1120  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1121 
1122  result = HeapTupleGetDatum(resultTuple);
1123 
1124  PG_RETURN_DATUM(result);
1125 }
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:1128
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int32_t srid
Definition: liblwgeom.h:401
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:330
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * geom
#define LW_FALSE
Definition: liblwgeom.h:76
double y
Definition: liblwgeom.h:330
POINT2D * center
Definition: liblwgeom.h:1611
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:
Here is the caller graph for this function: