85 WindowObject win_obj = PG_WINDOW_OBJECT();
86 uint32_t row = WinGetCurrentPosition(win_obj);
87 uint32_t ngeoms = WinGetPartitionRowCount(win_obj);
95 char* is_in_cluster = NULL;
97 bool tolerance_is_null;
98 bool minpoints_is_null;
99 Datum tolerance_datum = WinGetFuncArgCurrent(win_obj, 1, &tolerance_is_null);
100 Datum minpoints_datum = WinGetFuncArgCurrent(win_obj, 2, &minpoints_is_null);
101 double tolerance = DatumGetFloat8(tolerance_datum);
102 int minpoints = DatumGetInt32(minpoints_datum);
107 if (tolerance_is_null || tolerance < 0)
109 lwpgerror(
"Tolerance must be a positive number", tolerance);
112 if (minpoints_is_null || minpoints < 0)
114 lwpgerror(
"Minpoints must be a positive number", minpoints);
120 for (i = 0; i < ngeoms; i++)
126 lwpgerror(
"Error reading geometry.");
131 if (
union_dbscan(geoms, ngeoms, uf, tolerance, minpoints, minpoints > 1 ? &is_in_cluster : NULL) ==
LW_SUCCESS)
134 for (i = 0; i < ngeoms; i++)
145 lwpgerror(
"Error during clustering");
150 for (i = 0; i < ngeoms; i++)
152 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 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)
dbscan_cluster_result cluster_assignments[1]