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

◆ lwmpoint_extract_points_4d()

POINT4D * lwmpoint_extract_points_4d ( const LWMPOINT g,
uint32_t *  npoints,
int *  input_empty 
)

Definition at line 172 of file lwgeom_median.c.

173{
174 uint32_t n = 0;
175 POINT4D* points = lwalloc(g->ngeoms * sizeof(POINT4D));
176 int has_m = lwgeom_has_m((LWGEOM*) g);
177
178 for (uint32_t i = 0; i < g->ngeoms; i++)
179 {
180 const LWGEOM* subg = lwcollection_getsubgeom((LWCOLLECTION*) g, i);
181 if (!lwgeom_is_empty(subg))
182 {
183 *input_empty = LW_FALSE;
184 if (!getPoint4d_p(((LWPOINT*) subg)->point, 0, &points[n]))
185 {
186 lwerror("Geometric median: getPoint4d_p reported failure on point (POINT(%g %g %g %g), number %d of %d in input).", points[n].x, points[n].y, points[n].z, points[n].m, i, g->ngeoms);
187 lwfree(points);
188 return NULL;
189 }
190 if (has_m)
191 {
192 /* This limitation on non-negativity can be lifted
193 * by replacing Weiszfeld algorithm with different one.
194 * Possible option described in:
195 *
196 * Drezner, Zvi & O. Wesolowsky, George. (1991).
197 * The Weber Problem On The Plane With Some Negative Weights.
198 * INFOR. Information Systems and Operational Research.
199 * 29. 10.1080/03155986.1991.11732158.
200 */
201 if (points[n].m < 0)
202 {
203 lwerror("Geometric median input contains points with negative weights (POINT(%g %g %g %g), number %d of %d in input). Implementation can't guarantee global minimum convergence.", points[n].x, points[n].y, points[n].z, points[n].m, i, g->ngeoms);
204 lwfree(points);
205 return NULL;
206 }
207
208 /* points with zero weight are not going to affect calculation, drop them early */
209 if (points[n].m > DBL_EPSILON) n++;
210 }
211 else
212 {
213 points[n].m = 1.0;
214 n++;
215 }
216 }
217 }
218
219#ifndef NDEBUG
220 /* check Z=0 for 2D inputs */
221 if (!lwgeom_has_z((LWGEOM*) g))
222 for (uint32_t i = 0; i < n; i++)
223 assert(points[i].z == 0);
224#endif
225
226 *npoints = n;
227 return points;
228}
#define LW_FALSE
Definition liblwgeom.h:94
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:962
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
const LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, uint32_t gnum)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition lwgeom_api.c:125
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:969
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
uint32_t ngeoms
Definition liblwgeom.h:538
double m
Definition liblwgeom.h:414

References getPoint4d_p(), LW_FALSE, lwalloc(), lwcollection_getsubgeom(), lwerror(), lwfree(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), POINT4D::m, LWMPOINT::ngeoms, and LWCOLLECTION::ngeoms.

Referenced by do_median_test(), and lwmpoint_median().

Here is the call graph for this function:
Here is the caller graph for this function: