1223 static const double min_default_tolerance = 1e-8;
1224 double tolerance = min_default_tolerance;
1225 bool compute_tolerance_from_box;
1226 bool fail_if_not_converged;
1230 if (PG_ARGISNULL(0))
1233 compute_tolerance_from_box = PG_ARGISNULL(1);
1235 if (!compute_tolerance_from_box)
1237 tolerance = PG_GETARG_FLOAT8(1);
1240 lwpgerror(
"Tolerance must be positive.");
1245 max_iter = PG_ARGISNULL(2) ? -1 : PG_GETARG_INT32(2);
1246 fail_if_not_converged = PG_ARGISNULL(3) ?
LW_FALSE : PG_GETARG_BOOL(3);
1250 lwpgerror(
"Maximum iterations must be positive.");
1255 geom = PG_GETARG_GSERIALIZED_P(0);
1258 if (compute_tolerance_from_box)
1263 static const double tolerance_coefficient = 1e-6;
1276 tolerance =
FP_MAX(min_default_tolerance, tolerance_coefficient * min_dim);
1280 lwresult =
lwgeom_median(input, tolerance, max_iter, fail_if_not_converged);
1285 lwpgerror(
"Error computing geometric median.");
1291 PG_RETURN_POINTER(result);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)