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

◆ 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 320 of file lwgeom_geos_cluster.c.

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