PostGIS
3.0.6dev-r@@SVN_REVISION@@
lwgeom_out_geobuf.c
Go to the documentation of this file.
1
/**********************************************************************
2
*
3
* PostGIS - Spatial Types for PostgreSQL
4
* http://postgis.net
5
*
6
* PostGIS is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* PostGIS is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18
*
19
**********************************************************************
20
*
21
* Copyright (C) 2016-2017 Björn Harrtell <bjorn@wololo.org>
22
*
23
**********************************************************************/
24
25
#include "
geobuf.h
"
26
32
#include "postgres.h"
33
#include "utils/builtins.h"
34
#include "executor/spi.h"
35
36
#include "../postgis_config.h"
37
#include "lwgeom_pg.h"
38
#include "
lwgeom_log.h
"
39
#include "
liblwgeom.h
"
40
#include "
geobuf.h
"
41
45
PG_FUNCTION_INFO_V1
(
pgis_asgeobuf_transfn
);
46
Datum
pgis_asgeobuf_transfn
(PG_FUNCTION_ARGS)
47
{
48
#if ! (defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF)
49
elog(ERROR,
"ST_AsGeobuf: Missing libprotobuf-c >= version 1.1"
);
50
PG_RETURN_NULL();
51
#else
52
MemoryContext aggcontext, oldcontext;
53
struct
geobuf_agg_context
*ctx;
54
55
/* We need to initialize the internal cache to access it later via postgis_oid() */
56
postgis_initialize_cache(fcinfo);
57
58
if
(!AggCheckCallContext(fcinfo, &aggcontext))
59
elog(ERROR,
"pgis_asgeobuf_transfn: called in non-aggregate context"
);
60
oldcontext = MemoryContextSwitchTo(aggcontext);
61
62
if
(PG_ARGISNULL(0)) {
63
ctx = palloc(
sizeof
(*ctx));
64
65
ctx->
geom_name
= NULL;
66
if
(PG_NARGS() > 2 && !PG_ARGISNULL(2))
67
ctx->
geom_name
=
text_to_cstring
(PG_GETARG_TEXT_P(2));
68
geobuf_agg_init_context
(ctx);
69
}
else
{
70
ctx = (
struct
geobuf_agg_context
*) PG_GETARG_POINTER(0);
71
}
72
73
if
(!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
74
elog(ERROR,
"pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype"
);
75
76
/* Null input tuple => null result */
77
if
(PG_ARGISNULL(1)) {
78
PG_RETURN_NULL();
79
}
80
81
ctx->
row
= PG_GETARG_HEAPTUPLEHEADER(1);
82
83
geobuf_agg_transfn
(ctx);
84
MemoryContextSwitchTo(oldcontext);
85
PG_RETURN_POINTER(ctx);
86
#endif
87
}
88
92
PG_FUNCTION_INFO_V1
(
pgis_asgeobuf_finalfn
);
93
Datum
pgis_asgeobuf_finalfn
(PG_FUNCTION_ARGS)
94
{
95
#if ! (defined HAVE_LIBPROTOBUF && defined HAVE_GEOBUF)
96
elog(ERROR,
"ST_AsGeoBuf: Missing libprotobuf-c >= version 1.1"
);
97
PG_RETURN_NULL();
98
#else
99
uint8_t *buf;
100
struct
geobuf_agg_context
*ctx;
101
if
(!AggCheckCallContext(fcinfo, NULL))
102
elog(ERROR,
"pgis_asmvt_finalfn called in non-aggregate context"
);
103
104
if
(PG_ARGISNULL(0))
105
PG_RETURN_NULL();
106
107
ctx = (
struct
geobuf_agg_context
*) PG_GETARG_POINTER(0);
108
buf =
geobuf_agg_finalfn
(ctx);
109
PG_RETURN_BYTEA_P(buf);
110
#endif
111
}
geobuf_agg_finalfn
uint8_t * geobuf_agg_finalfn(struct geobuf_agg_context *ctx)
Finalize aggregation.
Definition:
geobuf.c:624
geobuf_agg_init_context
void geobuf_agg_init_context(struct geobuf_agg_context *ctx)
Initialize aggregation context.
Definition:
geobuf.c:541
geobuf_agg_transfn
void geobuf_agg_transfn(struct geobuf_agg_context *ctx)
Aggregation step.
Definition:
geobuf.c:578
geobuf.h
liblwgeom.h
This library is the generic geometry handling section of PostGIS.
lwgeom_log.h
pgis_asgeobuf_transfn
Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
Definition:
lwgeom_out_geobuf.c:46
PG_FUNCTION_INFO_V1
PG_FUNCTION_INFO_V1(pgis_asgeobuf_transfn)
Process input parameters and row data into state.
pgis_asgeobuf_finalfn
Datum pgis_asgeobuf_finalfn(PG_FUNCTION_ARGS)
Definition:
lwgeom_out_geobuf.c:93
text_to_cstring
char * text_to_cstring(const text *textptr)
geobuf_agg_context::row
HeapTupleHeader row
Definition:
geobuf.h:52
geobuf_agg_context::geom_name
char * geom_name
Definition:
geobuf.h:50
geobuf_agg_context
Definition:
geobuf.h:49
postgis
lwgeom_out_geobuf.c
Generated by
1.9.1