PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ union_dbscan_minpoints_1()

static int union_dbscan_minpoints_1 ( LWGEOM **  geoms,
uint32_t  num_geoms,
UNIONFIND uf,
double  eps,
char **  in_a_cluster_ret 
)
static

Definition at line 321 of file lwgeom_geos_cluster.c.

322 {
323  uint32_t p, i;
324  struct STRTree tree;
325  struct QueryContext cxt =
326  {
327  .items_found = NULL,
328  .num_items_found = 0,
329  .items_found_size = 0
330  };
331  int success = LW_SUCCESS;
332 
333  if (in_a_cluster_ret)
334  {
335  char* in_a_cluster = lwalloc(num_geoms * sizeof(char));
336  for (i = 0; i < num_geoms; i++)
337  in_a_cluster[i] = LW_TRUE;
338  *in_a_cluster_ret = in_a_cluster;
339  }
340 
341  if (num_geoms <= 1)
342  return LW_SUCCESS;
343 
344  tree = make_strtree((void**) geoms, num_geoms, LW_TRUE);
345  if (tree.tree == NULL)
346  {
347  destroy_strtree(&tree);
348  return LW_FAILURE;
349  }
350 
351  for (p = 0; p < num_geoms; p++)
352  {
353  int rv = LW_SUCCESS;
354  if (lwgeom_is_empty(geoms[p]))
355  continue;
356 
357  rv = dbscan_update_context(tree.tree, &cxt, geoms, p, eps);
358  if (rv == LW_FAILURE)
359  {
360  destroy_strtree(&tree);
361  return LW_FAILURE;
362  }
363  for (i = 0; i < cxt.num_items_found; i++)
364  {
365  uint32_t q = *((uint32_t*) cxt.items_found[i]);
366 
367  if (UF_find(uf, p) != UF_find(uf, q))
368  {
369  double mindist = lwgeom_mindistance2d_tolerance(geoms[p], geoms[q], eps);
370  if (mindist == FLT_MAX)
371  {
372  success = LW_FAILURE;
373  break;
374  }
375 
376  if (mindist <= eps)
377  UF_union(uf, p, q);
378  }
379  }
380  }
381 
382  if (cxt.items_found)
383  lwfree(cxt.items_found);
384 
385  destroy_strtree(&tree);
386 
387  return success;
388 }
#define LW_FAILURE
Definition: liblwgeom.h:111
#define LW_SUCCESS
Definition: liblwgeom.h:112
void lwfree(void *mem)
Definition: lwutil.c:242
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:210
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
static int dbscan_update_context(GEOSSTRtree *tree, struct QueryContext *cxt, LWGEOM **geoms, uint32_t p, double eps)
static struct STRTree make_strtree(void **geoms, uint32_t num_geoms, char is_lwgeom)
Make a GEOSSTRtree that stores a pointer to a variable containing the array index of the input geoms.
static void destroy_strtree(struct STRTree *tree)
Clean up STRTree after use.
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:203
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
Definition: lwunionfind.c:62
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)
Definition: lwunionfind.c:85
uint32_t num_items_found
GEOSSTRtree * tree

References dbscan_update_context(), destroy_strtree(), QueryContext::items_found, LW_FAILURE, LW_SUCCESS, LW_TRUE, lwalloc(), lwfree(), lwgeom_is_empty(), lwgeom_mindistance2d_tolerance(), make_strtree(), QueryContext::num_items_found, STRTree::tree, UF_find(), and UF_union().

Referenced by union_dbscan().

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