78 int32_t bandindex = 1;
79 bool exclude_nodata_value =
TRUE;
93 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
97 PG_FREE_IF_COPY(pgraster, 0);
98 elog(ERROR,
"RASTER_summaryStats: Cannot deserialize raster");
103 if (!PG_ARGISNULL(1))
104 bandindex = PG_GETARG_INT32(1);
106 if (bandindex < 1 || bandindex > num_bands) {
107 elog(NOTICE,
"Invalid band index (must use 1-based). Returning NULL");
109 PG_FREE_IF_COPY(pgraster, 0);
114 if (!PG_ARGISNULL(2))
115 exclude_nodata_value = PG_GETARG_BOOL(2);
118 if (!PG_ARGISNULL(3)) {
119 sample = PG_GETARG_FLOAT8(3);
120 if (sample < 0 || sample > 1) {
121 elog(NOTICE,
"Invalid sample percentage (must be between 0 and 1). Returning NULL");
123 PG_FREE_IF_COPY(pgraster, 0);
126 else if (
FLT_EQ(sample, 0.0))
135 elog(NOTICE,
"Cannot find band at index %d. Returning NULL", bandindex);
137 PG_FREE_IF_COPY(pgraster, 0);
145 PG_FREE_IF_COPY(pgraster, 0);
147 elog(NOTICE,
"Cannot compute summary statistics for band at index %d. Returning NULL", bandindex);
152 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
154 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
156 "function returning record called in context " 157 "that cannot accept type record" 162 BlessTupleDesc(tupdesc);
166 values[0] = Int64GetDatum(stats->
count);
167 if (stats->
count > 0) {
168 values[1] = Float8GetDatum(stats->
sum);
169 values[2] = Float8GetDatum(stats->
mean);
170 values[3] = Float8GetDatum(stats->
stddev);
171 values[4] = Float8GetDatum(stats->
min);
172 values[5] = Float8GetDatum(stats->
max);
183 tuple = heap_form_tuple(tupdesc, values, nulls);
186 result = HeapTupleGetDatum(tuple);
191 PG_RETURN_DATUM(result);
int rt_raster_get_num_bands(rt_raster raster)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
void rt_band_destroy(rt_band band)
Destroy a raster band.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a band.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.