121 WindowObject win_obj = PG_WINDOW_OBJECT();
122 uint32_t row = WinGetCurrentPosition(win_obj);
123 uint32_t ngeoms = WinGetPartitionRowCount(win_obj);
129 uint32_t* result_ids;
131 char* is_in_cluster = NULL;
133 bool tolerance_is_null;
134 bool minpoints_is_null;
135 Datum tolerance_datum = WinGetFuncArgCurrent(win_obj, 1, &tolerance_is_null);
136 Datum minpoints_datum = WinGetFuncArgCurrent(win_obj, 2, &minpoints_is_null);
137 double tolerance = DatumGetFloat8(tolerance_datum);
138 int minpoints = DatumGetInt32(minpoints_datum);
143 if (tolerance_is_null || tolerance < 0)
145 lwpgerror(
"Tolerance must be a positive number", tolerance);
148 if (minpoints_is_null || minpoints < 0)
150 lwpgerror(
"Minpoints must be a positive number", minpoints);
156 for (i = 0; i < ngeoms; i++)
164 lwpgerror(
"Error reading geometry.");
169 if (
union_dbscan(geoms, ngeoms, uf, tolerance, minpoints, minpoints > 1 ? &is_in_cluster : NULL) ==
LW_SUCCESS)
172 for (i = 0; i < ngeoms; i++)
183 lwpgerror(
"Error during clustering");
188 for (i = 0; i < ngeoms; i++)
190 if (minpoints > 1 && !is_in_cluster[i])
void lwgeom_geos_error(const char *fmt,...)
int union_dbscan(LWGEOM **geoms, uint32_t num_geoms, UNIONFIND *uf, double eps, uint32_t min_points, char **is_in_cluster_ret)
void lwgeom_free(LWGEOM *geom)
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static cluster_context * fetch_cluster_context(WindowObject win_obj, uint32_t ngeoms)
static LWGEOM * read_lwgeom_from_partition(WindowObject win_obj, uint32_t i, bool *is_null)
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
void UF_destroy(UNIONFIND *uf)
UNIONFIND * UF_create(uint32_t N)
cluster_entry clusters[1]