PostGIS  2.4.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 314 of file lwgeom_geos_cluster.c.

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().

315 {
316  uint32_t p, i;
317  struct STRTree tree;
318  struct QueryContext cxt =
319  {
320  .items_found = NULL,
321  .num_items_found = 0,
322  .items_found_size = 0
323  };
324  int success = LW_SUCCESS;
325 
326  if (in_a_cluster_ret)
327  {
328  char* in_a_cluster = lwalloc(num_geoms * sizeof(char));
329  for (i = 0; i < num_geoms; i++)
330  in_a_cluster[i] = LW_TRUE;
331  *in_a_cluster_ret = in_a_cluster;
332  }
333 
334  if (num_geoms <= 1)
335  return LW_SUCCESS;
336 
337  tree = make_strtree((void**) geoms, num_geoms, LW_TRUE);
338  if (tree.tree == NULL)
339  {
340  destroy_strtree(&tree);
341  return LW_FAILURE;
342  }
343 
344  for (p = 0; p < num_geoms; p++)
345  {
346  if (lwgeom_is_empty(geoms[p]))
347  continue;
348 
349  dbscan_update_context(tree.tree, &cxt, geoms, p, eps);
350  for (i = 0; i < cxt.num_items_found; i++)
351  {
352  uint32_t q = *((uint32_t*) cxt.items_found[i]);
353 
354  if (UF_find(uf, p) != UF_find(uf, q))
355  {
356  double mindist = lwgeom_mindistance2d_tolerance(geoms[p], geoms[q], eps);
357  if (mindist == FLT_MAX)
358  {
359  success = LW_FAILURE;
360  break;
361  }
362 
363  if (mindist <= eps)
364  UF_union(uf, p, q);
365  }
366  }
367  }
368 
369  if (cxt.items_found)
370  lwfree(cxt.items_found);
371 
372  destroy_strtree(&tree);
373 
374  return success;
375 }
uint32_t num_items_found
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
#define LW_SUCCESS
Definition: liblwgeom.h:80
GEOSSTRtree * tree
#define LW_FAILURE
Definition: liblwgeom.h:79
unsigned int uint32_t
Definition: uthash.h:78
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
Definition: lwunionfind.c:61
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...
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
static void destroy_strtree(struct STRTree *tree)
Clean up STRTree after use.
static int dbscan_update_context(GEOSSTRtree *tree, struct QueryContext *cxt, LWGEOM **geoms, uint32_t p, double eps)
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)
Definition: lwunionfind.c:84
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:1346
Here is the call graph for this function:
Here is the caller graph for this function: