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"
70 MemoryContext aggcontext, old;
74 Datum argType = get_fn_expr_argtype(fcinfo->flinfo, 1);
75 double gridSize = -1.0;
77 if (argType == InvalidOid)
79 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
80 errmsg(
"could not determine input data type")));
82 if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
85 elog(ERROR,
"%s called in non-aggregate context", __func__);
89 if ( PG_ARGISNULL(0) )
98 for (
int i = 0; i < n; i++)
100 Datum argument = PG_GETARG_DATUM(i+2);
101 Oid dataOid = get_fn_expr_argtype(fcinfo->flinfo, i+2);
102 old = MemoryContextSwitchTo(aggcontext);
103 state->
data[i] = datumCopy(argument, get_typbyval(dataOid), get_typlen(dataOid));
104 MemoryContextSwitchTo(old);
112 if (!PG_ARGISNULL(1))
113 gser = PG_GETARG_GSERIALIZED_P(1);
115 if (PG_NARGS()>2 && !PG_ARGISNULL(2))
117 gridSize = PG_GETARG_FLOAT8(2);
123 old = MemoryContextSwitchTo(aggcontext);
131 state->
geoms = list_make1(geom);
133 MemoryContextSwitchTo(old);
135 PG_RETURN_POINTER(state);
161 Assert(fcinfo->context &&
162 (IsA(fcinfo->context, AggState) ||
163 IsA(fcinfo->context, WindowAggState))
167 get_typlenbyvalalign(state->
geomOid, &elmlen, &elmbyval, &elmalign);
168 nelems = list_length(state->
geoms);
172 elems = palloc(nelems *
sizeof(Datum));
173 nulls = palloc(nelems *
sizeof(
bool));
175 foreach (l, state->
geoms)
178 Datum elem = (Datum)0;
183 elem = PointerGetDatum(gser);
196 arr = construct_md_array(elems, nulls, 1, dims, lbs, state->
geomOid,
197 elmlen, elmbyval, elmalign);
199 return PointerGetDatum(arr);
212 Datum geometry_array = 0;
238 Datum geometry_array = 0;
263 Datum geometry_array = 0;
288 Datum geometry_array = 0;
312 Datum geometry_array = 0;
321 elog(ERROR,
"Tolerance not defined");
340 #if POSTGIS_PGSQL_VERSION < 120
341 FunctionCallInfoData fcinfo;
345 InitFunctionCallInfoData(fcinfo, NULL, 1, InvalidOid, NULL, NULL);
348 fcinfo.arg[0] = arg1;
349 fcinfo.argnull[0] =
false;
351 result = (*func) (&fcinfo);
359 LOCAL_FCINFO(fcinfo, 1);
362 InitFunctionCallInfoData(*fcinfo, NULL, 1, InvalidOid, NULL, NULL);
364 fcinfo->args[0].value = arg1;
365 fcinfo->args[0].isnull =
false;
384 #if POSTGIS_PGSQL_VERSION < 120
385 FunctionCallInfoData fcinfo;
388 InitFunctionCallInfoData(fcinfo, NULL, 2, InvalidOid, NULL, NULL);
390 fcinfo.arg[0] = arg1;
391 fcinfo.arg[1] = arg2;
392 fcinfo.argnull[0] =
false;
393 fcinfo.argnull[1] =
false;
395 result = (*func) (&fcinfo);
403 LOCAL_FCINFO(fcinfo, 2);
406 InitFunctionCallInfoData(*fcinfo, NULL, 2, InvalidOid, NULL, NULL);
408 fcinfo->args[0].value = arg1;
409 fcinfo->args[1].value = arg2;
410 fcinfo->args[0].isnull =
false;
411 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 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 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]