PostGIS  2.5.0dev-r@@SVN_REVISION@@
geography_btree.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 2009 Paul Ramsey <pramsey@cleverelephant.ca>
22  *
23  **********************************************************************/
24 
25 
26 #include "postgres.h"
27 #include "access/hash.h"
28 
29 #include "../postgis_config.h"
30 
31 #include "liblwgeom.h" /* For standard geometry types. */
32 #include "liblwgeom_internal.h" /* For FP comparators. */
33 #include "lwgeom_pg.h" /* For debugging macros. */
34 #include "gserialized_gist.h"
35 #include "geography.h" /* For utility functions. */
36 
37 Datum geography_lt(PG_FUNCTION_ARGS);
38 Datum geography_le(PG_FUNCTION_ARGS);
39 Datum geography_eq(PG_FUNCTION_ARGS);
40 Datum geography_ge(PG_FUNCTION_ARGS);
41 Datum geography_gt(PG_FUNCTION_ARGS);
42 Datum geography_cmp(PG_FUNCTION_ARGS);
43 
44 /*
45 ** BTree support function. Based on two geographies return true if
46 ** they are "less than" and false otherwise.
47 */
49 Datum geography_lt(PG_FUNCTION_ARGS)
50 {
51  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
52  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
53  int cmp = gserialized_cmp(g1, g2);
54  if (cmp < 0)
55  PG_RETURN_BOOL(true);
56  else
57  PG_RETURN_BOOL(false);
58 }
59 
60 /*
61 ** BTree support function. Based on two geographies return true if
62 ** they are "less than or equal" and false otherwise.
63 */
65 Datum geography_le(PG_FUNCTION_ARGS)
66 {
67  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
68  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
69  int cmp = gserialized_cmp(g1, g2);
70  if (cmp <= 0)
71  PG_RETURN_BOOL(true);
72  else
73  PG_RETURN_BOOL(false);
74 }
75 
76 /*
77 ** BTree support function. Based on two geographies return true if
78 ** they are "greater than" and false otherwise.
79 */
81 Datum geography_gt(PG_FUNCTION_ARGS)
82 {
83  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
84  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
85  int cmp = gserialized_cmp(g1, g2);
86  if (cmp > 0)
87  PG_RETURN_BOOL(true);
88  else
89  PG_RETURN_BOOL(false);
90 }
91 
92 /*
93 ** BTree support function. Based on two geographies return true if
94 ** they are "greater than or equal" and false otherwise.
95 */
97 Datum geography_ge(PG_FUNCTION_ARGS)
98 {
99  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
100  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
101  int cmp = gserialized_cmp(g1, g2);
102  if (cmp >= 0)
103  PG_RETURN_BOOL(true);
104  else
105  PG_RETURN_BOOL(false);
106 }
107 
108 /*
109 ** BTree support function. Based on two geographies return true if
110 ** they are "equal" and false otherwise.
111 */
113 Datum geography_eq(PG_FUNCTION_ARGS)
114 {
115  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
116  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
117  int cmp = gserialized_cmp(g1, g2);
118  if (cmp == 0)
119  PG_RETURN_BOOL(true);
120  else
121  PG_RETURN_BOOL(false);
122 }
123 
124 /*
125 ** BTree support function. Based on two geographies return true if
126 ** they are "equal" and false otherwise.
127 */
129 Datum geography_cmp(PG_FUNCTION_ARGS)
130 {
131  GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
132  GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
133  PG_RETURN_INT32(gserialized_cmp(g1, g2));
134 }
int gserialized_cmp(const GSERIALIZED *g1, const GSERIALIZED *g2)
Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same"...
Definition: g_serialized.c:293
Datum geography_eq(PG_FUNCTION_ARGS)
Datum geography_gt(PG_FUNCTION_ARGS)
Datum geography_le(PG_FUNCTION_ARGS)
Datum geography_ge(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(geography_lt)
Datum geography_lt(PG_FUNCTION_ARGS)
Datum geography_cmp(PG_FUNCTION_ARGS)
This library is the generic geometry handling section of PostGIS.