PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ST_MinimumBoundingRadius()

Datum ST_MinimumBoundingRadius ( PG_FUNCTION_ARGS  )

Definition at line 1118 of file lwgeom_functions_analytic.c.

1119{
1120 GSERIALIZED* geom;
1121 LWGEOM* input;
1122 LWBOUNDINGCIRCLE* mbc = NULL;
1123 LWGEOM* lwcenter;
1124 GSERIALIZED* center;
1125 TupleDesc resultTupleDesc;
1126 HeapTuple resultTuple;
1127 Datum result;
1128 Datum result_values[2];
1129 bool result_is_null[2];
1130 double radius = 0;
1131
1132 if (PG_ARGISNULL(0))
1133 PG_RETURN_NULL();
1134
1135 geom = PG_GETARG_GSERIALIZED_P(0);
1136
1137 /* Empty geometry? Return POINT EMPTY with zero radius */
1138 if (gserialized_is_empty(geom))
1139 {
1141 }
1142 else
1143 {
1144 input = lwgeom_from_gserialized(geom);
1145 mbc = lwgeom_calculate_mbc(input);
1146
1147 if (!(mbc && mbc->center))
1148 {
1149 lwpgerror("Error calculating minimum bounding circle.");
1150 lwgeom_free(input);
1151 PG_RETURN_NULL();
1152 }
1153
1154 lwcenter = (LWGEOM*) lwpoint_make2d(input->srid, mbc->center->x, mbc->center->y);
1155 radius = mbc->radius;
1156
1158 lwgeom_free(input);
1159 }
1160
1161 center = geometry_serialize(lwcenter);
1162 lwgeom_free(lwcenter);
1163
1164 get_call_result_type(fcinfo, NULL, &resultTupleDesc);
1165 BlessTupleDesc(resultTupleDesc);
1166
1167 result_values[0] = PointerGetDatum(center);
1168 result_is_null[0] = false;
1169 result_values[1] = Float8GetDatum(radius);
1170 result_is_null[1] = false;
1171
1172 resultTuple = heap_form_tuple(resultTupleDesc, result_values, result_is_null);
1173
1174 result = HeapTupleGetDatum(resultTuple);
1175
1176 PG_RETURN_DATUM(result);
1177}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
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.
#define LW_FALSE
Definition liblwgeom.h:108
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition lwpoint.c:163
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoint.c:151
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
POINT2D * center
Definition liblwgeom.h:1756
int32_t srid
Definition liblwgeom.h:446
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376

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: