568 MemoryContext aggcontext;
569 MemoryContext oldcontext;
571 bool skiparg =
FALSE;
584 if (!AggCheckCallContext(fcinfo, &aggcontext)) {
587 "RASTER_summaryStats_transfn: Cannot be called in a non-aggregate context" 593 oldcontext = MemoryContextSwitchTo(aggcontext);
595 if (PG_ARGISNULL(0)) {
600 MemoryContextSwitchTo(oldcontext);
603 "RASTER_summaryStats_transfn: Cannot allocate memory for state variable" 617 if (!PG_ARGISNULL(1)) {
619 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
623 if (raster == NULL) {
626 PG_FREE_IF_COPY(pgraster, 1);
628 MemoryContextSwitchTo(oldcontext);
629 elog(ERROR,
"RASTER_summaryStats_transfn: Cannot deserialize raster");
645 for (i = 2; i < nargs; i++) {
649 calltype = get_fn_expr_argtype(fcinfo->flinfo, i);
653 (calltype == INT2OID || calltype == INT4OID) &&
656 if (calltype == INT2OID)
665 if (raster != NULL) {
667 PG_FREE_IF_COPY(pgraster, 1);
670 MemoryContextSwitchTo(oldcontext);
673 "RASTER_summaryStats_transfn: Invalid band index (must use 1-based). Returning NULL" 680 calltype == BOOLOID && (
688 (calltype == FLOAT4OID || calltype == FLOAT8OID) &&
691 if (calltype == FLOAT4OID)
692 state->
sample = PG_GETARG_FLOAT4(i);
694 state->
sample = PG_GETARG_FLOAT8(i);
700 if (raster != NULL) {
702 PG_FREE_IF_COPY(pgraster, 1);
705 MemoryContextSwitchTo(oldcontext);
708 "Invalid sample percentage (must be between 0 and 1). Returning NULL" 719 if (raster != NULL) {
721 PG_FREE_IF_COPY(pgraster, 1);
724 MemoryContextSwitchTo(oldcontext);
727 "RASTER_summaryStats_transfn: Unknown function parameter at index %d",
737 if (PG_ARGISNULL(1)) {
739 MemoryContextSwitchTo(oldcontext);
740 PG_RETURN_POINTER(state);
748 "Raster does not have band at index %d. Skipping raster",
753 PG_FREE_IF_COPY(pgraster, 1);
755 MemoryContextSwitchTo(oldcontext);
756 PG_RETURN_POINTER(state);
763 NOTICE,
"Cannot find band at index %d. Skipping raster",
768 PG_FREE_IF_COPY(pgraster, 1);
770 MemoryContextSwitchTo(oldcontext);
771 PG_RETURN_POINTER(state);
778 &(state->
cK), &(state->
cM), &(state->
cQ)
783 PG_FREE_IF_COPY(pgraster, 1);
788 "Cannot compute summary statistics for band at index %d. Returning NULL",
794 MemoryContextSwitchTo(oldcontext);
798 if (stats->
count > 0) {
822 MemoryContextSwitchTo(oldcontext);
826 PG_RETURN_POINTER(state);
static rtpg_summarystats_arg rtpg_summarystats_arg_init()
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.
struct rtpg_summarystats_arg_t * rtpg_summarystats_arg
#define POSTGIS_RT_DEBUGF(level, msg,...)
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.
bool exclude_nodata_value
static void rtpg_summarystats_arg_destroy(rtpg_summarystats_arg arg)
#define POSTGIS_RT_DEBUG(level, msg)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.