85 WindowObject win_obj = PG_WINDOW_OBJECT();
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])
dbscan_cluster_result cluster_assignments[1]
void UF_destroy(UNIONFIND *uf)
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)
void lwgeom_free(LWGEOM *geom)
int union_dbscan(LWGEOM **geoms, uint32_t num_geoms, UNIONFIND *uf, double eps, uint32_t min_points, char **is_in_cluster_ret)
void lwgeom_geos_error(const char *fmt,...)
#define LW_TRUE
Return types for functions with status returns.
UNIONFIND * UF_create(uint32_t N)
void * lwalloc(size_t size)
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)