PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1094 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().

1095 {
1096  GSERIALIZED* geom;
1097  LWGEOM* input;
1098  LWBOUNDINGCIRCLE* mbc = NULL;
1099  LWGEOM* lwcenter;
1100  GSERIALIZED* center;
1101  TupleDesc resultTupleDesc;
1102  HeapTuple resultTuple;
1103  Datum result;
1104  Datum result_values[2];
1105  bool result_is_null[2];
1106  double radius = 0;
1107 
1108  if (PG_ARGISNULL(0))
1109  PG_RETURN_NULL();
1110 
1111  geom = PG_GETARG_GSERIALIZED_P(0);
1112 
1113  /* Empty geometry? Return POINT EMPTY with zero radius */
1114  if (gserialized_is_empty(geom))
1115  {
1117  }
1118  else
1119  {
1120  input = lwgeom_from_gserialized(geom);
1121  mbc = lwgeom_calculate_mbc(input);
1122 
1123  if (!(mbc && mbc->center))
1124  {
1125  lwpgerror("Error calculating minimum bounding circle.");
1126  lwgeom_free(input);
1127  PG_RETURN_NULL();
1128  }
1129 
1130  lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1131  radius = mbc->radius;
1132 
1134  lwgeom_free(input);
1135  }
1136 
1137  center = geometry_serialize(lwcenter);
1138  lwgeom_free(lwcenter);
1139 
1140  get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1141  BlessTupleDesc(resultTupleDesc);
1142 
1143  result_values[0] = PointerGetDatum(center);
1144  result_is_null[0] = false;
1145  result_values[1] = Float8GetDatum(radius);
1146  result_is_null[1] = false;
1147 
1148  resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1149 
1150  result = HeapTupleGetDatum(resultTuple);
1151 
1152  PG_RETURN_DATUM(result);
1153 }
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:1099
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
int32_t srid
Definition: liblwgeom.h:399
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
double x
Definition: liblwgeom.h:328
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWGEOM * geom
#define LW_FALSE
Definition: liblwgeom.h:77
double y
Definition: liblwgeom.h:328
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:100
Here is the call graph for this function:
Here is the caller graph for this function: