PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ST_ClusterIntersectingWin()

Datum ST_ClusterIntersectingWin ( PG_FUNCTION_ARGS  )

Definition at line 289 of file lwgeom_window.c.

290 {
291  WindowObject win_obj = PG_WINDOW_OBJECT();
292  uint32_t row = WinGetCurrentPosition(win_obj);
293  uint32_t ngeoms = WinGetPartitionRowCount(win_obj);
294  cluster_context* context = fetch_cluster_context(win_obj, ngeoms);
295 
296  if (row == 0) /* beginning of the partition; do all of the work now */
297  {
298  uint32_t i;
299  uint32_t* result_ids;
300  GEOSGeometry** geoms = lwalloc(ngeoms * sizeof(GEOSGeometry*));
301  UNIONFIND* uf = UF_create(ngeoms);
302 
303  context->is_error = LW_TRUE; /* until proven otherwise */
304 
305  initGEOS(lwpgnotice, lwgeom_geos_error);
306 
307  for (i = 0; i < ngeoms; i++)
308  {
309  bool geom_is_null;
310  geoms[i] = read_geos_from_partition(win_obj, i, &geom_is_null);
311  context->clusters[i].is_null = geom_is_null;
312 
313  if (!geoms[i])
314  {
315  lwpgerror("Error reading geometry.");
316  PG_RETURN_NULL();
317  }
318  }
319 
320  if (union_intersecting_pairs(geoms, ngeoms, uf) == LW_SUCCESS)
321  context->is_error = LW_FALSE;
322 
323  for (i = 0; i < ngeoms; i++)
324  {
325  GEOSGeom_destroy(geoms[i]);
326  }
327  lwfree(geoms);
328 
329  if (context->is_error)
330  {
331  UF_destroy(uf);
332  lwpgerror("Error during clustering");
333  PG_RETURN_NULL();
334  }
335 
336  result_ids = UF_get_collapsed_cluster_ids(uf, NULL);
337  for (i = 0; i < ngeoms; i++)
338  {
339  context->clusters[i].cluster_id = result_ids[i];
340  }
341 
342  lwfree(result_ids);
343  UF_destroy(uf);
344  }
345 
346  if (context->clusters[row].is_null)
347  PG_RETURN_NULL();
348 
349  PG_RETURN_INT32(context->clusters[row].cluster_id);
350 }
void lwgeom_geos_error(const char *fmt,...)
int union_intersecting_pairs(GEOSGeometry **geoms, uint32_t num_geoms, UNIONFIND *uf)
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_SUCCESS
Definition: liblwgeom.h:97
void lwfree(void *mem)
Definition: lwutil.c:248
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
static GEOSGeometry * read_geos_from_partition(WindowObject win_obj, uint32_t i, bool *is_null)
Definition: lwgeom_window.c:90
static cluster_context * fetch_cluster_context(WindowObject win_obj, uint32_t ngeoms)
Definition: lwgeom_window.c:64
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
Definition: lwunionfind.c:146
void UF_destroy(UNIONFIND *uf)
Definition: lwunionfind.c:54
UNIONFIND * UF_create(uint32_t N)
Definition: lwunionfind.c:35
cluster_entry clusters[1]
Definition: lwgeom_window.c:60
uint32_t cluster_id
Definition: lwgeom_window.c:51
char is_null
Definition: lwgeom_window.c:52

References cluster_entry::cluster_id, cluster_context::clusters, fetch_cluster_context(), cluster_context::is_error, cluster_entry::is_null, LW_FALSE, LW_SUCCESS, LW_TRUE, lwalloc(), lwfree(), lwgeom_geos_error(), read_geos_from_partition(), UF_create(), UF_destroy(), UF_get_collapsed_cluster_ids(), and union_intersecting_pairs().

Here is the call graph for this function: