PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ 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.

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

Referenced by do_median_test(), and lwmpoint_median().

173 {
174  uint32_t i;
175  uint32_t n = 0;
176  POINT4D* points = lwalloc(g->ngeoms * sizeof(POINT4D));
177  int has_m = lwgeom_has_m((LWGEOM*) g);
178 
179  for (i = 0; i < g->ngeoms; i++)
180  {
182  if (!lwgeom_is_empty(subg))
183  {
184  *input_empty = LW_FALSE;
185  if (!getPoint4d_p(((LWPOINT*) subg)->point, 0, &points[n]))
186  {
187  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);
188  lwfree(points);
189  return NULL;
190  }
191  if (has_m)
192  {
193  /* This limitation on non-negativity can be lifted
194  * by replacing Weiszfeld algorithm with different one.
195  * Possible option described in:
196  *
197  * Drezner, Zvi & O. Wesolowsky, George. (1991).
198  * The Weber Problem On The Plane With Some Negative Weights.
199  * INFOR. Information Systems and Operational Research.
200  * 29. 10.1080/03155986.1991.11732158.
201  */
202  if (points[n].m < 0)
203  {
204  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);
205  lwfree(points);
206  return NULL;
207  }
208 
209  /* points with zero weight are not going to affect calculation, drop them early */
210  if (points[n].m > DBL_EPSILON) n++;
211  }
212  else
213  {
214  points[n].m = 1.0;
215  n++;
216  }
217  }
218  }
219 
220 #if PARANOIA_LEVEL > 0
221  /* check Z=0 for 2D inputs*/
222  if (!lwgeom_has_z((LWGEOM*) g)) for (i = 0; i < n; i++) assert(points[i].z == 0);
223 #endif
224 
225  *npoints = n;
226  return points;
227 }
double m
Definition: liblwgeom.h:351
uint32_t ngeoms
Definition: liblwgeom.h:467
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:929
unsigned int uint32_t
Definition: uthash.h:78
#define LW_FALSE
Definition: liblwgeom.h:76
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
void * lwalloc(size_t size)
Definition: lwutil.c:229
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1392
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:936
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: