PostGIS  2.5.7dev-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 318 of file lwgeom_geos_cluster.c.

319 {
320  uint32_t p, i;
321  struct STRTree tree;
322  struct QueryContext cxt =
323  {
324  .items_found = NULL,
325  .num_items_found = 0,
326  .items_found_size = 0
327  };
328  int success = LW_SUCCESS;
329 
330  if (in_a_cluster_ret)
331  {
332  char* in_a_cluster = lwalloc(num_geoms * sizeof(char));
333  for (i = 0; i < num_geoms; i++)
334  in_a_cluster[i] = LW_TRUE;
335  *in_a_cluster_ret = in_a_cluster;
336  }
337 
338  if (num_geoms <= 1)
339  return LW_SUCCESS;
340 
341  tree = make_strtree((void**) geoms, num_geoms, LW_TRUE);
342  if (tree.tree == NULL)
343  {
344  destroy_strtree(&tree);
345  return LW_FAILURE;
346  }
347 
348  for (p = 0; p < num_geoms; p++)
349  {
350  if (lwgeom_is_empty(geoms[p]))
351  continue;
352 
353  dbscan_update_context(tree.tree, &cxt, geoms, p, eps);
354  for (i = 0; i < cxt.num_items_found; i++)
355  {
356  uint32_t q = *((uint32_t*) cxt.items_found[i]);
357 
358  if (UF_find(uf, p) != UF_find(uf, q))
359  {
360  double mindist = lwgeom_mindistance2d_tolerance(geoms[p], geoms[q], eps);
361  if (mindist == FLT_MAX)
362  {
363  success = LW_FAILURE;
364  break;
365  }
366 
367  if (mindist <= eps)
368  UF_union(uf, p, q);
369  }
370  }
371  }
372 
373  if (cxt.items_found)
374  lwfree(cxt.items_found);
375 
376  destroy_strtree(&tree);
377 
378  return success;
379 }
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
void lwfree(void *mem)
Definition: lwutil.c:244
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:213
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:1393
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
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.
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
Definition: lwunionfind.c:61
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)
Definition: lwunionfind.c:84
uint32_t num_items_found
GEOSSTRtree * tree
unsigned int uint32_t
Definition: uthash.h:78

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: