84{
85 WindowObject win_obj = PG_WINDOW_OBJECT();
86 uint32_t row = WinGetCurrentPosition(win_obj);
87 uint32_t ngeoms = WinGetPartitionRowCount(win_obj);
89
90 if (row == 0)
91 {
92 uint32_t i;
93 uint32_t* result_ids;
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);
103
105
106
107 if (tolerance_is_null || tolerance < 0)
108 {
109 lwpgerror("Tolerance must be a positive number", tolerance);
110 PG_RETURN_NULL();
111 }
112 if (minpoints_is_null || minpoints < 0)
113 {
114 lwpgerror("Minpoints must be a positive number", minpoints);
115 }
116
120 for (i = 0; i < ngeoms; i++)
121 {
123
124 if (!geoms[i]) {
125
126 lwpgerror("Error reading geometry.");
127 PG_RETURN_NULL();
128 }
129 }
130
131 if (
union_dbscan(geoms, ngeoms, uf, tolerance, minpoints, minpoints > 1 ? &is_in_cluster : NULL) ==
LW_SUCCESS)
133
134 for (i = 0; i < ngeoms; i++)
135 {
137 }
139
141 {
143 if (is_in_cluster)
145 lwpgerror("Error during clustering");
146 PG_RETURN_NULL();
147 }
148
150 for (i = 0; i < ngeoms; i++)
151 {
152 if (minpoints > 1 && !is_in_cluster[i])
153 {
155 }
156 else
157 {
159 }
160 }
161
164 }
165
167 PG_RETURN_NULL();
168
170}
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)
void UF_destroy(UNIONFIND *uf)
UNIONFIND * UF_create(uint32_t N)
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
dbscan_cluster_result cluster_assignments[1]