34 for (i = 0; i < npoints; i++)
51 for (i = 0; i < npoints; i++)
53 if (distances[i] == 0)
56 denom += 1.0 / distances[i];
59 for (i = 0; i < npoints; i++)
63 next.
x += (points[i].
x / distances[i]) / denom;
64 next.
y += (points[i].
y / distances[i]) / denom;
65 next.
z += (points[i].
z / distances[i]) / denom;
91 for (i = 0; i < npoints; i++)
95 dx += (points[i].
x - curr->
x) / distances[i];
96 dy += (points[i].
y - curr->
y) / distances[i];
97 dz += (points[i].
z - curr->
z) / distances[i];
101 d_sqr = sqrt (dx*dx + dy*dy + dz*dz);
102 r_inv = d_sqr > DBL_EPSILON ? 1.0 / d_sqr : 1.0;
123 for (i = 0; i < npoints; i++)
125 guess.
x += points[i].
x / npoints;
126 guess.
y += points[i].
y / npoints;
127 guess.
z += points[i].
z / npoints;
141 for (i = 0; i < g->ngeoms; i++)
163 double delta = DBL_MAX;
176 distances =
lwalloc(npoints *
sizeof(
double));
178 for (i = 0; i < max_iter && delta > tol; i++)
180 delta =
iterate_3d(&median, points, npoints, distances);
186 if (fail_if_not_converged && delta > tol)
188 lwerror(
"Median failed to converge within %g after %d iterations.", tol, max_iter);
212 lwerror(
"Unsupported geometry type in lwgeom_median");
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
LWPOINT * lwpoint_make2d(int srid, double x, double y)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
#define LW_TRUE
Return types for functions with status returns.
LWPOINT * lwpoint_make3dz(int srid, double x, double y, double z)
double distance3d_pt_pt(const POINT3D *p1, const POINT3D *p2)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
void * lwalloc(size_t size)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
void lwerror(const char *fmt,...)
Write a notice out to the error handler.