PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ST_ClusterIntersectingWin()

Datum ST_ClusterIntersectingWin ( PG_FUNCTION_ARGS  )

Definition at line 288 of file lwgeom_window.c.

289 {
290  WindowObject win_obj = PG_WINDOW_OBJECT();
291  uint32_t row = WinGetCurrentPosition(win_obj);
292  uint32_t ngeoms = WinGetPartitionRowCount(win_obj);
293  cluster_context* context = fetch_cluster_context(win_obj, ngeoms);
294 
295  if (row == 0) /* beginning of the partition; do all of the work now */
296  {
297  uint32_t i;
298  uint32_t* result_ids;
299  GEOSGeometry** geoms = lwalloc(ngeoms * sizeof(GEOSGeometry*));
300  UNIONFIND* uf = UF_create(ngeoms);
301 
302  context->is_error = LW_TRUE; /* until proven otherwise */
303 
304  initGEOS(lwpgnotice, lwgeom_geos_error);
305 
306  for (i = 0; i < ngeoms; i++)
307  {
308  bool geom_is_null;
309  geoms[i] = read_geos_from_partition(win_obj, i, &geom_is_null);
310  context->clusters[i].is_null = geom_is_null;
311 
312  if (!geoms[i])
313  {
314  lwpgerror("Error reading geometry.");
315  PG_RETURN_NULL();
316  }
317  }
318 
319  if (union_intersecting_pairs(geoms, ngeoms, uf) == LW_SUCCESS)
320  context->is_error = LW_FALSE;
321 
322  for (i = 0; i < ngeoms; i++)
323  {
324  GEOSGeom_destroy(geoms[i]);
325  }
326  lwfree(geoms);
327 
328  if (context->is_error)
329  {
330  UF_destroy(uf);
331  lwpgerror("Error during clustering");
332  PG_RETURN_NULL();
333  }
334 
335  result_ids = UF_get_collapsed_cluster_ids(uf, NULL);
336  for (i = 0; i < ngeoms; i++)
337  {
338  context->clusters[i].cluster_id = result_ids[i];
339  }
340 
341  lwfree(result_ids);
342  UF_destroy(uf);
343  }
344 
345  if (context->clusters[row].is_null)
346  PG_RETURN_NULL();
347 
348  PG_RETURN_INT32(context->clusters[row].cluster_id);
349 }
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:242
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:89
static cluster_context * fetch_cluster_context(WindowObject win_obj, uint32_t ngeoms)
Definition: lwgeom_window.c:63
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:59
uint32_t cluster_id
Definition: lwgeom_window.c:50
char is_null
Definition: lwgeom_window.c:51

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: