-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvaguegeom_pg.c
125 lines (101 loc) · 3.74 KB
/
vaguegeom_pg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**********************************************************************
*
* VagueGeometry - Vague Spatial Objects for PostgreSQL
* http://gbd.dc.ufscar.br/vaguegeometry/
*
* Copyright 2013-2016 Anderson Chaves Carniel <[email protected]>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU General Public Licence. See the COPYING file.
*
* Fully developed by Anderson Chaves Carniel
*
**********************************************************************/
/************************
*
* Basic functions executed by the PostgreSQL internal library to handle VagueGeometry objects.
*
*************************/
#include "util_pg.h"
#include "fmgr.h"
#include "lwgeom_pg.h" //because of convertions
/* basic functions for VAGUEGEOM */
Datum VG_setsrid(PG_FUNCTION_ARGS);
Datum VG_getsrid(PG_FUNCTION_ARGS);
Datum VG_gettype(PG_FUNCTION_ARGS);
Datum VG_pcunion(PG_FUNCTION_ARGS);
Datum VG_precompute(PG_FUNCTION_ARGS);
/* TO-DO define functions to capture the MBR of each element, the allextension inclusive */
/* set srid for kernel and conjecture */
PG_FUNCTION_INFO_V1(VG_setsrid);
Datum VG_setsrid(PG_FUNCTION_ARGS) {
VAGUEGEOMSERIALIZED *vgeom_serialized = (VAGUEGEOMSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
int32_t srid = PG_GETARG_INT32(1);
vgserialized_set_srid(vgeom_serialized, srid);
PG_FREE_IF_COPY(vgeom_serialized, 0);
PG_RETURN_POINTER(vgeom_serialized);
}
/* get srid */
PG_FUNCTION_INFO_V1(VG_getsrid);
Datum VG_getsrid(PG_FUNCTION_ARGS) {
VAGUEGEOMSERIALIZED *vgeom_serialized = (VAGUEGEOMSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
int32_t srid = vgserialized_get_srid(vgeom_serialized);
PG_FREE_IF_COPY(vgeom_serialized, 0);
PG_RETURN_INT32(srid);
}
PG_FUNCTION_INFO_V1(VG_gettype);
Datum VG_gettype(PG_FUNCTION_ARGS) {
VAGUEGEOMSERIALIZED *vg1;
char *type;
text *result;
vg1 = (VAGUEGEOMSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
type = vaguegeom_gettype_i(vgserialized_get_type(vg1));
/* Write to text and free */
result = cstring2text(type);
/* Return the text */
PG_FREE_IF_COPY(vg1, 0);
PG_RETURN_TEXT_P(result);
}
PG_FUNCTION_INFO_V1(VG_pcunion);
Datum VG_pcunion(PG_FUNCTION_ARGS) {
VAGUEGEOMSERIALIZED *vg1;
vg1 = (VAGUEGEOMSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
if(HAS_PUNION(vg1->flags)) {
PG_FREE_IF_COPY(vg1, 0);
PG_RETURN_BOOL(TRUE);
} else {
PG_FREE_IF_COPY(vg1, 0);
PG_RETURN_BOOL(FALSE);
}
}
PG_FUNCTION_INFO_V1(VG_precompute);
Datum VG_precompute(PG_FUNCTION_ARGS) {
VAGUEGEOMSERIALIZED *vgeom_serialized = (VAGUEGEOMSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* TO-DO create specific functions in vaguegeom_serialize to do it */
if(PG_GETARG_BOOL(1) && !HAS_PUNION(vgeom_serialized->flags)) {
VAGUEGEOMSERIALIZED *result;
VAGUEGEOM *vgeom;
vgeom = serialization_to_vaguegeom(vgeom_serialized);
valid_convertion_vaguegeom(vgeom);
FLAGS_SET_PUNION(vgeom->flags, 1);
vgeom->allextension = lwgeom_union(vgeom->kernel, vgeom->conjecture);
result = vgeometry_serialize(vgeom);
vaguegeom_free(vgeom);
PG_FREE_IF_COPY(vgeom_serialized, 0);
PG_RETURN_POINTER(result);
} else if(!PG_GETARG_BOOL(1) && HAS_PUNION(vgeom_serialized->flags)) {
VAGUEGEOMSERIALIZED *result;
VAGUEGEOM *vgeom;
vgeom = serialization_to_vaguegeom(vgeom_serialized);
valid_convertion_vaguegeom(vgeom);
FLAGS_SET_PUNION(vgeom->flags, 0);
vgeom->allextension = NULL;
result = vgeometry_serialize(vgeom);
vaguegeom_free(vgeom);
PG_FREE_IF_COPY(vgeom_serialized, 0);
PG_RETURN_POINTER(result);
} else {
PG_FREE_IF_COPY(vgeom_serialized, 0);
PG_RETURN_POINTER(vgeom_serialized);
}
}