H3C HEALPix library for PostgreSQL  (version 1.2)
h3c.sql.in
1 
2 CREATE OR REPLACE FUNCTION h3c_version() RETURNS float
3  AS 'MODULE_PATHNAME', 'pgh3c_version'
4  LANGUAGE C IMMUTABLE STRICT;
5 CREATE OR REPLACE FUNCTION h3c_ang2ipix(double precision, double precision, integer)
6  RETURNS bigint
7  AS 'MODULE_PATHNAME', 'pgh3c_ang2ipix'
8  LANGUAGE C IMMUTABLE STRICT;
9 COMMENT ON FUNCTION h3c_ang2ipix (double precision, double precision, integer)
10  IS 'Function converting Ra and Dec to the H3C ipix value';
11 
12 CREATE OR REPLACE FUNCTION h3c_ang2ipix(double precision, double precision)
13  RETURNS bigint
14  AS 'MODULE_PATHNAME', 'pgh3c_ang2ipix_default'
15  LANGUAGE C IMMUTABLE STRICT;
16 COMMENT ON FUNCTION h3c_ang2ipix (double precision, double precision)
17  IS 'Function converting Ra and Dec to the H3C ipix value';
18 
19 CREATE OR REPLACE FUNCTION h3c_ipix2ang(ipix bigint, integer)
20  RETURNS double precision[]
21  AS 'MODULE_PATHNAME', 'pgh3c_ipix2ang'
22  LANGUAGE C IMMUTABLE STRICT;
23 COMMENT ON FUNCTION h3c_ipix2ang (bigint, integer)
24  IS 'Function converting the H3C ipix value to Ra, Dec (the center)';
25 
26 CREATE OR REPLACE FUNCTION h3c_ipix2ang(ipix bigint)
27  RETURNS double precision[]
28  AS 'MODULE_PATHNAME', 'pgh3c_ipix2ang_default'
29  LANGUAGE C IMMUTABLE STRICT;
30 COMMENT ON FUNCTION h3c_ipix2ang(bigint)
31  IS 'Function converting the H3C ipix value to Ra, Dec (the center)';
32 
33 
34 CREATE OR REPLACE FUNCTION h3c_disk_ipix(IN double precision, IN double precision, IN double precision, IN integer,
35  OUT f bigint)
36  RETURNS SETOF bigint
37  AS 'MODULE_PATHNAME', 'pgh3c_disk_ipix'
38  LANGUAGE C IMMUTABLE STRICT;
39 
40 CREATE OR REPLACE FUNCTION h3c_disk_ipix(IN double precision, IN double precision, IN double precision,
41  OUT f bigint)
42  RETURNS SETOF bigint
43  AS 'MODULE_PATHNAME', 'pgh3c_disk_ipix_default'
44  LANGUAGE C IMMUTABLE STRICT;
45 
46 /*
47 CREATE OR REPLACE FUNCTION h3c_pixarea(ipix bigint, depth int)
48  RETURNS double precision
49  AS 'MODULE_PATHNAME', 'pgh3c_pixarea'
50  LANGUAGE C IMMUTABLE STRICT;
51 COMMENT ON FUNCTION h3c_pixarea (bigint, int )
52  IS 'Function returning the area of the pixel containing ipix being located at certain depth in the quadtree';
53 
54 CREATE OR REPLACE FUNCTION h3c_ipixcenter(ra double precision, decl double precision, int)
55  RETURNS bigint
56  AS
57  'SELECT ((h3c_ang2ipix($1,$2))>>((2*$3))<<((2*$3))) +
58  ((1::bigint)<<(2*($3-1))) -1'
59  LANGUAGE SQL;
60 */
61 
62 CREATE OR REPLACE FUNCTION h3c_dist(ra1 double precision, dec1 double precision,
63  ra2 double precision, dec2 double precision)
64  RETURNS double precision
65  AS 'MODULE_PATHNAME', 'pgh3c_dist'
66  LANGUAGE C IMMUTABLE STRICT;
67 COMMENT ON FUNCTION h3c_dist(double precision, double precision,
68  double precision, double precision)
69  IS 'Function h3c_dist(ra1, dec1, ra2, dec2) computing the distance between points (ra1, dec1) and (ra2, dec2)';
70 
71 CREATE OR REPLACE FUNCTION h3c_sindist(double precision, double precision,
72  double precision, double precision)
73  RETURNS double precision
74  AS 'MODULE_PATHNAME', 'pgh3c_sindist'
75  LANGUAGE C IMMUTABLE STRICT;
76 
77 
78 CREATE OR REPLACE FUNCTION h3c_radial_query_it(IN double precision, IN double precision, IN double precision, IN integer, IN integer,
79  OUT f bigint)
80  RETURNS bigint
81  AS 'MODULE_PATHNAME', 'pgh3c_radial_query_it'
82  LANGUAGE C IMMUTABLE STRICT;
83 
84 CREATE OR REPLACE FUNCTION h3c_radial_query_it(IN double precision, IN double precision, IN double precision, IN integer,
85  OUT f bigint)
86  RETURNS bigint
87  AS 'MODULE_PATHNAME', 'pgh3c_radial_query_it_default'
88  LANGUAGE C IMMUTABLE STRICT;
89 
90 /*CREATE OR REPLACE FUNCTION h3c_radial_query2(
91  double precision, double precision,
92  double precision, double precision, double precision)
93  returns boolean as 'SELECT
94 (h3c_ang2ipix($1,$2) in (select h3c_disk_ipix($3,$4,$5)))
95 AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
96 ' LANGUAGE SQL IMMUTABLE; index is not took */
97 
98 CREATE OR REPLACE FUNCTION h3c_nearby_it(IN double precision, IN double precision, IN double precision, IN integer, IN integer,
99  OUT f bigint)
100  RETURNS bigint
101  AS 'MODULE_PATHNAME', 'pgh3c_nearby_it'
102  LANGUAGE C IMMUTABLE STRICT;
103 
104 CREATE OR REPLACE FUNCTION h3c_nearby_it(IN double precision, IN double precision, IN double precision, IN integer,
105  OUT f bigint)
106  RETURNS bigint
107  AS 'MODULE_PATHNAME', 'pgh3c_nearby_it_default'
108  LANGUAGE C IMMUTABLE STRICT;
109 
110 CREATE OR REPLACE FUNCTION h3c_join_symetric(
111  double precision, double precision,
112  double precision, double precision, double precision, integer)
113  returns boolean as 'SELECT((
114 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,0,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,1,$6)) OR
115 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,2,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,3,$6)) OR
116 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,4,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,5,$6)) OR
117 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,6,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,7,$6))
118 )
119  AND (
120 (h3c_ang2ipix($1,$2,$6)>=h3c_nearby_it($3,$4,$5,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_nearby_it($3,$4,$5,1,$6)) OR
121 (h3c_ang2ipix($1,$2,$6)>=h3c_nearby_it($3,$4,$5,2,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_nearby_it($3,$4,$5,3,$6)) OR
122 (h3c_ang2ipix($1,$2,$6)>=h3c_nearby_it($3,$4,$5,4,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_nearby_it($3,$4,$5,5,$6)) OR
123 (h3c_ang2ipix($1,$2,$6)>=h3c_nearby_it($3,$4,$5,6,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_nearby_it($3,$4,$5,7,$6))
124 )
125  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
126 )
127 ' LANGUAGE SQL IMMUTABLE;
128 
129 CREATE OR REPLACE FUNCTION h3c_join_symetric(
130  double precision, double precision,
131  double precision, double precision, double precision)
132  returns boolean as 'SELECT((
133 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,0) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,1)) OR
134 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,2) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,3)) OR
135 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,4) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,5)) OR
136 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,6) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,7))
137 )
138 AND (
139 (h3c_ang2ipix($1,$2)>=h3c_nearby_it($3,$4,$5,0) AND h3c_ang2ipix($1,$2)<=h3c_nearby_it($3,$4,$5,1)) OR
140 (h3c_ang2ipix($1,$2)>=h3c_nearby_it($3,$4,$5,2) AND h3c_ang2ipix($1,$2)<=h3c_nearby_it($3,$4,$5,3)) OR
141 (h3c_ang2ipix($1,$2)>=h3c_nearby_it($3,$4,$5,4) AND h3c_ang2ipix($1,$2)<=h3c_nearby_it($3,$4,$5,5)) OR
142 (h3c_ang2ipix($1,$2)>=h3c_nearby_it($3,$4,$5,6) AND h3c_ang2ipix($1,$2)<=h3c_nearby_it($3,$4,$5,7))
143 )
144  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
145 )
146 ' LANGUAGE SQL IMMUTABLE;
147 
148 CREATE OR REPLACE FUNCTION h3c_join(
149  double precision, double precision,
150  double precision, double precision, double precision, integer)
151  returns boolean as 'SELECT((
152 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,0,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,1,$6)) OR
153 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,2,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,3,$6)) OR
154 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,4,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,5,$6)) OR
155 (h3c_ang2ipix($3,$4,$6)>=h3c_nearby_it($1,$2,$5,6,$6) AND h3c_ang2ipix($3,$4,$6)<=h3c_nearby_it($1,$2,$5,7,$6))
156 )
157  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
158 )
159 ' LANGUAGE SQL IMMUTABLE;
160 
161 CREATE OR REPLACE FUNCTION h3c_join(
162  double precision, double precision,
163  double precision, double precision, double precision)
164  returns boolean as 'SELECT((
165 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,0) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,1)) OR
166 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,2) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,3)) OR
167 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,4) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,5)) OR
168 (h3c_ang2ipix($3,$4)>=h3c_nearby_it($1,$2,$5,6) AND h3c_ang2ipix($3,$4)<=h3c_nearby_it($1,$2,$5,7))
169 )
170  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
171 )
172 ' LANGUAGE SQL IMMUTABLE;
173 
174 CREATE OR REPLACE FUNCTION h3c_dist_ipix(bigint, bigint)
175  RETURNS double precision
176  AS 'MODULE_PATHNAME', 'pgh3c_dist_ipix'
177  LANGUAGE C IMMUTABLE STRICT;
178 
179 CREATE OR REPLACE FUNCTION h3c_radial_query(
180  double precision, double precision,
181  double precision, double precision, double precision)
182  returns boolean as 'SELECT((
183 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,1)) OR
184 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,2) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,3)) OR
185 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,4) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,5)) OR
186 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,6) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,7)) OR
187 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,8) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,9)) OR
188 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,10) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,11)) OR
189 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,12) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,13)) OR
190 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,14) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,15)) OR
191 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,16) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,17)) OR
192 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,18) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,19)) OR
193 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,20) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,21)) OR
194 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,22) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,23)) OR
195 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,24) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,25)) OR
196 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,26) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,27)) OR
197 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,28) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,29)) OR
198 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,30) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,31)) OR
199 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,32) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,33)) OR
200 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,34) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,35)) OR
201 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,36) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,37)) OR
202 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,38) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,39)) OR
203 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,40) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,41)) OR
204 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,42) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,43)) OR
205 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,44) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,45)) OR
206 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,46) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,47)) OR
207 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,48) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,49)) OR
208 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,50) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,51)) OR
209 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,52) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,53)) OR
210 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,54) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,55)) OR
211 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,56) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,57)) OR
212 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,58) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,59)) OR
213 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,60) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,61)) OR
214 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,62) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,63)) OR
215 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,64) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,65)) OR
216 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,66) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,67)) OR
217 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,68) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,69)) OR
218 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,70) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,71)) OR
219 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,72) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,73)) OR
220 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,74) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,75)) OR
221 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,76) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,77)) OR
222 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,78) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,79)) OR
223 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,80) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,81)) OR
224 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,82) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,83)) OR
225 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,84) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,85)) OR
226 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,86) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,87)) OR
227 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,88) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,89)) OR
228 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,90) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,91)) OR
229 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,92) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,93)) OR
230 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,94) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,95)) OR
231 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,96) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,97)) OR
232 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,98) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,99))
233 ) /*OR (
234 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,0,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,1,0)) OR
235 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,2,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,3,0)) OR
236 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,4,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,5,0)) OR
237 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,6,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,7,0)) OR
238 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,8,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,9,0)) OR
239 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,10,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,11,0)) OR
240 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,12,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,13,0)) OR
241 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,14,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,15,0)) OR
242 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,16,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,17,0)) OR
243 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,18,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,19,0)) OR
244 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,20,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,21,0)) OR
245 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,22,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,23,0)) OR
246 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,24,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,25,0)) OR
247 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,26,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,27,0)) OR
248 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,28,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,29,0)) OR
249 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,30,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,31,0)) OR
250 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,32,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,33,0)) OR
251 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,34,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,35,0)) OR
252 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,36,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,37,0)) OR
253 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,38,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,39,0)) OR
254 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,40,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,41,0)) OR
255 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,42,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,43,0)) OR
256 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,44,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,45,0)) OR
257 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,46,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,47,0)) OR
258 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,48,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,49,0)) OR
259 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,50,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,51,0)) OR
260 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,52,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,53,0)) OR
261 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,54,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,55,0)) OR
262 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,56,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,57,0)) OR
263 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,58,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,59,0)) OR
264 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,60,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,61,0)) OR
265 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,62,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,63,0)) OR
266 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,64,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,65,0)) OR
267 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,66,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,67,0)) OR
268 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,68,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,69,0)) OR
269 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,70,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,71,0)) OR
270 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,72,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,73,0)) OR
271 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,74,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,75,0)) OR
272 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,76,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,77,0)) OR
273 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,78,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,79,0)) OR
274 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,80,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,81,0)) OR
275 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,82,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,83,0)) OR
276 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,84,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,85,0)) OR
277 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,86,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,87,0)) OR
278 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,88,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,89,0)) OR
279 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,90,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,91,0)) OR
280 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,92,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,93,0)) OR
281 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,94,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,95,0)) OR
282 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,96,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,97,0)) OR
283 (h3c_ang2ipix($1,$2)>=h3c_radial_query_it($3,$4,$5,98,0) AND h3c_ang2ipix($1,$2)<=h3c_radial_query_it($3,$4,$5,99,0))
284 )*/
285  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
286 )
287 ' LANGUAGE SQL IMMUTABLE;
288 
289 CREATE OR REPLACE FUNCTION h3c_radial_query(
290  double precision, double precision,
291  double precision, double precision, double precision, integer)
292  returns boolean as 'SELECT((
293 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,1,$6)) OR
294 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,2,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,3,$6)) OR
295 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,4,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,5,$6)) OR
296 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,6,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,7,$6)) OR
297 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,8,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,9,$6)) OR
298 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,10,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,11,$6)) OR
299 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,12,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,13,$6)) OR
300 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,14,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,15,$6)) OR
301 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,16,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,17,$6)) OR
302 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,18,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,19,$6)) OR
303 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,20,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,21,$6)) OR
304 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,22,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,23,$6)) OR
305 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,24,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,25,$6)) OR
306 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,26,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,27,$6)) OR
307 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,28,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,29,$6)) OR
308 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,30,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,31,$6)) OR
309 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,32,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,33,$6)) OR
310 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,34,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,35,$6)) OR
311 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,36,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,37,$6)) OR
312 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,38,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,39,$6)) OR
313 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,40,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,41,$6)) OR
314 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,42,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,43,$6)) OR
315 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,44,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,45,$6)) OR
316 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,46,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,47,$6)) OR
317 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,48,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,49,$6)) OR
318 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,50,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,51,$6)) OR
319 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,52,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,53,$6)) OR
320 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,54,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,55,$6)) OR
321 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,56,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,57,$6)) OR
322 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,58,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,59,$6)) OR
323 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,60,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,61,$6)) OR
324 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,62,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,63,$6)) OR
325 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,64,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,65,$6)) OR
326 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,66,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,67,$6)) OR
327 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,68,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,69,$6)) OR
328 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,70,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,71,$6)) OR
329 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,72,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,73,$6)) OR
330 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,74,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,75,$6)) OR
331 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,76,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,77,$6)) OR
332 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,78,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,79,$6)) OR
333 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,80,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,81,$6)) OR
334 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,82,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,83,$6)) OR
335 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,84,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,85,$6)) OR
336 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,86,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,87,$6)) OR
337 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,88,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,89,$6)) OR
338 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,90,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,91,$6)) OR
339 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,92,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,93,$6)) OR
340 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,94,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,95,$6)) OR
341 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,96,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,97,$6)) OR
342 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,98,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,99,$6))
343 ) /*OR (
344 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,0,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,1,0,$6)) OR
345 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,2,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,3,0,$6)) OR
346 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,4,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,5,0,$6)) OR
347 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,6,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,7,0,$6)) OR
348 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,8,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,9,0,$6)) OR
349 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,10,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,11,0,$6)) OR
350 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,12,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,13,0,$6)) OR
351 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,14,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,15,0,$6)) OR
352 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,16,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,17,0,$6)) OR
353 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,18,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,19,0,$6)) OR
354 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,20,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,21,0,$6)) OR
355 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,22,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,23,0,$6)) OR
356 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,24,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,25,0,$6)) OR
357 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,26,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,27,0,$6)) OR
358 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,28,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,29,0,$6)) OR
359 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,30,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,31,0,$6)) OR
360 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,32,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,33,0,$6)) OR
361 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,34,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,35,0,$6)) OR
362 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,36,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,37,0,$6)) OR
363 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,38,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,39,0,$6)) OR
364 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,40,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,41,0,$6)) OR
365 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,42,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,43,0,$6)) OR
366 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,44,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,45,0,$6)) OR
367 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,46,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,47,0,$6)) OR
368 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,48,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,49,0,$6)) OR
369 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,50,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,51,0,$6)) OR
370 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,52,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,53,0,$6)) OR
371 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,54,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,55,0,$6)) OR
372 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,56,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,57,0,$6)) OR
373 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,58,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,59,0,$6)) OR
374 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,60,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,61,0,$6)) OR
375 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,62,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,63,0,$6)) OR
376 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,64,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,65,0,$6)) OR
377 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,66,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,67,0,$6)) OR
378 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,68,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,69,0,$6)) OR
379 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,70,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,71,0,$6)) OR
380 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,72,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,73,0,$6)) OR
381 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,74,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,75,0,$6)) OR
382 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,76,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,77,0,$6)) OR
383 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,78,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,79,0,$6)) OR
384 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,80,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,81,0,$6)) OR
385 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,82,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,83,0,$6)) OR
386 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,84,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,85,0,$6)) OR
387 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,86,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,87,0,$6)) OR
388 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,88,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,89,0,$6)) OR
389 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,90,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,91,0,$6)) OR
390 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,92,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,93,0,$6)) OR
391 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,94,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,95,0,$6)) OR
392 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,96,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,97,0,$6)) OR
393 (h3c_ang2ipix($1,$2,$6)>=h3c_radial_query_it($3,$4,$5,98,0,$6) AND h3c_ang2ipix($1,$2,$6)<=h3c_radial_query_it($3,$4,$5,99,0,$6))
394 )*/
395  AND h3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)
396 )
397 ' LANGUAGE SQL IMMUTABLE;
398 
399 CREATE OR REPLACE FUNCTION h3c_radial_query(bigint,
400  double precision, double precision, double precision)
401  returns boolean as '
402 SELECT h3c_radial_query((h3c_ipix2ang($1))[1],(h3c_ipix2ang($1))[2],$2,$3,$4)
403 ' LANGUAGE SQL IMMUTABLE;
404 
405 CREATE OR REPLACE FUNCTION h3c_radial_query(bigint, bigint, double precision)
406  returns boolean as '
407 SELECT h3c_radial_query((h3c_ipix2ang($1))[1],(h3c_ipix2ang($1))[2],(h3c_ipix2ang($2))[1],(h3c_ipix2ang($2))[2],$3)
408 ' LANGUAGE SQL IMMUTABLE;
409 
410 CREATE OR REPLACE FUNCTION h3c_in_ellipse(ra0 double precision, dec0 double precision,
411  ra_ell double precision, dec_ell double precision,
412  maj_ax double precision, axis_ratio double precision,
413  pa double precision)
414  RETURNS boolean
415  AS 'MODULE_PATHNAME', 'pgh3c_in_ellipse'
416  LANGUAGE C IMMUTABLE STRICT;
417 
418 /*
419 
420 CREATE OR REPLACE FUNCTION h3c_ellipse_nearby_it(double precision, double precision,
421  double precision, double precision, double precision, integer)
422  RETURNS bigint
423  AS 'MODULE_PATHNAME', 'pgh3c_ellipse_nearby_it'
424  LANGUAGE C IMMUTABLE STRICT;
425 
426 CREATE OR REPLACE FUNCTION h3c_in_ellipse(ra0 double precision, dec0 double precision,
427  ra_ell double precision, dec_ell double precision,
428  maj_ax double precision, axis_ratio double precision,
429  pa double precision)
430  RETURNS boolean
431  AS 'MODULE_PATHNAME', 'pgh3c_in_ellipse'
432  LANGUAGE C IMMUTABLE STRICT;
433 
434 
435 CREATE OR REPLACE FUNCTION h3c_ellipse_query_it(ra_ell double precision,
436  dec_ell double precision,
437  majax double precision,
438  axis_ratio double precision,
439  PA double precision,
440  iteration integer,
441  full_flag integer)
442  RETURNS bigint
443  AS 'MODULE_PATHNAME', 'pgh3c_ellipse_query_it'
444 LANGUAGE C IMMUTABLE STRICT;
445 
446 */
447 
448 CREATE OR REPLACE FUNCTION h3c_poly_query_it(double precision[], integer, integer)
449  RETURNS bigint
450  AS 'MODULE_PATHNAME', 'pgh3c_poly_query_it'
451  LANGUAGE C IMMUTABLE STRICT;
452 
453 CREATE OR REPLACE FUNCTION h3c_poly_query_it(double precision[], integer)
454  RETURNS bigint
455  AS 'MODULE_PATHNAME', 'pgh3c_poly_query_it_default'
456  LANGUAGE C IMMUTABLE STRICT;
457 
458 CREATE OR REPLACE FUNCTION h3c_in_poly(double precision, double precision,
459  double precision[])
460  RETURNS boolean
461  AS 'MODULE_PATHNAME', 'pgh3c_in_poly_convex'
462  LANGUAGE C IMMUTABLE STRICT;
463 
464 CREATE OR REPLACE FUNCTION h3c_in_poly_convex(double precision, double precision,
465  double precision[])
466  RETURNS boolean
467  AS 'MODULE_PATHNAME', 'pgh3c_in_poly_convex'
468  LANGUAGE C IMMUTABLE STRICT;
469 /*
470 CREATE OR REPLACE FUNCTION h3c_in_box(double precision, double precision,
471  double precision, double precision,
472  double precision, double precision)
473  RETURNS boolean
474  AS 'MODULE_PATHNAME', 'pgh3c_in_box'
475  LANGUAGE C IMMUTABLE STRICT;
476 */
477 CREATE OR REPLACE FUNCTION h3c_poly_center(double precision[])
478  RETURNS double precision[]
479  AS 'MODULE_PATHNAME', 'pgh3c_poly_center'
480  LANGUAGE C IMMUTABLE STRICT;
481 
482 CREATE OR REPLACE FUNCTION h3c_circle_intersect_poly(double precision, double precision, double precision, double precision[])
483  RETURNS boolean
484  AS 'MODULE_PATHNAME', 'pgh3c_circle_intersect_poly'
485  LANGUAGE C IMMUTABLE STRICT;
486 
487 CREATE OR REPLACE FUNCTION h3c_poly_intersect_poly(double precision[], double precision[])
488  RETURNS boolean
489  AS 'MODULE_PATHNAME', 'pgh3c_poly_intersect_poly'
490  LANGUAGE C IMMUTABLE STRICT;
491 
492 /*CREATE OR REPLACE FUNCTION h3c_box_query_it(double precision, double precision, double precision, double precision, integer, integer)
493  RETURNS bigint
494  AS 'MODULE_PATHNAME', 'pgh3c_box_query_it'
495  LANGUAGE C IMMUTABLE STRICT;
496 
497 CREATE OR REPLACE FUNCTION h3c_box_query_it(double precision, double precision, double precision, double precision, integer)
498  RETURNS bigint
499  AS 'MODULE_PATHNAME', 'pgh3c_box_query_it_default'
500  LANGUAGE C IMMUTABLE STRICT;
501 */
502 CREATE OR REPLACE FUNCTION h3c_box_to_poly(double precision, double precision, double precision, double precision)
503  RETURNS double precision[]
504  AS 'MODULE_PATHNAME', 'pgh3c_box_to_poly'
505  LANGUAGE C IMMUTABLE STRICT;
506 
507 /*
508 CREATE OR REPLACE FUNCTION h3c_ellipse_join(leftra double precision, leftdec double precision,
509  rightra double precision, rightdec double precision,
510  majoraxis double precision, axisratio double precision,
511  pa double precision)
512  RETURNS boolean AS
513 '
514 SELECT (((h3c_ang2ipix($3,$4)>=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,0))) AND (h3c_ang2ipix($3,$4)<=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,1))))
515  OR ((h3c_ang2ipix($3,$4)>=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,2))) AND (h3c_ang2ipix($3,$4)<=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,3))))
516  OR ((h3c_ang2ipix($3,$4)>=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,4))) AND (h3c_ang2ipix($3,$4)<=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,5))))
517  OR ((h3c_ang2ipix($3,$4)>=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,6))) AND (h3c_ang2ipix($3,$4)<=(h3c_ellipse_nearby_it($1,$2,$5,$6,$7,7)))))
518  AND h3c_in_ellipse($3,$4,$1,$2,$5,$6,$7)
519 ' LANGUAGE SQL IMMUTABLE;
520 
521 CREATE OR REPLACE FUNCTION h3c_ellipse_query(
522  ra_col double precision, dec_col double precision,
523  ra_ell double precision, dec_ell double precision,
524  majax double precision, axis_ratio double precision,
525  PA double precision)
526  RETURNS boolean AS
527 'SELECT (
528 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,0,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,1,1)) OR
529 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,2,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,3,1)) OR
530 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,4,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,5,1)) OR
531 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,6,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,7,1)) OR
532 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,8,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,9,1)) OR
533 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,10,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,11,1)) OR
534 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,12,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,13,1)) OR
535 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,14,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,15,1)) OR
536 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,16,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,17,1)) OR
537 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,18,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,19,1)) OR
538 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,20,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,21,1)) OR
539 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,22,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,23,1)) OR
540 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,24,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,25,1)) OR
541 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,26,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,27,1)) OR
542 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,28,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,29,1)) OR
543 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,30,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,31,1)) OR
544 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,32,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,33,1)) OR
545 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,34,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,35,1)) OR
546 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,36,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,37,1)) OR
547 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,38,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,39,1)) OR
548 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,40,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,41,1)) OR
549 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,42,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,43,1)) OR
550 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,44,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,45,1)) OR
551 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,46,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,47,1)) OR
552 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,48,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,49,1)) OR
553 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,50,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,51,1)) OR
554 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,52,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,53,1)) OR
555 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,54,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,55,1)) OR
556 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,56,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,57,1)) OR
557 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,58,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,59,1)) OR
558 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,60,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,61,1)) OR
559 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,62,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,63,1)) OR
560 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,64,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,65,1)) OR
561 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,66,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,67,1)) OR
562 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,68,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,69,1)) OR
563 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,70,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,71,1)) OR
564 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,72,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,73,1)) OR
565 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,74,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,75,1)) OR
566 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,76,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,77,1)) OR
567 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,78,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,79,1)) OR
568 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,80,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,81,1)) OR
569 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,82,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,83,1)) OR
570 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,84,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,85,1)) OR
571 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,86,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,87,1)) OR
572 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,88,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,89,1)) OR
573 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,90,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,91,1)) OR
574 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,92,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,93,1)) OR
575 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,94,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,95,1)) OR
576 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,96,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,97,1)) OR
577 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,98,1) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,99,1)) OR
578 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,0,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,1,0)) OR
579 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,2,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,3,0)) OR
580 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,4,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,5,0)) OR
581 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,6,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,7,0)) OR
582 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,8,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,9,0)) OR
583 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,10,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,11,0)) OR
584 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,12,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,13,0)) OR
585 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,14,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,15,0)) OR
586 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,16,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,17,0)) OR
587 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,18,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,19,0)) OR
588 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,20,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,21,0)) OR
589 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,22,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,23,0)) OR
590 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,24,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,25,0)) OR
591 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,26,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,27,0)) OR
592 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,28,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,29,0)) OR
593 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,30,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,31,0)) OR
594 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,32,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,33,0)) OR
595 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,34,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,35,0)) OR
596 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,36,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,37,0)) OR
597 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,38,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,39,0)) OR
598 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,40,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,41,0)) OR
599 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,42,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,43,0)) OR
600 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,44,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,45,0)) OR
601 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,46,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,47,0)) OR
602 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,48,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,49,0)) OR
603 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,50,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,51,0)) OR
604 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,52,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,53,0)) OR
605 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,54,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,55,0)) OR
606 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,56,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,57,0)) OR
607 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,58,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,59,0)) OR
608 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,60,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,61,0)) OR
609 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,62,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,63,0)) OR
610 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,64,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,65,0)) OR
611 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,66,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,67,0)) OR
612 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,68,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,69,0)) OR
613 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,70,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,71,0)) OR
614 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,72,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,73,0)) OR
615 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,74,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,75,0)) OR
616 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,76,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,77,0)) OR
617 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,78,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,79,0)) OR
618 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,80,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,81,0)) OR
619 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,82,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,83,0)) OR
620 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,84,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,85,0)) OR
621 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,86,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,87,0)) OR
622 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,88,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,89,0)) OR
623 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,90,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,91,0)) OR
624 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,92,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,93,0)) OR
625 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,94,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,95,0)) OR
626 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,96,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,97,0)) OR
627 (h3c_ang2ipix($1,$2)>=h3c_ellipse_query_it($3,$4,$5,$6,$7,98,0) AND h3c_ang2ipix($1,$2)<h3c_ellipse_query_it($3,$4,$5,$6,$7,99,0))
628 )
629 AND h3c_in_ellipse($1,$2,$3,$4,$5,$6,$7)
630 ' LANGUAGE SQL IMMUTABLE;
631 
632 
633 
634 */
635 CREATE OR REPLACE FUNCTION h3c_poly_query(
636  double precision, double precision,
637  double precision[])
638  returns boolean as 'SELECT (
639 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,0) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,1)) OR
640 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,2) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,3)) OR
641 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,4) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,5)) OR
642 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,6) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,7)) OR
643 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,8) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,9)) OR
644 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,10) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,11)) OR
645 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,12) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,13)) OR
646 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,14) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,15)) OR
647 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,16) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,17)) OR
648 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,18) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,19)) OR
649 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,20) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,21)) OR
650 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,22) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,23)) OR
651 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,24) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,25)) OR
652 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,26) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,27)) OR
653 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,28) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,29)) OR
654 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,30) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,31)) OR
655 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,32) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,33)) OR
656 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,34) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,35)) OR
657 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,36) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,37)) OR
658 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,38) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,39)) OR
659 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,40) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,41)) OR
660 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,42) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,43)) OR
661 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,44) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,45)) OR
662 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,46) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,47)) OR
663 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,48) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,49)) OR
664 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,50) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,51)) OR
665 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,52) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,53)) OR
666 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,54) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,55)) OR
667 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,56) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,57)) OR
668 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,58) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,59)) OR
669 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,60) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,61)) OR
670 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,62) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,63)) OR
671 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,64) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,65)) OR
672 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,66) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,67)) OR
673 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,68) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,69)) OR
674 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,70) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,71)) OR
675 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,72) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,73)) OR
676 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,74) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,75)) OR
677 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,76) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,77)) OR
678 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,78) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,79)) OR
679 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,80) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,81)) OR
680 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,82) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,83)) OR
681 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,84) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,85)) OR
682 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,86) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,87)) OR
683 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,88) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,89)) OR
684 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,90) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,91)) OR
685 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,92) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,93)) OR
686 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,94) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,95)) OR
687 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,96) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,97)) OR
688 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,98) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,99))
689 )
690 AND h3c_in_poly_convex($1,$2,$3);
691 ' LANGUAGE SQL IMMUTABLE;
692 
693 CREATE OR REPLACE FUNCTION h3c_poly_query(
694  double precision, double precision,
695  double precision[], integer)
696  returns boolean as 'SELECT (
697 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,0,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,1,$4)) OR
698 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,2,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,3,$4)) OR
699 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,4,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,5,$4)) OR
700 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,6,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,7,$4)) OR
701 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,8,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,9,$4)) OR
702 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,10,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,11,$4)) OR
703 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,12,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,13,$4)) OR
704 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,14,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,15,$4)) OR
705 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,16,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,17,$4)) OR
706 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,18,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,19,$4)) OR
707 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,20,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,21,$4)) OR
708 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,22,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,23,$4)) OR
709 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,24,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,25,$4)) OR
710 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,26,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,27,$4)) OR
711 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,28,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,29,$4)) OR
712 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,30,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,31,$4)) OR
713 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,32,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,33,$4)) OR
714 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,34,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,35,$4)) OR
715 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,36,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,37,$4)) OR
716 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,38,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,39,$4)) OR
717 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,40,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,41,$4)) OR
718 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,42,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,43,$4)) OR
719 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,44,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,45,$4)) OR
720 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,46,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,47,$4)) OR
721 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,48,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,49,$4)) OR
722 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,50,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,51,$4)) OR
723 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,52,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,53,$4)) OR
724 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,54,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,55,$4)) OR
725 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,56,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,57,$4)) OR
726 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,58,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,59,$4)) OR
727 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,60,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,61,$4)) OR
728 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,62,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,63,$4)) OR
729 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,64,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,65,$4)) OR
730 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,66,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,67,$4)) OR
731 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,68,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,69,$4)) OR
732 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,70,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,71,$4)) OR
733 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,72,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,73,$4)) OR
734 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,74,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,75,$4)) OR
735 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,76,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,77,$4)) OR
736 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,78,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,79,$4)) OR
737 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,80,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,81,$4)) OR
738 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,82,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,83,$4)) OR
739 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,84,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,85,$4)) OR
740 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,86,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,87,$4)) OR
741 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,88,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,89,$4)) OR
742 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,90,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,91,$4)) OR
743 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,92,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,93,$4)) OR
744 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,94,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,95,$4)) OR
745 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,96,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,97,$4)) OR
746 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,98,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,99,$4))
747 )
748 AND h3c_in_poly_convex($1,$2,$3);
749 ' LANGUAGE SQL IMMUTABLE;
750 
751 CREATE OR REPLACE FUNCTION h3c_poly_convex_query(
752  double precision, double precision,
753  double precision[])
754  returns boolean as 'SELECT (
755 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,0) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,1)) OR
756 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,2) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,3)) OR
757 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,4) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,5)) OR
758 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,6) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,7)) OR
759 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,8) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,9)) OR
760 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,10) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,11)) OR
761 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,12) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,13)) OR
762 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,14) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,15)) OR
763 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,16) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,17)) OR
764 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,18) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,19)) OR
765 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,20) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,21)) OR
766 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,22) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,23)) OR
767 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,24) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,25)) OR
768 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,26) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,27)) OR
769 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,28) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,29)) OR
770 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,30) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,31)) OR
771 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,32) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,33)) OR
772 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,34) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,35)) OR
773 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,36) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,37)) OR
774 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,38) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,39)) OR
775 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,40) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,41)) OR
776 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,42) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,43)) OR
777 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,44) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,45)) OR
778 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,46) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,47)) OR
779 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,48) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,49)) OR
780 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,50) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,51)) OR
781 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,52) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,53)) OR
782 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,54) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,55)) OR
783 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,56) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,57)) OR
784 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,58) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,59)) OR
785 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,60) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,61)) OR
786 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,62) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,63)) OR
787 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,64) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,65)) OR
788 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,66) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,67)) OR
789 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,68) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,69)) OR
790 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,70) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,71)) OR
791 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,72) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,73)) OR
792 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,74) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,75)) OR
793 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,76) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,77)) OR
794 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,78) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,79)) OR
795 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,80) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,81)) OR
796 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,82) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,83)) OR
797 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,84) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,85)) OR
798 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,86) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,87)) OR
799 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,88) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,89)) OR
800 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,90) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,91)) OR
801 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,92) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,93)) OR
802 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,94) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,95)) OR
803 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,96) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,97)) OR
804 (h3c_ang2ipix($1,$2)>=h3c_poly_query_it($3,98) AND h3c_ang2ipix($1,$2)<=h3c_poly_query_it($3,99))
805 )
806 AND h3c_in_poly_convex($1,$2,$3)
807 ' LANGUAGE SQL IMMUTABLE;
808 
809 CREATE OR REPLACE FUNCTION h3c_poly_convex_query(
810  double precision, double precision,
811  double precision[], integer)
812  returns boolean as 'SELECT (
813 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,0,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,1,$4)) OR
814 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,2,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,3,$4)) OR
815 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,4,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,5,$4)) OR
816 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,6,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,7,$4)) OR
817 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,8,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,9,$4)) OR
818 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,10,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,11,$4)) OR
819 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,12,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,13,$4)) OR
820 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,14,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,15,$4)) OR
821 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,16,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,17,$4)) OR
822 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,18,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,19,$4)) OR
823 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,20,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,21,$4)) OR
824 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,22,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,23,$4)) OR
825 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,24,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,25,$4)) OR
826 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,26,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,27,$4)) OR
827 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,28,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,29,$4)) OR
828 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,30,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,31,$4)) OR
829 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,32,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,33,$4)) OR
830 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,34,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,35,$4)) OR
831 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,36,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,37,$4)) OR
832 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,38,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,39,$4)) OR
833 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,40,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,41,$4)) OR
834 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,42,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,43,$4)) OR
835 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,44,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,45,$4)) OR
836 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,46,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,47,$4)) OR
837 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,48,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,49,$4)) OR
838 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,50,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,51,$4)) OR
839 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,52,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,53,$4)) OR
840 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,54,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,55,$4)) OR
841 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,56,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,57,$4)) OR
842 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,58,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,59,$4)) OR
843 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,60,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,61,$4)) OR
844 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,62,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,63,$4)) OR
845 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,64,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,65,$4)) OR
846 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,66,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,67,$4)) OR
847 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,68,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,69,$4)) OR
848 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,70,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,71,$4)) OR
849 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,72,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,73,$4)) OR
850 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,74,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,75,$4)) OR
851 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,76,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,77,$4)) OR
852 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,78,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,79,$4)) OR
853 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,80,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,81,$4)) OR
854 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,82,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,83,$4)) OR
855 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,84,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,85,$4)) OR
856 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,86,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,87,$4)) OR
857 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,88,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,89,$4)) OR
858 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,90,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,91,$4)) OR
859 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,92,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,93,$4)) OR
860 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,94,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,95,$4)) OR
861 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,96,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,97,$4)) OR
862 (h3c_ang2ipix($1,$2,$4)>=h3c_poly_query_it($3,98,$4) AND h3c_ang2ipix($1,$2,$4)<=h3c_poly_query_it($3,99,$4))
863 )
864 AND h3c_in_poly_convex($1,$2,$3)
865 ' LANGUAGE SQL IMMUTABLE;
866 
867 /*
868 CREATE OR REPLACE FUNCTION h3c_box_query(
869  double precision, double precision,
870  double precision, double precision,
871  double precision, double precision)
872  returns boolean as 'SELECT (
873 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,0) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,1)) OR
874 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,2) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,3)) OR
875 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,4) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,5)) OR
876 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,6) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,7)) OR
877 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,8) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,9)) OR
878 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,10) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,11)) OR
879 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,12) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,13)) OR
880 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,14) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,15)) OR
881 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,16) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,17)) OR
882 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,18) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,19)) OR
883 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,20) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,21)) OR
884 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,22) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,23)) OR
885 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,24) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,25)) OR
886 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,26) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,27)) OR
887 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,28) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,29)) OR
888 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,30) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,31)) OR
889 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,32) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,33)) OR
890 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,34) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,35)) OR
891 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,36) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,37)) OR
892 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,38) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,39)) OR
893 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,40) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,41)) OR
894 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,42) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,43)) OR
895 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,44) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,45)) OR
896 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,46) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,47)) OR
897 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,48) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,49)) OR
898 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,50) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,51)) OR
899 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,52) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,53)) OR
900 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,54) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,55)) OR
901 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,56) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,57)) OR
902 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,58) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,59)) OR
903 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,60) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,61)) OR
904 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,62) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,63)) OR
905 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,64) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,65)) OR
906 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,66) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,67)) OR
907 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,68) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,69)) OR
908 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,70) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,71)) OR
909 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,72) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,73)) OR
910 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,74) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,75)) OR
911 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,76) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,77)) OR
912 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,78) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,79)) OR
913 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,80) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,81)) OR
914 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,82) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,83)) OR
915 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,84) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,85)) OR
916 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,86) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,87)) OR
917 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,88) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,89)) OR
918 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,90) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,91)) OR
919 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,92) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,93)) OR
920 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,94) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,95)) OR
921 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,96) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,97)) OR
922 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,98) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,99))
923 )
924 AND h3c_in_box($1,$2,$3,$4,$5,$6)
925 ' LANGUAGE SQL IMMUTABLE;
926 
927 CREATE OR REPLACE FUNCTION h3c_box_query(
928  double precision, double precision,
929  double precision, double precision,
930  double precision, double precision, integer)
931  returns boolean as 'SELECT (
932 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,0,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,1,$7)) OR
933 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,2,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,3,$7)) OR
934 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,4,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,5,$7)) OR
935 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,6,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,7,$7)) OR
936 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,8,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,9,$7)) OR
937 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,10,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,11,$7)) OR
938 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,12,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,13,$7)) OR
939 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,14,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,15,$7)) OR
940 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,16,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,17,$7)) OR
941 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,18,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,19,$7)) OR
942 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,20,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,21,$7)) OR
943 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,22,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,23,$7)) OR
944 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,24,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,25,$7)) OR
945 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,26,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,27,$7)) OR
946 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,28,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,29,$7)) OR
947 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,30,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,31,$7)) OR
948 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,32,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,33,$7)) OR
949 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,34,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,35,$7)) OR
950 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,36,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,37,$7)) OR
951 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,38,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,39,$7)) OR
952 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,40,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,41,$7)) OR
953 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,42,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,43,$7)) OR
954 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,44,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,45,$7)) OR
955 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,46,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,47,$7)) OR
956 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,48,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,49,$7)) OR
957 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,50,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,51,$7)) OR
958 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,52,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,53,$7)) OR
959 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,54,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,55,$7)) OR
960 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,56,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,57,$7)) OR
961 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,58,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,59,$7)) OR
962 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,60,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,61,$7)) OR
963 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,62,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,63,$7)) OR
964 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,64,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,65,$7)) OR
965 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,66,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,67,$7)) OR
966 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,68,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,69,$7)) OR
967 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,70,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,71,$7)) OR
968 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,72,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,73,$7)) OR
969 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,74,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,75,$7)) OR
970 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,76,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,77,$7)) OR
971 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,78,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,79,$7)) OR
972 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,80,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,81,$7)) OR
973 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,82,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,83,$7)) OR
974 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,84,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,85,$7)) OR
975 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,86,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,87,$7)) OR
976 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,88,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,89,$7)) OR
977 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,90,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,91,$7)) OR
978 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,92,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,93,$7)) OR
979 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,94,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,95,$7)) OR
980 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,96,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,97,$7)) OR
981 (h3c_ang2ipix($1,$2)>=h3c_box_query_it($3,$4,$5,$6,98,$7) AND h3c_ang2ipix($1,$2)<=h3c_box_query_it($3,$4,$5,$6,99,$7))
982 )
983 AND h3c_in_box($1,$2,$3,$4,$5,$6)
984 ' LANGUAGE SQL IMMUTABLE;
985 */
986 
987 CREATE OR REPLACE FUNCTION h3c_circle_area(double precision)
988  RETURNS double precision
989  AS 'MODULE_PATHNAME', 'pgh3c_circle_area'
990  LANGUAGE C IMMUTABLE STRICT;
991 
992 CREATE OR REPLACE FUNCTION h3c_poly_area(double precision[])
993  RETURNS double precision
994  AS 'MODULE_PATHNAME', 'pgh3c_poly_area'
995  LANGUAGE C IMMUTABLE STRICT;
996 
997 
998 CREATE OR REPLACE FUNCTION h3c_ipix2default_it(bigint, integer, integer)
999  RETURNS bigint
1000  AS 'MODULE_PATHNAME', 'pgh3c_ipix2default_it'
1001  LANGUAGE C IMMUTABLE STRICT;
1002 
1003 CREATE OR REPLACE FUNCTION h3c_ipix_query(double precision, double precision, bigint, integer)
1004  RETURNS boolean AS 'SELECT
1005 h3c_ang2ipix($1,$2)>=h3c_ipix2default_it($3,$4,0) AND h3c_ang2ipix($1,$2)<=h3c_ipix2default_it($3,$4,1)
1006 ' LANGUAGE SQL IMMUTABLE;
1007 
1008 CREATE OR REPLACE FUNCTION h3c_nside_config()
1009  RETURNS bigint
1010  AS 'MODULE_PATHNAME', 'pgh3c_nside_config'
1011  LANGUAGE C IMMUTABLE STRICT;
1012 COMMENT ON FUNCTION h3c_nside_config ()
1013  IS 'GET default nside (use for indexation)';
1014