29 #include "access/tupmacs.h"
30 #include "utils/datum.h"
31 #include "utils/array.h"
32 #include "utils/lsyscache.h"
34 #include "../postgis_config.h"
38 #include "lwgeom_pg.h"
39 #include "lwgeom_transform.h"
71 MemoryContext aggcontext, old;
75 Datum argType = get_fn_expr_argtype(fcinfo->flinfo, 1);
76 double gridSize = -1.0;
78 if (argType == InvalidOid)
80 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
81 errmsg(
"could not determine input data type")));
83 if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
86 elog(ERROR,
"%s called in non-aggregate context", __func__);
90 if ( PG_ARGISNULL(0) )
99 for (
int i = 0; i < n; i++)
101 Datum argument = PG_GETARG_DATUM(i+2);
102 Oid dataOid = get_fn_expr_argtype(fcinfo->flinfo, i+2);
103 old = MemoryContextSwitchTo(aggcontext);
104 state->
data[i] = datumCopy(argument, get_typbyval(dataOid), get_typlen(dataOid));
105 MemoryContextSwitchTo(old);
113 if (!PG_ARGISNULL(1))
114 gser = PG_GETARG_GSERIALIZED_P(1);
116 if (PG_NARGS()>2 && !PG_ARGISNULL(2))
118 gridSize = PG_GETARG_FLOAT8(2);
124 old = MemoryContextSwitchTo(aggcontext);
132 state->
geoms = list_make1(geom);
134 MemoryContextSwitchTo(old);
136 PG_RETURN_POINTER(state);
162 Assert(fcinfo->context &&
163 (IsA(fcinfo->context, AggState) ||
164 IsA(fcinfo->context, WindowAggState))
168 get_typlenbyvalalign(state->
geomOid, &elmlen, &elmbyval, &elmalign);
169 nelems = list_length(state->
geoms);
173 elems = palloc(nelems *
sizeof(Datum));
174 nulls = palloc(nelems *
sizeof(
bool));
176 foreach (l, state->
geoms)
179 Datum elem = (Datum)0;
184 elem = PointerGetDatum(gser);
197 arr = construct_md_array(elems, nulls, 1, dims, lbs, state->
geomOid,
198 elmlen, elmbyval, elmalign);
200 return PointerGetDatum(arr);
213 Datum geometry_array = 0;
239 Datum geometry_array = 0;
264 Datum geometry_array = 0;
289 Datum geometry_array = 0;
313 Datum geometry_array = 0;
322 elog(ERROR,
"Tolerance not defined");
346 Datum geometry_array = 0;
369 LOCAL_FCINFO(fcinfo, 1);
372 InitFunctionCallInfoData(*fcinfo, NULL, 1, InvalidOid, NULL, NULL);
374 fcinfo->args[0].value = arg1;
375 fcinfo->args[0].isnull =
false;
393 LOCAL_FCINFO(fcinfo, 2);
396 InitFunctionCallInfoData(*fcinfo, NULL, 2, InvalidOid, NULL, NULL);
398 fcinfo->args[0].value = arg1;
399 fcinfo->args[1].value = arg2;
400 fcinfo->args[0].isnull =
false;
401 fcinfo->args[1].isnull =
false;
char result[OUT_DOUBLE_BUFFER_SIZE]
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
This library is the generic geometry handling section of PostGIS.
Datum polygonize_garray(PG_FUNCTION_ARGS)
Datum pgis_geometry_makeline_finalfn(PG_FUNCTION_ARGS)
Datum pgis_geometry_polygonize_finalfn(PG_FUNCTION_ARGS)
Datum cluster_within_distance_garray(PG_FUNCTION_ARGS)
Datum pgis_accum_finalfn(CollectionBuildState *state, MemoryContext mctx, FunctionCallInfo fcinfo)
Datum ST_CoverageUnion(PG_FUNCTION_ARGS)
Datum pgis_geometry_collect_finalfn(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pgis_geometry_accum_transfn)
The transfer function builds a List of LWGEOM* allocated in the aggregate memory context.
Datum PGISDirectFunctionCall1(PGFunction func, Datum arg1)
A modified version of PostgreSQL's DirectFunctionCall1 which allows NULL results; this is required fo...
Datum pgis_geometry_clusterintersecting_finalfn(PG_FUNCTION_ARGS)
Datum PGISDirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2)
A modified version of PostgreSQL's DirectFunctionCall2 which allows NULL results; this is required fo...
Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
Datum pgis_geometry_clusterwithin_finalfn(PG_FUNCTION_ARGS)
Datum pgis_geometry_coverageunion_finalfn(PG_FUNCTION_ARGS)
Datum clusterintersecting_garray(PG_FUNCTION_ARGS)
Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
Datum pgis_geometry_accum_transfn(PG_FUNCTION_ARGS)
Datum pgis_union_geometry_array(PG_FUNCTION_ARGS)
#define CollectionBuildStateDataSize
To pass the internal state of our collection between the transfn and finalfn we need to wrap it into ...
Datum data[CollectionBuildStateDataSize]