2095{
2096 Datum* result_array_data;
2097 ArrayType *array, *
result;
2098 int is3d = 0;
2099 uint32 nelems, nclusters, i;
2102 double tolerance;
2104
2105
2106 int16 elmlen;
2107 bool elmbyval;
2108 char elmalign;
2109
2110
2111 if (PG_ARGISNULL(0))
2112 PG_RETURN_NULL();
2113
2114 array = PG_GETARG_ARRAYTYPE_P(0);
2115
2116 tolerance = PG_GETARG_FLOAT8(1);
2117 if (tolerance < 0)
2118 {
2119 lwpgerror("Tolerance must be a positive number.");
2120 PG_RETURN_NULL();
2121 }
2122
2124
2125 POSTGIS_DEBUGF(3, "cluster_within_distance_garray: number of non-null elements: %d", nelems);
2126
2127 if ( nelems == 0 ) PG_RETURN_NULL();
2128
2129
2130
2131
2133
2135 if (!lw_inputs)
2136 {
2137 PG_RETURN_NULL();
2138 }
2139
2141 {
2142 elog(ERROR, "cluster_within: Error performing clustering");
2143 PG_RETURN_NULL();
2144 }
2145 pfree(lw_inputs);
2146
2147 if (!lw_results) PG_RETURN_NULL();
2148
2149 result_array_data = palloc(nclusters * sizeof(Datum));
2150 for (i=0; i<nclusters; ++i)
2151 {
2152 result_array_data[i] = PointerGetDatum(geometry_serialize(lw_results[i]));
2154 }
2156
2157 get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
2158 result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
2159
2161 {
2162 elog(ERROR, "clusterwithin: Error constructing return-array");
2163 PG_RETURN_NULL();
2164 }
2165
2166 PG_RETURN_POINTER(
result);
2167}
char result[OUT_DOUBLE_BUFFER_SIZE]
void lwgeom_geos_error(const char *fmt,...)
int cluster_within_distance(LWGEOM **geoms, uint32_t num_geoms, double tolerance, LWGEOM ***clusterGeoms, uint32_t *num_clusters)
Takes an array of LWGEOM* and constructs an array of LWGEOM*, where each element in the constructed a...
void lwgeom_free(LWGEOM *geom)
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM ** ARRAY2LWGEOM(ArrayType *array, uint32_t nelems, int *is3d, int *srid)
static uint32_t array_nelems_not_null(ArrayType *array)