pgLatLon

changeset 63:9771b81559c7

Fixed version numbers for new version 0.14
author jbe
date Tue Feb 11 01:59:04 2020 +0100 (5 months ago)
parents e1d42b91d826
children da23ebd9fd4c
files GNUmakefile README.html latlon--0.11--0.12.sql latlon--0.12--0.14.sql latlon--0.12.sql latlon--0.14.sql latlon.control
line diff
     1.1 --- a/GNUmakefile	Mon Feb 10 21:44:32 2020 +0100
     1.2 +++ b/GNUmakefile	Tue Feb 11 01:59:04 2020 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  EXTENSION = latlon
     1.5 -DATA = latlon--0.11--0.12.sql latlon--0.12.sql
     1.6 +DATA = latlon--0.12--0.14.sql latlon--0.14.sql
     1.7  MODULES = latlon-v0009
     1.8  
     1.9  PG_CONFIG = pg_config
     2.1 --- a/README.html	Mon Feb 10 21:44:32 2020 +0100
     2.2 +++ b/README.html	Tue Feb 11 01:59:04 2020 +0100
     2.3 @@ -1,5 +1,5 @@
     2.4 -<html><head><title>pgLatLon v0.13 documentation</title></head><body>
     2.5 -<h1>pgLatLon v0.13 documentation</h1>
     2.6 +<html><head><title>pgLatLon v0.14 documentation</title></head><body>
     2.7 +<h1>pgLatLon v0.14 documentation</h1>
     2.8  
     2.9  <p>pgLatLon is a spatial database extension for the PostgreSQL object-relational
    2.10  database management system providing geographic data types and spatial indexing
     3.1 --- a/latlon--0.11--0.12.sql	Mon Feb 10 21:44:32 2020 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,34 +0,0 @@
     3.4 -DROP OPERATOR <> (epoint, epoint);
     3.5 -DROP OPERATOR <> (ebox, ebox);
     3.6 -DROP OPERATOR <> (ecircle, ecircle);
     3.7 -
     3.8 -CREATE OPERATOR <> (
     3.9 -  leftarg = epoint,
    3.10 -  rightarg = epoint,
    3.11 -  procedure = epoint_btree_ne,
    3.12 -  commutator = <>,
    3.13 -  negator = =,
    3.14 -  restrict = neqsel,
    3.15 -  join = neqjoinsel
    3.16 -);
    3.17 -
    3.18 -CREATE OPERATOR <> (
    3.19 -  leftarg = ebox,
    3.20 -  rightarg = ebox,
    3.21 -  procedure = ebox_btree_ne,
    3.22 -  commutator = <>,
    3.23 -  negator = =,
    3.24 -  restrict = neqsel,
    3.25 -  join = neqjoinsel
    3.26 -);
    3.27 -
    3.28 -CREATE OPERATOR <> (
    3.29 -  leftarg = ecircle,
    3.30 -  rightarg = ecircle,
    3.31 -  procedure = ecircle_btree_ne,
    3.32 -  commutator = <>,
    3.33 -  negator = =,
    3.34 -  restrict = neqsel,
    3.35 -  join = neqjoinsel
    3.36 -);
    3.37 -
     5.1 --- a/latlon--0.12.sql	Mon Feb 10 21:44:32 2020 +0100
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,1717 +0,0 @@
     5.4 -
     5.5 -----------------------------------------
     5.6 --- forward declarations (shell types) --
     5.7 -----------------------------------------
     5.8 -
     5.9 -CREATE TYPE ekey_point;
    5.10 -CREATE TYPE ekey_area;
    5.11 -CREATE TYPE epoint;
    5.12 -CREATE TYPE epoint_with_sample_count;
    5.13 -CREATE TYPE ebox;
    5.14 -CREATE TYPE ecircle;
    5.15 -CREATE TYPE ecluster;
    5.16 -
    5.17 -
    5.18 -------------------------------------------------------------
    5.19 --- dummy input/output functions for dummy index key types --
    5.20 -------------------------------------------------------------
    5.21 -
    5.22 -CREATE FUNCTION ekey_point_in_dummy(cstring)
    5.23 -  RETURNS ekey_point
    5.24 -  LANGUAGE C IMMUTABLE STRICT
    5.25 -  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    5.26 -
    5.27 -CREATE FUNCTION ekey_point_out_dummy(ekey_point)
    5.28 -  RETURNS cstring
    5.29 -  LANGUAGE C IMMUTABLE STRICT
    5.30 -  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    5.31 -
    5.32 -CREATE FUNCTION ekey_area_in_dummy(cstring)
    5.33 -  RETURNS ekey_area
    5.34 -  LANGUAGE C IMMUTABLE STRICT
    5.35 -  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    5.36 -
    5.37 -CREATE FUNCTION ekey_area_out_dummy(ekey_area)
    5.38 -  RETURNS cstring
    5.39 -  LANGUAGE C IMMUTABLE STRICT
    5.40 -  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    5.41 -
    5.42 -
    5.43 ---------------------------
    5.44 --- text input functions --
    5.45 ---------------------------
    5.46 -
    5.47 -CREATE FUNCTION epoint_in(cstring)
    5.48 -  RETURNS epoint
    5.49 -  LANGUAGE C IMMUTABLE STRICT
    5.50 -  AS '$libdir/latlon-v0009', 'pgl_epoint_in';
    5.51 -
    5.52 -CREATE FUNCTION epoint_with_sample_count_in(cstring)
    5.53 -  RETURNS epoint_with_sample_count
    5.54 -  LANGUAGE C IMMUTABLE STRICT
    5.55 -  AS '$libdir/latlon-v0009', 'pgl_epoint_with_sample_count_in';
    5.56 -
    5.57 -CREATE FUNCTION ebox_in(cstring)
    5.58 -  RETURNS ebox
    5.59 -  LANGUAGE C IMMUTABLE STRICT
    5.60 -  AS '$libdir/latlon-v0009', 'pgl_ebox_in';
    5.61 -
    5.62 -CREATE FUNCTION ecircle_in(cstring)
    5.63 -  RETURNS ecircle
    5.64 -  LANGUAGE C IMMUTABLE STRICT
    5.65 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_in';
    5.66 -
    5.67 -CREATE FUNCTION ecluster_in(cstring)
    5.68 -  RETURNS ecluster
    5.69 -  LANGUAGE C IMMUTABLE STRICT
    5.70 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_in';
    5.71 -
    5.72 -
    5.73 ----------------------------
    5.74 --- text output functions --
    5.75 ----------------------------
    5.76 -
    5.77 -CREATE FUNCTION epoint_out(epoint)
    5.78 -  RETURNS cstring
    5.79 -  LANGUAGE C IMMUTABLE STRICT
    5.80 -  AS '$libdir/latlon-v0009', 'pgl_epoint_out';
    5.81 -
    5.82 -CREATE FUNCTION epoint_with_sample_count_out(epoint_with_sample_count)
    5.83 -  RETURNS cstring
    5.84 -  LANGUAGE C IMMUTABLE STRICT
    5.85 -  AS '$libdir/latlon-v0009', 'pgl_epoint_with_sample_count_out';
    5.86 -
    5.87 -CREATE FUNCTION ebox_out(ebox)
    5.88 -  RETURNS cstring
    5.89 -  LANGUAGE C IMMUTABLE STRICT
    5.90 -  AS '$libdir/latlon-v0009', 'pgl_ebox_out';
    5.91 -
    5.92 -CREATE FUNCTION ecircle_out(ecircle)
    5.93 -  RETURNS cstring
    5.94 -  LANGUAGE C IMMUTABLE STRICT
    5.95 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_out';
    5.96 -
    5.97 -CREATE FUNCTION ecluster_out(ecluster)
    5.98 -  RETURNS cstring
    5.99 -  LANGUAGE C IMMUTABLE STRICT
   5.100 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_out';
   5.101 -
   5.102 -
   5.103 ---------------------------
   5.104 --- binary I/O functions --
   5.105 ---------------------------
   5.106 -
   5.107 -CREATE FUNCTION epoint_recv(internal)
   5.108 -  RETURNS epoint
   5.109 -  LANGUAGE C IMMUTABLE STRICT
   5.110 -  AS '$libdir/latlon-v0009', 'pgl_epoint_recv';
   5.111 -
   5.112 -CREATE FUNCTION ebox_recv(internal)
   5.113 -  RETURNS ebox
   5.114 -  LANGUAGE C IMMUTABLE STRICT
   5.115 -  AS '$libdir/latlon-v0009', 'pgl_ebox_recv';
   5.116 -
   5.117 -CREATE FUNCTION ecircle_recv(internal)
   5.118 -  RETURNS ecircle
   5.119 -  LANGUAGE C IMMUTABLE STRICT
   5.120 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_recv';
   5.121 -
   5.122 -CREATE FUNCTION epoint_send(epoint)
   5.123 -  RETURNS bytea
   5.124 -  LANGUAGE C IMMUTABLE STRICT
   5.125 -  AS '$libdir/latlon-v0009', 'pgl_epoint_send';
   5.126 -
   5.127 -CREATE FUNCTION ebox_send(ebox)
   5.128 -  RETURNS bytea
   5.129 -  LANGUAGE C IMMUTABLE STRICT
   5.130 -  AS '$libdir/latlon-v0009', 'pgl_ebox_send';
   5.131 -
   5.132 -CREATE FUNCTION ecircle_send(ecircle)
   5.133 -  RETURNS bytea
   5.134 -  LANGUAGE C IMMUTABLE STRICT
   5.135 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_send';
   5.136 -
   5.137 -
   5.138 ------------------------------------------------
   5.139 --- type definitions of dummy index key types --
   5.140 ------------------------------------------------
   5.141 -
   5.142 -CREATE TYPE ekey_point (
   5.143 -  internallength = 8,
   5.144 -  input = ekey_point_in_dummy,
   5.145 -  output = ekey_point_out_dummy,
   5.146 -  alignment = char );
   5.147 -
   5.148 -CREATE TYPE ekey_area (
   5.149 -  internallength = 9,
   5.150 -  input = ekey_area_in_dummy,
   5.151 -  output = ekey_area_out_dummy,
   5.152 -  alignment = char );
   5.153 -
   5.154 -
   5.155 -------------------------------------------
   5.156 --- definitions of geographic data types --
   5.157 -------------------------------------------
   5.158 -
   5.159 -CREATE TYPE epoint (
   5.160 -  internallength = 16,
   5.161 -  input = epoint_in,
   5.162 -  output = epoint_out,
   5.163 -  receive = epoint_recv,
   5.164 -  send = epoint_send,
   5.165 -  alignment = double );
   5.166 -
   5.167 -CREATE TYPE epoint_with_sample_count (
   5.168 -  internallength = 20,
   5.169 -  input = epoint_with_sample_count_in,
   5.170 -  output = epoint_with_sample_count_out,
   5.171 -  alignment = double );
   5.172 -
   5.173 -CREATE TYPE ebox (
   5.174 -  internallength = 32,
   5.175 -  input = ebox_in,
   5.176 -  output = ebox_out,
   5.177 -  receive = ebox_recv,
   5.178 -  send = ebox_send,
   5.179 -  alignment = double );
   5.180 -
   5.181 -CREATE TYPE ecircle (
   5.182 -  internallength = 24,
   5.183 -  input = ecircle_in,
   5.184 -  output = ecircle_out,
   5.185 -  receive = ecircle_recv,
   5.186 -  send = ecircle_send,
   5.187 -  alignment = double );
   5.188 -
   5.189 -CREATE TYPE ecluster (
   5.190 -  internallength = VARIABLE,
   5.191 -  input = ecluster_in,
   5.192 -  output = ecluster_out,
   5.193 -  alignment = double,
   5.194 -  storage = external );
   5.195 -
   5.196 -
   5.197 ---------------------
   5.198 --- B-tree support --
   5.199 ---------------------
   5.200 -
   5.201 --- begin of B-tree support for epoint
   5.202 -
   5.203 -CREATE FUNCTION epoint_btree_lt(epoint, epoint)
   5.204 -  RETURNS boolean
   5.205 -  LANGUAGE C IMMUTABLE STRICT
   5.206 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_lt';
   5.207 -
   5.208 -CREATE FUNCTION epoint_btree_le(epoint, epoint)
   5.209 -  RETURNS boolean
   5.210 -  LANGUAGE C IMMUTABLE STRICT
   5.211 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_le';
   5.212 -
   5.213 -CREATE FUNCTION epoint_btree_eq(epoint, epoint)
   5.214 -  RETURNS boolean
   5.215 -  LANGUAGE C IMMUTABLE STRICT
   5.216 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_eq';
   5.217 -
   5.218 -CREATE FUNCTION epoint_btree_ne(epoint, epoint)
   5.219 -  RETURNS boolean
   5.220 -  LANGUAGE C IMMUTABLE STRICT
   5.221 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_ne';
   5.222 -
   5.223 -CREATE FUNCTION epoint_btree_ge(epoint, epoint)
   5.224 -  RETURNS boolean
   5.225 -  LANGUAGE C IMMUTABLE STRICT
   5.226 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_ge';
   5.227 -
   5.228 -CREATE FUNCTION epoint_btree_gt(epoint, epoint)
   5.229 -  RETURNS boolean
   5.230 -  LANGUAGE C IMMUTABLE STRICT
   5.231 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_gt';
   5.232 -
   5.233 -CREATE OPERATOR <<< (
   5.234 -  leftarg = epoint,
   5.235 -  rightarg = epoint,
   5.236 -  procedure = epoint_btree_lt,
   5.237 -  commutator = >>>,
   5.238 -  negator = >>>=,
   5.239 -  restrict = scalarltsel,
   5.240 -  join = scalarltjoinsel
   5.241 -);
   5.242 -
   5.243 -CREATE OPERATOR <<<= (
   5.244 -  leftarg = epoint,
   5.245 -  rightarg = epoint,
   5.246 -  procedure = epoint_btree_le,
   5.247 -  commutator = >>>=,
   5.248 -  negator = >>>,
   5.249 -  restrict = scalarltsel,
   5.250 -  join = scalarltjoinsel
   5.251 -);
   5.252 -
   5.253 -CREATE OPERATOR = (
   5.254 -  leftarg = epoint,
   5.255 -  rightarg = epoint,
   5.256 -  procedure = epoint_btree_eq,
   5.257 -  commutator = =,
   5.258 -  negator = <>,
   5.259 -  restrict = eqsel,
   5.260 -  join = eqjoinsel,
   5.261 -  merges
   5.262 -);
   5.263 -
   5.264 -CREATE OPERATOR <> (
   5.265 -  leftarg = epoint,
   5.266 -  rightarg = epoint,
   5.267 -  procedure = epoint_btree_ne,
   5.268 -  commutator = <>,
   5.269 -  negator = =,
   5.270 -  restrict = neqsel,
   5.271 -  join = neqjoinsel
   5.272 -);
   5.273 -
   5.274 -CREATE OPERATOR >>>= (
   5.275 -  leftarg = epoint,
   5.276 -  rightarg = epoint,
   5.277 -  procedure = epoint_btree_ge,
   5.278 -  commutator = <<<=,
   5.279 -  negator = <<<,
   5.280 -  restrict = scalargtsel,
   5.281 -  join = scalargtjoinsel
   5.282 -);
   5.283 -
   5.284 -CREATE OPERATOR >>> (
   5.285 -  leftarg = epoint,
   5.286 -  rightarg = epoint,
   5.287 -  procedure = epoint_btree_gt,
   5.288 -  commutator = <<<,
   5.289 -  negator = <<<=,
   5.290 -  restrict = scalargtsel,
   5.291 -  join = scalargtjoinsel
   5.292 -);
   5.293 -
   5.294 -CREATE FUNCTION epoint_btree_cmp(epoint, epoint)
   5.295 -  RETURNS int4
   5.296 -  LANGUAGE C IMMUTABLE STRICT
   5.297 -  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_cmp';
   5.298 -
   5.299 -CREATE OPERATOR CLASS epoint_btree_ops
   5.300 -  DEFAULT FOR TYPE epoint USING btree AS
   5.301 -  OPERATOR 1 <<< ,
   5.302 -  OPERATOR 2 <<<= ,
   5.303 -  OPERATOR 3 = ,
   5.304 -  OPERATOR 4 >>>= ,
   5.305 -  OPERATOR 5 >>> ,
   5.306 -  FUNCTION 1 epoint_btree_cmp(epoint, epoint);
   5.307 -
   5.308 --- end of B-tree support for epoint
   5.309 -
   5.310 --- begin of B-tree support for ebox
   5.311 -
   5.312 -CREATE FUNCTION ebox_btree_lt(ebox, ebox)
   5.313 -  RETURNS boolean
   5.314 -  LANGUAGE C IMMUTABLE STRICT
   5.315 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_lt';
   5.316 -
   5.317 -CREATE FUNCTION ebox_btree_le(ebox, ebox)
   5.318 -  RETURNS boolean
   5.319 -  LANGUAGE C IMMUTABLE STRICT
   5.320 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_le';
   5.321 -
   5.322 -CREATE FUNCTION ebox_btree_eq(ebox, ebox)
   5.323 -  RETURNS boolean
   5.324 -  LANGUAGE C IMMUTABLE STRICT
   5.325 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_eq';
   5.326 -
   5.327 -CREATE FUNCTION ebox_btree_ne(ebox, ebox)
   5.328 -  RETURNS boolean
   5.329 -  LANGUAGE C IMMUTABLE STRICT
   5.330 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_ne';
   5.331 -
   5.332 -CREATE FUNCTION ebox_btree_ge(ebox, ebox)
   5.333 -  RETURNS boolean
   5.334 -  LANGUAGE C IMMUTABLE STRICT
   5.335 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_ge';
   5.336 -
   5.337 -CREATE FUNCTION ebox_btree_gt(ebox, ebox)
   5.338 -  RETURNS boolean
   5.339 -  LANGUAGE C IMMUTABLE STRICT
   5.340 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_gt';
   5.341 -
   5.342 -CREATE OPERATOR <<< (
   5.343 -  leftarg = ebox,
   5.344 -  rightarg = ebox,
   5.345 -  procedure = ebox_btree_lt,
   5.346 -  commutator = >>>,
   5.347 -  negator = >>>=,
   5.348 -  restrict = scalarltsel,
   5.349 -  join = scalarltjoinsel
   5.350 -);
   5.351 -
   5.352 -CREATE OPERATOR <<<= (
   5.353 -  leftarg = ebox,
   5.354 -  rightarg = ebox,
   5.355 -  procedure = ebox_btree_le,
   5.356 -  commutator = >>>=,
   5.357 -  negator = >>>,
   5.358 -  restrict = scalarltsel,
   5.359 -  join = scalarltjoinsel
   5.360 -);
   5.361 -
   5.362 -CREATE OPERATOR = (
   5.363 -  leftarg = ebox,
   5.364 -  rightarg = ebox,
   5.365 -  procedure = ebox_btree_eq,
   5.366 -  commutator = =,
   5.367 -  negator = <>,
   5.368 -  restrict = eqsel,
   5.369 -  join = eqjoinsel,
   5.370 -  merges
   5.371 -);
   5.372 -
   5.373 -CREATE OPERATOR <> (
   5.374 -  leftarg = ebox,
   5.375 -  rightarg = ebox,
   5.376 -  procedure = ebox_btree_ne,
   5.377 -  commutator = <>,
   5.378 -  negator = =,
   5.379 -  restrict = neqsel,
   5.380 -  join = neqjoinsel
   5.381 -);
   5.382 -
   5.383 -CREATE OPERATOR >>>= (
   5.384 -  leftarg = ebox,
   5.385 -  rightarg = ebox,
   5.386 -  procedure = ebox_btree_ge,
   5.387 -  commutator = <<<=,
   5.388 -  negator = <<<,
   5.389 -  restrict = scalargtsel,
   5.390 -  join = scalargtjoinsel
   5.391 -);
   5.392 -
   5.393 -CREATE OPERATOR >>> (
   5.394 -  leftarg = ebox,
   5.395 -  rightarg = ebox,
   5.396 -  procedure = ebox_btree_gt,
   5.397 -  commutator = <<<,
   5.398 -  negator = <<<=,
   5.399 -  restrict = scalargtsel,
   5.400 -  join = scalargtjoinsel
   5.401 -);
   5.402 -
   5.403 -CREATE FUNCTION ebox_btree_cmp(ebox, ebox)
   5.404 -  RETURNS int4
   5.405 -  LANGUAGE C IMMUTABLE STRICT
   5.406 -  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_cmp';
   5.407 -
   5.408 -CREATE OPERATOR CLASS ebox_btree_ops
   5.409 -  DEFAULT FOR TYPE ebox USING btree AS
   5.410 -  OPERATOR 1 <<< ,
   5.411 -  OPERATOR 2 <<<= ,
   5.412 -  OPERATOR 3 = ,
   5.413 -  OPERATOR 4 >>>= ,
   5.414 -  OPERATOR 5 >>> ,
   5.415 -  FUNCTION 1 ebox_btree_cmp(ebox, ebox);
   5.416 -
   5.417 --- end of B-tree support for ebox
   5.418 -
   5.419 --- begin of B-tree support for ecircle
   5.420 -
   5.421 -CREATE FUNCTION ecircle_btree_lt(ecircle, ecircle)
   5.422 -  RETURNS boolean
   5.423 -  LANGUAGE C IMMUTABLE STRICT
   5.424 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_lt';
   5.425 -
   5.426 -CREATE FUNCTION ecircle_btree_le(ecircle, ecircle)
   5.427 -  RETURNS boolean
   5.428 -  LANGUAGE C IMMUTABLE STRICT
   5.429 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_le';
   5.430 -
   5.431 -CREATE FUNCTION ecircle_btree_eq(ecircle, ecircle)
   5.432 -  RETURNS boolean
   5.433 -  LANGUAGE C IMMUTABLE STRICT
   5.434 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_eq';
   5.435 -
   5.436 -CREATE FUNCTION ecircle_btree_ne(ecircle, ecircle)
   5.437 -  RETURNS boolean
   5.438 -  LANGUAGE C IMMUTABLE STRICT
   5.439 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_ne';
   5.440 -
   5.441 -CREATE FUNCTION ecircle_btree_ge(ecircle, ecircle)
   5.442 -  RETURNS boolean
   5.443 -  LANGUAGE C IMMUTABLE STRICT
   5.444 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_ge';
   5.445 -
   5.446 -CREATE FUNCTION ecircle_btree_gt(ecircle, ecircle)
   5.447 -  RETURNS boolean
   5.448 -  LANGUAGE C IMMUTABLE STRICT
   5.449 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_gt';
   5.450 -
   5.451 -CREATE OPERATOR <<< (
   5.452 -  leftarg = ecircle,
   5.453 -  rightarg = ecircle,
   5.454 -  procedure = ecircle_btree_lt,
   5.455 -  commutator = >>>,
   5.456 -  negator = >>>=,
   5.457 -  restrict = scalarltsel,
   5.458 -  join = scalarltjoinsel
   5.459 -);
   5.460 -
   5.461 -CREATE OPERATOR <<<= (
   5.462 -  leftarg = ecircle,
   5.463 -  rightarg = ecircle,
   5.464 -  procedure = ecircle_btree_le,
   5.465 -  commutator = >>>=,
   5.466 -  negator = >>>,
   5.467 -  restrict = scalarltsel,
   5.468 -  join = scalarltjoinsel
   5.469 -);
   5.470 -
   5.471 -CREATE OPERATOR = (
   5.472 -  leftarg = ecircle,
   5.473 -  rightarg = ecircle,
   5.474 -  procedure = ecircle_btree_eq,
   5.475 -  commutator = =,
   5.476 -  negator = <>,
   5.477 -  restrict = eqsel,
   5.478 -  join = eqjoinsel,
   5.479 -  merges
   5.480 -);
   5.481 -
   5.482 -CREATE OPERATOR <> (
   5.483 -  leftarg = ecircle,
   5.484 -  rightarg = ecircle,
   5.485 -  procedure = ecircle_btree_ne,
   5.486 -  commutator = <>,
   5.487 -  negator = =,
   5.488 -  restrict = neqsel,
   5.489 -  join = neqjoinsel
   5.490 -);
   5.491 -
   5.492 -CREATE OPERATOR >>>= (
   5.493 -  leftarg = ecircle,
   5.494 -  rightarg = ecircle,
   5.495 -  procedure = ecircle_btree_ge,
   5.496 -  commutator = <<<=,
   5.497 -  negator = <<<,
   5.498 -  restrict = scalargtsel,
   5.499 -  join = scalargtjoinsel
   5.500 -);
   5.501 -
   5.502 -CREATE OPERATOR >>> (
   5.503 -  leftarg = ecircle,
   5.504 -  rightarg = ecircle,
   5.505 -  procedure = ecircle_btree_gt,
   5.506 -  commutator = <<<,
   5.507 -  negator = <<<=,
   5.508 -  restrict = scalargtsel,
   5.509 -  join = scalargtjoinsel
   5.510 -);
   5.511 -
   5.512 -CREATE FUNCTION ecircle_btree_cmp(ecircle, ecircle)
   5.513 -  RETURNS int4
   5.514 -  LANGUAGE C IMMUTABLE STRICT
   5.515 -  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_cmp';
   5.516 -
   5.517 -CREATE OPERATOR CLASS ecircle_btree_ops
   5.518 -  DEFAULT FOR TYPE ecircle USING btree AS
   5.519 -  OPERATOR 1 <<< ,
   5.520 -  OPERATOR 2 <<<= ,
   5.521 -  OPERATOR 3 = ,
   5.522 -  OPERATOR 4 >>>= ,
   5.523 -  OPERATOR 5 >>> ,
   5.524 -  FUNCTION 1 ecircle_btree_cmp(ecircle, ecircle);
   5.525 -
   5.526 --- end of B-tree support for ecircle
   5.527 -
   5.528 -
   5.529 -----------------
   5.530 --- type casts --
   5.531 -----------------
   5.532 -
   5.533 -CREATE FUNCTION cast_epoint_to_ebox(epoint)
   5.534 -  RETURNS ebox
   5.535 -  LANGUAGE C IMMUTABLE STRICT
   5.536 -  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ebox';
   5.537 -
   5.538 -CREATE CAST (epoint AS ebox) WITH FUNCTION cast_epoint_to_ebox(epoint);
   5.539 -
   5.540 -CREATE FUNCTION cast_epoint_to_ecircle(epoint)
   5.541 -  RETURNS ecircle
   5.542 -  LANGUAGE C IMMUTABLE STRICT
   5.543 -  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ecircle';
   5.544 -
   5.545 -CREATE CAST (epoint AS ecircle) WITH FUNCTION cast_epoint_to_ecircle(epoint);
   5.546 -
   5.547 -CREATE FUNCTION cast_epoint_to_ecluster(epoint)
   5.548 -  RETURNS ecluster
   5.549 -  LANGUAGE C IMMUTABLE STRICT
   5.550 -  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ecluster';
   5.551 -
   5.552 -CREATE CAST (epoint AS ecluster) WITH FUNCTION cast_epoint_to_ecluster(epoint);
   5.553 -
   5.554 -CREATE FUNCTION cast_ebox_to_ecluster(ebox)
   5.555 -  RETURNS ecluster
   5.556 -  LANGUAGE C IMMUTABLE STRICT
   5.557 -  AS '$libdir/latlon-v0009', 'pgl_ebox_to_ecluster';
   5.558 -
   5.559 -CREATE CAST (ebox AS ecluster) WITH FUNCTION cast_ebox_to_ecluster(ebox);
   5.560 -
   5.561 -
   5.562 ----------------------------
   5.563 --- constructor functions --
   5.564 ----------------------------
   5.565 -
   5.566 -CREATE FUNCTION epoint(float8, float8)
   5.567 -  RETURNS epoint
   5.568 -  LANGUAGE C IMMUTABLE STRICT
   5.569 -  AS '$libdir/latlon-v0009', 'pgl_create_epoint';
   5.570 -
   5.571 -CREATE FUNCTION epoint_latlon(float8, float8)
   5.572 -  RETURNS epoint
   5.573 -  LANGUAGE SQL IMMUTABLE STRICT AS $$
   5.574 -    SELECT epoint($1, $2)
   5.575 -  $$;
   5.576 -
   5.577 -CREATE FUNCTION epoint_lonlat(float8, float8)
   5.578 -  RETURNS epoint
   5.579 -  LANGUAGE SQL IMMUTABLE STRICT AS $$
   5.580 -    SELECT epoint($2, $1)
   5.581 -  $$;
   5.582 -
   5.583 -CREATE FUNCTION epoint_with_sample_count(epoint, int4)
   5.584 -  RETURNS epoint_with_sample_count
   5.585 -  LANGUAGE C IMMUTABLE STRICT
   5.586 -  AS '$libdir/latlon-v0009', 'pgl_create_epoint_with_sample_count';
   5.587 -
   5.588 -CREATE FUNCTION empty_ebox()
   5.589 -  RETURNS ebox
   5.590 -  LANGUAGE C IMMUTABLE STRICT
   5.591 -  AS '$libdir/latlon-v0009', 'pgl_create_empty_ebox';
   5.592 -
   5.593 -CREATE FUNCTION ebox(float8, float8, float8, float8)
   5.594 -  RETURNS ebox
   5.595 -  LANGUAGE C IMMUTABLE STRICT
   5.596 -  AS '$libdir/latlon-v0009', 'pgl_create_ebox';
   5.597 -
   5.598 -CREATE FUNCTION ebox(epoint, epoint)
   5.599 -  RETURNS ebox
   5.600 -  LANGUAGE C IMMUTABLE STRICT
   5.601 -  AS '$libdir/latlon-v0009', 'pgl_create_ebox_from_epoints';
   5.602 -
   5.603 -CREATE FUNCTION ecircle(float8, float8, float8)
   5.604 -  RETURNS ecircle
   5.605 -  LANGUAGE C IMMUTABLE STRICT
   5.606 -  AS '$libdir/latlon-v0009', 'pgl_create_ecircle';
   5.607 -
   5.608 -CREATE FUNCTION ecircle(epoint, float8)
   5.609 -  RETURNS ecircle
   5.610 -  LANGUAGE C IMMUTABLE STRICT
   5.611 -  AS '$libdir/latlon-v0009', 'pgl_create_ecircle_from_epoint';
   5.612 -
   5.613 -CREATE FUNCTION ecluster_concat(ecluster[])
   5.614 -  RETURNS ecluster
   5.615 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.616 -    SELECT array_to_string($1, ' ')::ecluster
   5.617 -  $$;
   5.618 -
   5.619 -CREATE FUNCTION ecluster_concat(ecluster, ecluster)
   5.620 -  RETURNS ecluster
   5.621 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.622 -    SELECT ($1::text || ' ' || $2::text)::ecluster
   5.623 -  $$;
   5.624 -
   5.625 -CREATE FUNCTION ecluster_create_multipoint(epoint[])
   5.626 -  RETURNS ecluster
   5.627 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.628 -    SELECT
   5.629 -      array_to_string(array_agg('point (' || unnest || ')'), ' ')::ecluster
   5.630 -    FROM unnest($1)
   5.631 -  $$;
   5.632 -
   5.633 -CREATE FUNCTION ecluster_create_path(epoint[])
   5.634 -  RETURNS ecluster
   5.635 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.636 -    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   5.637 -      ('path (' || array_to_string($1, ' ') || ')')::ecluster
   5.638 -    END
   5.639 -    FROM array_to_string($1, ' ') AS "str"
   5.640 -  $$;
   5.641 -
   5.642 -CREATE FUNCTION ecluster_create_outline(epoint[])
   5.643 -  RETURNS ecluster
   5.644 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.645 -    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   5.646 -      ('outline (' || array_to_string($1, ' ') || ')')::ecluster
   5.647 -    END
   5.648 -    FROM array_to_string($1, ' ') AS "str"
   5.649 -  $$;
   5.650 -
   5.651 -CREATE FUNCTION ecluster_create_polygon(epoint[])
   5.652 -  RETURNS ecluster
   5.653 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.654 -    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   5.655 -      ('polygon (' || array_to_string($1, ' ') || ')')::ecluster
   5.656 -    END
   5.657 -    FROM array_to_string($1, ' ') AS "str"
   5.658 -  $$;
   5.659 -
   5.660 -
   5.661 -----------------------
   5.662 --- getter functions --
   5.663 -----------------------
   5.664 -
   5.665 -CREATE FUNCTION latitude(epoint)
   5.666 -  RETURNS float8
   5.667 -  LANGUAGE C IMMUTABLE STRICT
   5.668 -  AS '$libdir/latlon-v0009', 'pgl_epoint_lat';
   5.669 -
   5.670 -CREATE FUNCTION longitude(epoint)
   5.671 -  RETURNS float8
   5.672 -  LANGUAGE C IMMUTABLE STRICT
   5.673 -  AS '$libdir/latlon-v0009', 'pgl_epoint_lon';
   5.674 -
   5.675 -CREATE FUNCTION min_latitude(ebox)
   5.676 -  RETURNS float8
   5.677 -  LANGUAGE C IMMUTABLE STRICT
   5.678 -  AS '$libdir/latlon-v0009', 'pgl_ebox_lat_min';
   5.679 -
   5.680 -CREATE FUNCTION max_latitude(ebox)
   5.681 -  RETURNS float8
   5.682 -  LANGUAGE C IMMUTABLE STRICT
   5.683 -  AS '$libdir/latlon-v0009', 'pgl_ebox_lat_max';
   5.684 -
   5.685 -CREATE FUNCTION min_longitude(ebox)
   5.686 -  RETURNS float8
   5.687 -  LANGUAGE C IMMUTABLE STRICT
   5.688 -  AS '$libdir/latlon-v0009', 'pgl_ebox_lon_min';
   5.689 -
   5.690 -CREATE FUNCTION max_longitude(ebox)
   5.691 -  RETURNS float8
   5.692 -  LANGUAGE C IMMUTABLE STRICT
   5.693 -  AS '$libdir/latlon-v0009', 'pgl_ebox_lon_max';
   5.694 -
   5.695 -CREATE FUNCTION center(ecircle)
   5.696 -  RETURNS epoint
   5.697 -  LANGUAGE C IMMUTABLE STRICT
   5.698 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_center';
   5.699 -
   5.700 -CREATE FUNCTION radius(ecircle)
   5.701 -  RETURNS float8
   5.702 -  LANGUAGE C IMMUTABLE STRICT
   5.703 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_radius';
   5.704 -
   5.705 -CREATE FUNCTION ecluster_extract_points(ecluster)
   5.706 -  RETURNS SETOF epoint
   5.707 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.708 -    SELECT "match"[2]::epoint
   5.709 -    FROM regexp_matches($1::text, e'(^| )point \\(([^)]+)\\)', 'g') AS "match"
   5.710 -  $$;
   5.711 -
   5.712 -CREATE FUNCTION ecluster_extract_paths(ecluster)
   5.713 -  RETURNS SETOF epoint[]
   5.714 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.715 -    SELECT (
   5.716 -      SELECT array_agg("m2"[1]::epoint)
   5.717 -      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   5.718 -    )
   5.719 -    FROM regexp_matches($1::text, e'(^| )path \\(([^)]+)\\)', 'g') AS "m1"
   5.720 -  $$;
   5.721 -
   5.722 -CREATE FUNCTION ecluster_extract_outlines(ecluster)
   5.723 -  RETURNS SETOF epoint[]
   5.724 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.725 -    SELECT (
   5.726 -      SELECT array_agg("m2"[1]::epoint)
   5.727 -      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   5.728 -    )
   5.729 -    FROM regexp_matches($1::text, e'(^| )outline \\(([^)]+)\\)', 'g') AS "m1"
   5.730 -  $$;
   5.731 -
   5.732 -CREATE FUNCTION ecluster_extract_polygons(ecluster)
   5.733 -  RETURNS SETOF epoint[]
   5.734 -  LANGUAGE sql IMMUTABLE STRICT AS $$
   5.735 -    SELECT (
   5.736 -      SELECT array_agg("m2"[1]::epoint)
   5.737 -      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   5.738 -    )
   5.739 -    FROM regexp_matches($1::text, e'(^| )polygon \\(([^)]+)\\)', 'g') AS "m1"
   5.740 -  $$;
   5.741 -
   5.742 -
   5.743 ----------------
   5.744 --- operators --
   5.745 ----------------
   5.746 -
   5.747 -CREATE FUNCTION epoint_ebox_overlap_proc(epoint, ebox)
   5.748 -  RETURNS boolean
   5.749 -  LANGUAGE C IMMUTABLE STRICT
   5.750 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ebox_overlap';
   5.751 -
   5.752 -CREATE FUNCTION epoint_ecircle_overlap_proc(epoint, ecircle)
   5.753 -  RETURNS boolean
   5.754 -  LANGUAGE C IMMUTABLE STRICT
   5.755 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ecircle_overlap';
   5.756 -
   5.757 -CREATE FUNCTION epoint_ecluster_overlap_proc(epoint, ecluster)
   5.758 -  RETURNS boolean
   5.759 -  LANGUAGE C IMMUTABLE STRICT
   5.760 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_overlap';
   5.761 -
   5.762 -CREATE FUNCTION epoint_ecluster_may_overlap_proc(epoint, ecluster)
   5.763 -  RETURNS boolean
   5.764 -  LANGUAGE C IMMUTABLE STRICT
   5.765 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_may_overlap';
   5.766 -
   5.767 -CREATE FUNCTION ebox_overlap_proc(ebox, ebox)
   5.768 -  RETURNS boolean
   5.769 -  LANGUAGE C IMMUTABLE STRICT
   5.770 -  AS '$libdir/latlon-v0009', 'pgl_ebox_overlap';
   5.771 -
   5.772 -CREATE FUNCTION ebox_ecircle_may_overlap_proc(ebox, ecircle)
   5.773 -  RETURNS boolean
   5.774 -  LANGUAGE C IMMUTABLE STRICT
   5.775 -  AS '$libdir/latlon-v0009', 'pgl_ebox_ecircle_may_overlap';
   5.776 -
   5.777 -CREATE FUNCTION ebox_ecluster_may_overlap_proc(ebox, ecluster)
   5.778 -  RETURNS boolean
   5.779 -  LANGUAGE C IMMUTABLE STRICT
   5.780 -  AS '$libdir/latlon-v0009', 'pgl_ebox_ecluster_may_overlap';
   5.781 -
   5.782 -CREATE FUNCTION ecircle_overlap_proc(ecircle, ecircle)
   5.783 -  RETURNS boolean
   5.784 -  LANGUAGE C IMMUTABLE STRICT
   5.785 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_overlap';
   5.786 -
   5.787 -CREATE FUNCTION ecircle_ecluster_overlap_proc(ecircle, ecluster)
   5.788 -  RETURNS boolean
   5.789 -  LANGUAGE C IMMUTABLE STRICT
   5.790 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_overlap';
   5.791 -
   5.792 -CREATE FUNCTION ecircle_ecluster_may_overlap_proc(ecircle, ecluster)
   5.793 -  RETURNS boolean
   5.794 -  LANGUAGE C IMMUTABLE STRICT
   5.795 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_may_overlap';
   5.796 -
   5.797 -CREATE FUNCTION ecluster_overlap_proc(ecluster, ecluster)
   5.798 -  RETURNS boolean
   5.799 -  LANGUAGE C IMMUTABLE STRICT
   5.800 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_overlap';
   5.801 -
   5.802 -CREATE FUNCTION ecluster_may_overlap_proc(ecluster, ecluster)
   5.803 -  RETURNS boolean
   5.804 -  LANGUAGE C IMMUTABLE STRICT
   5.805 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_may_overlap';
   5.806 -
   5.807 -CREATE FUNCTION ecluster_contains_proc(ecluster, ecluster)
   5.808 -  RETURNS boolean
   5.809 -  LANGUAGE C IMMUTABLE STRICT
   5.810 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_contains';
   5.811 -
   5.812 -CREATE FUNCTION epoint_distance_proc(epoint, epoint)
   5.813 -  RETURNS float8
   5.814 -  LANGUAGE C IMMUTABLE STRICT
   5.815 -  AS '$libdir/latlon-v0009', 'pgl_epoint_distance';
   5.816 -
   5.817 -CREATE FUNCTION epoint_ecircle_distance_proc(epoint, ecircle)
   5.818 -  RETURNS float8
   5.819 -  LANGUAGE C IMMUTABLE STRICT
   5.820 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ecircle_distance';
   5.821 -
   5.822 -CREATE FUNCTION epoint_ecluster_distance_proc(epoint, ecluster)
   5.823 -  RETURNS float8
   5.824 -  LANGUAGE C IMMUTABLE STRICT
   5.825 -  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_distance';
   5.826 -
   5.827 -CREATE FUNCTION ecircle_distance_proc(ecircle, ecircle)
   5.828 -  RETURNS float8
   5.829 -  LANGUAGE C IMMUTABLE STRICT
   5.830 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_distance';
   5.831 -
   5.832 -CREATE FUNCTION ecircle_ecluster_distance_proc(ecircle, ecluster)
   5.833 -  RETURNS float8
   5.834 -  LANGUAGE C IMMUTABLE STRICT
   5.835 -  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_distance';
   5.836 -
   5.837 -CREATE FUNCTION ecluster_distance_proc(ecluster, ecluster)
   5.838 -  RETURNS float8
   5.839 -  LANGUAGE C IMMUTABLE STRICT
   5.840 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_distance';
   5.841 -
   5.842 -CREATE FUNCTION fair_distance_operator_proc(ecluster, epoint_with_sample_count)
   5.843 -  RETURNS float8
   5.844 -  LANGUAGE C IMMUTABLE STRICT
   5.845 -  AS '$libdir/latlon-v0009', 'pgl_ecluster_epoint_sc_fair_distance';
   5.846 -
   5.847 -CREATE OPERATOR && (
   5.848 -  leftarg = epoint,
   5.849 -  rightarg = ebox,
   5.850 -  procedure = epoint_ebox_overlap_proc,
   5.851 -  commutator = &&,
   5.852 -  restrict = areasel,
   5.853 -  join = areajoinsel
   5.854 -);
   5.855 -
   5.856 -CREATE FUNCTION epoint_ebox_overlap_commutator(ebox, epoint)
   5.857 -  RETURNS boolean
   5.858 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   5.859 -
   5.860 -CREATE OPERATOR && (
   5.861 -  leftarg = ebox,
   5.862 -  rightarg = epoint,
   5.863 -  procedure = epoint_ebox_overlap_commutator,
   5.864 -  commutator = &&,
   5.865 -  restrict = areasel,
   5.866 -  join = areajoinsel
   5.867 -);
   5.868 -
   5.869 -CREATE OPERATOR && (
   5.870 -  leftarg = epoint,
   5.871 -  rightarg = ecircle,
   5.872 -  procedure = epoint_ecircle_overlap_proc,
   5.873 -  commutator = &&,
   5.874 -  restrict = areasel,
   5.875 -  join = areajoinsel
   5.876 -);
   5.877 -
   5.878 -CREATE FUNCTION epoint_ecircle_overlap_commutator(ecircle, epoint)
   5.879 -  RETURNS boolean
   5.880 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   5.881 -
   5.882 -CREATE OPERATOR && (
   5.883 -  leftarg = ecircle,
   5.884 -  rightarg = epoint,
   5.885 -  procedure = epoint_ecircle_overlap_commutator,
   5.886 -  commutator = &&,
   5.887 -  restrict = areasel,
   5.888 -  join = areajoinsel
   5.889 -);
   5.890 -
   5.891 -CREATE OPERATOR && (
   5.892 -  leftarg = epoint,
   5.893 -  rightarg = ecluster,
   5.894 -  procedure = epoint_ecluster_overlap_proc,
   5.895 -  commutator = &&,
   5.896 -  restrict = areasel,
   5.897 -  join = areajoinsel
   5.898 -);
   5.899 -
   5.900 -CREATE FUNCTION epoint_ecluster_overlap_commutator(ecluster, epoint)
   5.901 -  RETURNS boolean
   5.902 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   5.903 -
   5.904 -CREATE OPERATOR && (
   5.905 -  leftarg = ecluster,
   5.906 -  rightarg = epoint,
   5.907 -  procedure = epoint_ecluster_overlap_commutator,
   5.908 -  commutator = &&,
   5.909 -  restrict = areasel,
   5.910 -  join = areajoinsel
   5.911 -);
   5.912 -
   5.913 -CREATE OPERATOR && (
   5.914 -  leftarg = ebox,
   5.915 -  rightarg = ebox,
   5.916 -  procedure = ebox_overlap_proc,
   5.917 -  commutator = &&,
   5.918 -  restrict = areasel,
   5.919 -  join = areajoinsel
   5.920 -);
   5.921 -
   5.922 -CREATE OPERATOR && (
   5.923 -  leftarg = ecircle,
   5.924 -  rightarg = ecircle,
   5.925 -  procedure = ecircle_overlap_proc,
   5.926 -  commutator = &&,
   5.927 -  restrict = areasel,
   5.928 -  join = areajoinsel
   5.929 -);
   5.930 -
   5.931 -CREATE OPERATOR && (
   5.932 -  leftarg = ecircle,
   5.933 -  rightarg = ecluster,
   5.934 -  procedure = ecircle_ecluster_overlap_proc,
   5.935 -  commutator = &&,
   5.936 -  restrict = areasel,
   5.937 -  join = areajoinsel
   5.938 -);
   5.939 -
   5.940 -CREATE FUNCTION ecircle_ecluster_overlap_commutator(ecluster, ecircle)
   5.941 -  RETURNS boolean
   5.942 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   5.943 -
   5.944 -CREATE OPERATOR && (
   5.945 -  leftarg = ecluster,
   5.946 -  rightarg = ecircle,
   5.947 -  procedure = ecircle_ecluster_overlap_commutator,
   5.948 -  commutator = &&,
   5.949 -  restrict = areasel,
   5.950 -  join = areajoinsel
   5.951 -);
   5.952 -
   5.953 -CREATE OPERATOR && (
   5.954 -  leftarg = ecluster,
   5.955 -  rightarg = ecluster,
   5.956 -  procedure = ecluster_overlap_proc,
   5.957 -  commutator = &&,
   5.958 -  restrict = areasel,
   5.959 -  join = areajoinsel
   5.960 -);
   5.961 -
   5.962 -CREATE FUNCTION ebox_ecircle_overlap_castwrap(ebox, ecircle)
   5.963 -  RETURNS boolean
   5.964 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster && $2';
   5.965 -
   5.966 -CREATE OPERATOR && (
   5.967 -  leftarg = ebox,
   5.968 -  rightarg = ecircle,
   5.969 -  procedure = ebox_ecircle_overlap_castwrap,
   5.970 -  commutator = &&,
   5.971 -  restrict = areasel,
   5.972 -  join = areajoinsel
   5.973 -);
   5.974 -
   5.975 -CREATE FUNCTION ebox_ecircle_overlap_castwrap(ecircle, ebox)
   5.976 -  RETURNS boolean
   5.977 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && $2::ecluster';
   5.978 -
   5.979 -CREATE OPERATOR && (
   5.980 -  leftarg = ecircle,
   5.981 -  rightarg = ebox,
   5.982 -  procedure = ebox_ecircle_overlap_castwrap,
   5.983 -  commutator = &&,
   5.984 -  restrict = areasel,
   5.985 -  join = areajoinsel
   5.986 -);
   5.987 -
   5.988 -CREATE FUNCTION ebox_ecluster_overlap_castwrap(ebox, ecluster)
   5.989 -  RETURNS boolean
   5.990 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster && $2';
   5.991 -
   5.992 -CREATE OPERATOR && (
   5.993 -  leftarg = ebox,
   5.994 -  rightarg = ecluster,
   5.995 -  procedure = ebox_ecluster_overlap_castwrap,
   5.996 -  commutator = &&,
   5.997 -  restrict = areasel,
   5.998 -  join = areajoinsel
   5.999 -);
  5.1000 -
  5.1001 -CREATE FUNCTION ebox_ecluster_overlap_castwrap(ecluster, ebox)
  5.1002 -  RETURNS boolean
  5.1003 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && $2::ecluster';
  5.1004 -
  5.1005 -CREATE OPERATOR && (
  5.1006 -  leftarg = ecluster,
  5.1007 -  rightarg = ebox,
  5.1008 -  procedure = ebox_ecluster_overlap_castwrap,
  5.1009 -  commutator = &&,
  5.1010 -  restrict = areasel,
  5.1011 -  join = areajoinsel
  5.1012 -);
  5.1013 -
  5.1014 -CREATE OPERATOR &&+ (
  5.1015 -  leftarg = epoint,
  5.1016 -  rightarg = ecluster,
  5.1017 -  procedure = epoint_ecluster_may_overlap_proc,
  5.1018 -  commutator = &&+,
  5.1019 -  restrict = areasel,
  5.1020 -  join = areajoinsel
  5.1021 -);
  5.1022 -
  5.1023 -CREATE FUNCTION epoint_ecluster_may_overlap_commutator(ecluster, epoint)
  5.1024 -  RETURNS boolean
  5.1025 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  5.1026 -
  5.1027 -CREATE OPERATOR &&+ (
  5.1028 -  leftarg = ecluster,
  5.1029 -  rightarg = epoint,
  5.1030 -  procedure = epoint_ecluster_may_overlap_commutator,
  5.1031 -  commutator = &&+,
  5.1032 -  restrict = areasel,
  5.1033 -  join = areajoinsel
  5.1034 -);
  5.1035 -
  5.1036 -CREATE OPERATOR &&+ (
  5.1037 -  leftarg = ebox,
  5.1038 -  rightarg = ecircle,
  5.1039 -  procedure = ebox_ecircle_may_overlap_proc,
  5.1040 -  commutator = &&+,
  5.1041 -  restrict = areasel,
  5.1042 -  join = areajoinsel
  5.1043 -);
  5.1044 -
  5.1045 -CREATE FUNCTION ebox_ecircle_may_overlap_commutator(ecircle, ebox)
  5.1046 -  RETURNS boolean
  5.1047 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  5.1048 -
  5.1049 -CREATE OPERATOR &&+ (
  5.1050 -  leftarg = ecircle,
  5.1051 -  rightarg = ebox,
  5.1052 -  procedure = ebox_ecircle_may_overlap_commutator,
  5.1053 -  commutator = &&+,
  5.1054 -  restrict = areasel,
  5.1055 -  join = areajoinsel
  5.1056 -);
  5.1057 -
  5.1058 -CREATE OPERATOR &&+ (
  5.1059 -  leftarg = ebox,
  5.1060 -  rightarg = ecluster,
  5.1061 -  procedure = ebox_ecluster_may_overlap_proc,
  5.1062 -  commutator = &&+,
  5.1063 -  restrict = areasel,
  5.1064 -  join = areajoinsel
  5.1065 -);
  5.1066 -
  5.1067 -CREATE FUNCTION ebox_ecluster_may_overlap_commutator(ecluster, ebox)
  5.1068 -  RETURNS boolean
  5.1069 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  5.1070 -
  5.1071 -CREATE OPERATOR &&+ (
  5.1072 -  leftarg = ecluster,
  5.1073 -  rightarg = ebox,
  5.1074 -  procedure = ebox_ecluster_may_overlap_commutator,
  5.1075 -  commutator = &&+,
  5.1076 -  restrict = areasel,
  5.1077 -  join = areajoinsel
  5.1078 -);
  5.1079 -
  5.1080 -CREATE OPERATOR &&+ (
  5.1081 -  leftarg = ecircle,
  5.1082 -  rightarg = ecluster,
  5.1083 -  procedure = ecircle_ecluster_may_overlap_proc,
  5.1084 -  commutator = &&+,
  5.1085 -  restrict = areasel,
  5.1086 -  join = areajoinsel
  5.1087 -);
  5.1088 -
  5.1089 -CREATE FUNCTION ecircle_ecluster_may_overlap_commutator(ecluster, ecircle)
  5.1090 -  RETURNS boolean
  5.1091 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  5.1092 -
  5.1093 -CREATE OPERATOR &&+ (
  5.1094 -  leftarg = ecluster,
  5.1095 -  rightarg = ecircle,
  5.1096 -  procedure = ecircle_ecluster_may_overlap_commutator,
  5.1097 -  commutator = &&+,
  5.1098 -  restrict = areasel,
  5.1099 -  join = areajoinsel
  5.1100 -);
  5.1101 -
  5.1102 -CREATE OPERATOR &&+ (
  5.1103 -  leftarg = ecluster,
  5.1104 -  rightarg = ecluster,
  5.1105 -  procedure = ecluster_may_overlap_proc,
  5.1106 -  commutator = &&+,
  5.1107 -  restrict = areasel,
  5.1108 -  join = areajoinsel
  5.1109 -);
  5.1110 -
  5.1111 -CREATE OPERATOR @> (
  5.1112 -  leftarg = ebox,
  5.1113 -  rightarg = epoint,
  5.1114 -  procedure = epoint_ebox_overlap_commutator,
  5.1115 -  commutator = <@,
  5.1116 -  restrict = areasel,
  5.1117 -  join = areajoinsel
  5.1118 -);
  5.1119 -
  5.1120 -CREATE OPERATOR <@ (
  5.1121 -  leftarg = epoint,
  5.1122 -  rightarg = ebox,
  5.1123 -  procedure = epoint_ebox_overlap_proc,
  5.1124 -  commutator = @>,
  5.1125 -  restrict = areasel,
  5.1126 -  join = areajoinsel
  5.1127 -);
  5.1128 -
  5.1129 -CREATE OPERATOR @> (
  5.1130 -  leftarg = ecluster,
  5.1131 -  rightarg = epoint,
  5.1132 -  procedure = epoint_ecluster_overlap_commutator,
  5.1133 -  commutator = <@,
  5.1134 -  restrict = areasel,
  5.1135 -  join = areajoinsel
  5.1136 -);
  5.1137 -
  5.1138 -CREATE OPERATOR <@ (
  5.1139 -  leftarg = epoint,
  5.1140 -  rightarg = ecluster,
  5.1141 -  procedure = epoint_ecluster_overlap_proc,
  5.1142 -  commutator = <@,
  5.1143 -  restrict = areasel,
  5.1144 -  join = areajoinsel
  5.1145 -);
  5.1146 -
  5.1147 -CREATE OPERATOR @> (
  5.1148 -  leftarg = ecluster,
  5.1149 -  rightarg = ecluster,
  5.1150 -  procedure = ecluster_contains_proc,
  5.1151 -  commutator = <@,
  5.1152 -  restrict = areasel,
  5.1153 -  join = areajoinsel
  5.1154 -);
  5.1155 -
  5.1156 -CREATE FUNCTION ecluster_contains_commutator(ecluster, ecluster)
  5.1157 -  RETURNS boolean
  5.1158 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 @> $1';
  5.1159 -
  5.1160 -CREATE OPERATOR <@ (
  5.1161 -  leftarg = ecluster,
  5.1162 -  rightarg = ecluster,
  5.1163 -  procedure = ecluster_contains_commutator,
  5.1164 -  commutator = @>,
  5.1165 -  restrict = areasel,
  5.1166 -  join = areajoinsel
  5.1167 -);
  5.1168 -
  5.1169 -CREATE FUNCTION ebox_contains_castwrap(ebox, ebox)
  5.1170 -  RETURNS boolean
  5.1171 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster @> $2::ecluster';
  5.1172 -
  5.1173 -CREATE OPERATOR @> (
  5.1174 -  leftarg = ebox,
  5.1175 -  rightarg = ebox,
  5.1176 -  procedure = ebox_contains_castwrap,
  5.1177 -  commutator = <@,
  5.1178 -  restrict = areasel,
  5.1179 -  join = areajoinsel
  5.1180 -);
  5.1181 -
  5.1182 -CREATE FUNCTION ebox_contains_swapped_castwrap(ebox, ebox)
  5.1183 -  RETURNS boolean
  5.1184 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2::ecluster @> $1::ecluster';
  5.1185 -
  5.1186 -CREATE OPERATOR <@ (
  5.1187 -  leftarg = ebox,
  5.1188 -  rightarg = ebox,
  5.1189 -  procedure = ebox_contains_swapped_castwrap,
  5.1190 -  commutator = @>,
  5.1191 -  restrict = areasel,
  5.1192 -  join = areajoinsel
  5.1193 -);
  5.1194 -
  5.1195 -CREATE FUNCTION ebox_ecluster_contains_castwrap(ebox, ecluster)
  5.1196 -  RETURNS boolean
  5.1197 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster @> $2';
  5.1198 -
  5.1199 -CREATE OPERATOR @> (
  5.1200 -  leftarg = ebox,
  5.1201 -  rightarg = ecluster,
  5.1202 -  procedure = ebox_ecluster_contains_castwrap,
  5.1203 -  commutator = <@,
  5.1204 -  restrict = areasel,
  5.1205 -  join = areajoinsel
  5.1206 -);
  5.1207 -
  5.1208 -CREATE FUNCTION ebox_ecluster_contains_castwrap(ecluster, ebox)
  5.1209 -  RETURNS boolean
  5.1210 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2::ecluster @> $1';
  5.1211 -
  5.1212 -CREATE OPERATOR <@ (
  5.1213 -  leftarg = ecluster,
  5.1214 -  rightarg = ebox,
  5.1215 -  procedure = ebox_ecluster_contains_castwrap,
  5.1216 -  commutator = @>,
  5.1217 -  restrict = areasel,
  5.1218 -  join = areajoinsel
  5.1219 -);
  5.1220 -
  5.1221 -CREATE FUNCTION ecluster_ebox_contains_castwrap(ecluster, ebox)
  5.1222 -  RETURNS boolean
  5.1223 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 @> $2::ecluster';
  5.1224 -
  5.1225 -CREATE OPERATOR @> (
  5.1226 -  leftarg = ecluster,
  5.1227 -  rightarg = ebox,
  5.1228 -  procedure = ecluster_ebox_contains_castwrap,
  5.1229 -  commutator = <@,
  5.1230 -  restrict = areasel,
  5.1231 -  join = areajoinsel
  5.1232 -);
  5.1233 -
  5.1234 -CREATE FUNCTION ecluster_ebox_contains_castwrap(ebox, ecluster)
  5.1235 -  RETURNS boolean
  5.1236 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 @> $1::ecluster';
  5.1237 -
  5.1238 -CREATE OPERATOR <@ (
  5.1239 -  leftarg = ebox,
  5.1240 -  rightarg = ecluster,
  5.1241 -  procedure = ecluster_ebox_contains_castwrap,
  5.1242 -  commutator = @>,
  5.1243 -  restrict = areasel,
  5.1244 -  join = areajoinsel
  5.1245 -);
  5.1246 -
  5.1247 -CREATE OPERATOR <-> (
  5.1248 -  leftarg = epoint,
  5.1249 -  rightarg = epoint,
  5.1250 -  procedure = epoint_distance_proc,
  5.1251 -  commutator = <->
  5.1252 -);
  5.1253 -
  5.1254 -CREATE OPERATOR <-> (
  5.1255 -  leftarg = epoint,
  5.1256 -  rightarg = ecircle,
  5.1257 -  procedure = epoint_ecircle_distance_proc,
  5.1258 -  commutator = <->
  5.1259 -);
  5.1260 -
  5.1261 -CREATE FUNCTION epoint_ecircle_distance_commutator(ecircle, epoint)
  5.1262 -  RETURNS float8
  5.1263 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  5.1264 -
  5.1265 -CREATE OPERATOR <-> (
  5.1266 -  leftarg = ecircle,
  5.1267 -  rightarg = epoint,
  5.1268 -  procedure = epoint_ecircle_distance_commutator,
  5.1269 -  commutator = <->
  5.1270 -);
  5.1271 -
  5.1272 -CREATE OPERATOR <-> (
  5.1273 -  leftarg = epoint,
  5.1274 -  rightarg = ecluster,
  5.1275 -  procedure = epoint_ecluster_distance_proc,
  5.1276 -  commutator = <->
  5.1277 -);
  5.1278 -
  5.1279 -CREATE FUNCTION epoint_ecluster_distance_commutator(ecluster, epoint)
  5.1280 -  RETURNS float8
  5.1281 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  5.1282 -
  5.1283 -CREATE OPERATOR <-> (
  5.1284 -  leftarg = ecluster,
  5.1285 -  rightarg = epoint,
  5.1286 -  procedure = epoint_ecluster_distance_commutator,
  5.1287 -  commutator = <->
  5.1288 -);
  5.1289 -
  5.1290 -CREATE OPERATOR <-> (
  5.1291 -  leftarg = ecircle,
  5.1292 -  rightarg = ecircle,
  5.1293 -  procedure = ecircle_distance_proc,
  5.1294 -  commutator = <->
  5.1295 -);
  5.1296 -
  5.1297 -CREATE OPERATOR <-> (
  5.1298 -  leftarg = ecircle,
  5.1299 -  rightarg = ecluster,
  5.1300 -  procedure = ecircle_ecluster_distance_proc,
  5.1301 -  commutator = <->
  5.1302 -);
  5.1303 -
  5.1304 -CREATE FUNCTION ecircle_ecluster_distance_commutator(ecluster, ecircle)
  5.1305 -  RETURNS float8
  5.1306 -  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  5.1307 -
  5.1308 -CREATE OPERATOR <-> (
  5.1309 -  leftarg = ecluster,
  5.1310 -  rightarg = ecircle,
  5.1311 -  procedure = ecircle_ecluster_distance_commutator,
  5.1312 -  commutator = <->
  5.1313 -);
  5.1314 -
  5.1315 -CREATE OPERATOR <-> (
  5.1316 -  leftarg = ecluster,
  5.1317 -  rightarg = ecluster,
  5.1318 -  procedure = ecluster_distance_proc,
  5.1319 -  commutator = <->
  5.1320 -);
  5.1321 -
  5.1322 -CREATE FUNCTION epoint_ebox_distance_castwrap(epoint, ebox)
  5.1323 -  RETURNS float8
  5.1324 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  5.1325 -
  5.1326 -CREATE OPERATOR <-> (
  5.1327 -  leftarg = epoint,
  5.1328 -  rightarg = ebox,
  5.1329 -  procedure = epoint_ebox_distance_castwrap,
  5.1330 -  commutator = <->
  5.1331 -);
  5.1332 -
  5.1333 -CREATE FUNCTION epoint_ebox_distance_castwrap(ebox, epoint)
  5.1334 -  RETURNS float8
  5.1335 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  5.1336 -
  5.1337 -CREATE OPERATOR <-> (
  5.1338 -  leftarg = ebox,
  5.1339 -  rightarg = epoint,
  5.1340 -  procedure = epoint_ebox_distance_castwrap,
  5.1341 -  commutator = <->
  5.1342 -);
  5.1343 -
  5.1344 -CREATE FUNCTION ebox_distance_castwrap(ebox, ebox)
  5.1345 -  RETURNS float8
  5.1346 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2::ecluster';
  5.1347 -
  5.1348 -CREATE OPERATOR <-> (
  5.1349 -  leftarg = ebox,
  5.1350 -  rightarg = ebox,
  5.1351 -  procedure = ebox_distance_castwrap,
  5.1352 -  commutator = <->
  5.1353 -);
  5.1354 -
  5.1355 -CREATE FUNCTION ebox_ecircle_distance_castwrap(ebox, ecircle)
  5.1356 -  RETURNS float8
  5.1357 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  5.1358 -
  5.1359 -CREATE OPERATOR <-> (
  5.1360 -  leftarg = ebox,
  5.1361 -  rightarg = ecircle,
  5.1362 -  procedure = ebox_ecircle_distance_castwrap,
  5.1363 -  commutator = <->
  5.1364 -);
  5.1365 -
  5.1366 -CREATE FUNCTION ebox_ecircle_distance_castwrap(ecircle, ebox)
  5.1367 -  RETURNS float8
  5.1368 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  5.1369 -
  5.1370 -CREATE OPERATOR <-> (
  5.1371 -  leftarg = ecircle,
  5.1372 -  rightarg = ebox,
  5.1373 -  procedure = ebox_ecircle_distance_castwrap,
  5.1374 -  commutator = <->
  5.1375 -);
  5.1376 -
  5.1377 -CREATE FUNCTION ebox_ecluster_distance_castwrap(ebox, ecluster)
  5.1378 -  RETURNS float8
  5.1379 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  5.1380 -
  5.1381 -CREATE OPERATOR <-> (
  5.1382 -  leftarg = ebox,
  5.1383 -  rightarg = ecluster,
  5.1384 -  procedure = ebox_ecluster_distance_castwrap,
  5.1385 -  commutator = <->
  5.1386 -);
  5.1387 -
  5.1388 -CREATE FUNCTION ebox_ecluster_distance_castwrap(ecluster, ebox)
  5.1389 -  RETURNS float8
  5.1390 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  5.1391 -
  5.1392 -CREATE OPERATOR <-> (
  5.1393 -  leftarg = ecluster,
  5.1394 -  rightarg = ebox,
  5.1395 -  procedure = ebox_ecluster_distance_castwrap,
  5.1396 -  commutator = <->
  5.1397 -);
  5.1398 -
  5.1399 -CREATE OPERATOR <=> (
  5.1400 -  leftarg = ecluster,
  5.1401 -  rightarg = epoint_with_sample_count,
  5.1402 -  procedure = fair_distance_operator_proc
  5.1403 -);
  5.1404 -
  5.1405 -
  5.1406 -----------------
  5.1407 --- GiST index --
  5.1408 -----------------
  5.1409 -
  5.1410 -CREATE FUNCTION pgl_gist_consistent(internal, internal, smallint, oid, internal)
  5.1411 -  RETURNS boolean
  5.1412 -  LANGUAGE C STRICT
  5.1413 -  AS '$libdir/latlon-v0009', 'pgl_gist_consistent';
  5.1414 -
  5.1415 -CREATE FUNCTION pgl_gist_union(internal, internal)
  5.1416 -  RETURNS internal
  5.1417 -  LANGUAGE C STRICT
  5.1418 -  AS '$libdir/latlon-v0009', 'pgl_gist_union';
  5.1419 -
  5.1420 -CREATE FUNCTION pgl_gist_compress_epoint(internal)
  5.1421 -  RETURNS internal
  5.1422 -  LANGUAGE C STRICT
  5.1423 -  AS '$libdir/latlon-v0009', 'pgl_gist_compress_epoint';
  5.1424 -
  5.1425 -CREATE FUNCTION pgl_gist_compress_ecircle(internal)
  5.1426 -  RETURNS internal
  5.1427 -  LANGUAGE C STRICT
  5.1428 -  AS '$libdir/latlon-v0009', 'pgl_gist_compress_ecircle';
  5.1429 -
  5.1430 -CREATE FUNCTION pgl_gist_compress_ecluster(internal)
  5.1431 -  RETURNS internal
  5.1432 -  LANGUAGE C STRICT
  5.1433 -  AS '$libdir/latlon-v0009', 'pgl_gist_compress_ecluster';
  5.1434 -
  5.1435 -CREATE FUNCTION pgl_gist_decompress(internal)
  5.1436 -  RETURNS internal
  5.1437 -  LANGUAGE C STRICT
  5.1438 -  AS '$libdir/latlon-v0009', 'pgl_gist_decompress';
  5.1439 -
  5.1440 -CREATE FUNCTION pgl_gist_penalty(internal, internal, internal)
  5.1441 -  RETURNS internal
  5.1442 -  LANGUAGE C STRICT
  5.1443 -  AS '$libdir/latlon-v0009', 'pgl_gist_penalty';
  5.1444 -
  5.1445 -CREATE FUNCTION pgl_gist_picksplit(internal, internal)
  5.1446 -  RETURNS internal
  5.1447 -  LANGUAGE C STRICT
  5.1448 -  AS '$libdir/latlon-v0009', 'pgl_gist_picksplit';
  5.1449 -
  5.1450 -CREATE FUNCTION pgl_gist_same(internal, internal, internal)
  5.1451 -  RETURNS internal
  5.1452 -  LANGUAGE C STRICT
  5.1453 -  AS '$libdir/latlon-v0009', 'pgl_gist_same';
  5.1454 -
  5.1455 -CREATE FUNCTION pgl_gist_distance(internal, internal, smallint, oid)
  5.1456 -  RETURNS internal
  5.1457 -  LANGUAGE C STRICT
  5.1458 -  AS '$libdir/latlon-v0009', 'pgl_gist_distance';
  5.1459 -
  5.1460 -CREATE OPERATOR CLASS epoint_ops
  5.1461 -  DEFAULT FOR TYPE epoint USING gist AS
  5.1462 -  OPERATOR  11 = ,
  5.1463 -  OPERATOR  22 &&  (epoint, ebox),
  5.1464 -  OPERATOR 222 <@  (epoint, ebox),
  5.1465 -  OPERATOR  23 &&  (epoint, ecircle),
  5.1466 -  OPERATOR  24 &&  (epoint, ecluster),
  5.1467 -  OPERATOR 124 &&+ (epoint, ecluster),
  5.1468 -  OPERATOR 224 <@  (epoint, ecluster),
  5.1469 -  OPERATOR  31 <-> (epoint, epoint) FOR ORDER BY float_ops,
  5.1470 -  OPERATOR  32 <-> (epoint, ebox) FOR ORDER BY float_ops,
  5.1471 -  OPERATOR  33 <-> (epoint, ecircle) FOR ORDER BY float_ops,
  5.1472 -  OPERATOR  34 <-> (epoint, ecluster) FOR ORDER BY float_ops,
  5.1473 -  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  5.1474 -  FUNCTION 2 pgl_gist_union(internal, internal),
  5.1475 -  FUNCTION 3 pgl_gist_compress_epoint(internal),
  5.1476 -  FUNCTION 4 pgl_gist_decompress(internal),
  5.1477 -  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  5.1478 -  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  5.1479 -  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  5.1480 -  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  5.1481 -  STORAGE ekey_point;
  5.1482 -
  5.1483 -CREATE OPERATOR CLASS ecircle_ops
  5.1484 -  DEFAULT FOR TYPE ecircle USING gist AS
  5.1485 -  OPERATOR  13 = ,
  5.1486 -  OPERATOR  21 &&  (ecircle, epoint),
  5.1487 -  OPERATOR  22 &&  (ecircle, ebox),
  5.1488 -  OPERATOR 122 &&+ (ecircle, ebox),
  5.1489 -  OPERATOR  23 &&  (ecircle, ecircle),
  5.1490 -  OPERATOR  24 &&  (ecircle, ecluster),
  5.1491 -  OPERATOR 124 &&+ (ecircle, ecluster),
  5.1492 -  OPERATOR  31 <-> (ecircle, epoint) FOR ORDER BY float_ops,
  5.1493 -  OPERATOR  32 <-> (ecircle, ebox) FOR ORDER BY float_ops,
  5.1494 -  OPERATOR  33 <-> (ecircle, ecircle) FOR ORDER BY float_ops,
  5.1495 -  OPERATOR  34 <-> (ecircle, ecluster) FOR ORDER BY float_ops,
  5.1496 -  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  5.1497 -  FUNCTION 2 pgl_gist_union(internal, internal),
  5.1498 -  FUNCTION 3 pgl_gist_compress_ecircle(internal),
  5.1499 -  FUNCTION 4 pgl_gist_decompress(internal),
  5.1500 -  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  5.1501 -  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  5.1502 -  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  5.1503 -  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  5.1504 -  STORAGE ekey_area;
  5.1505 -
  5.1506 -CREATE OPERATOR CLASS ecluster_ops
  5.1507 -  DEFAULT FOR TYPE ecluster USING gist AS
  5.1508 -  OPERATOR  21 &&  (ecluster, epoint),
  5.1509 -  OPERATOR 121 &&+ (ecluster, epoint),
  5.1510 -  OPERATOR 221 @>  (ecluster, epoint),
  5.1511 -  OPERATOR  22 &&  (ecluster, ebox),
  5.1512 -  OPERATOR 122 &&+ (ecluster, ebox),
  5.1513 -  OPERATOR 222 @>  (ecluster, ebox),
  5.1514 -  OPERATOR 322 <@  (ecluster, ebox),
  5.1515 -  OPERATOR  23 &&  (ecluster, ecircle),
  5.1516 -  OPERATOR 123 &&+ (ecluster, ecircle),
  5.1517 -  OPERATOR  24 &&  (ecluster, ecluster),
  5.1518 -  OPERATOR 124 &&+ (ecluster, ecluster),
  5.1519 -  OPERATOR 224 @>  (ecluster, ecluster),
  5.1520 -  OPERATOR 324 <@  (ecluster, ecluster),
  5.1521 -  OPERATOR  31 <-> (ecluster, epoint) FOR ORDER BY float_ops,
  5.1522 -  OPERATOR  32 <-> (ecluster, ebox) FOR ORDER BY float_ops,
  5.1523 -  OPERATOR  33 <-> (ecluster, ecircle) FOR ORDER BY float_ops,
  5.1524 -  OPERATOR  34 <-> (ecluster, ecluster) FOR ORDER BY float_ops,
  5.1525 -  OPERATOR 131 <=> (ecluster, epoint_with_sample_count) FOR ORDER BY float_ops,
  5.1526 -  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  5.1527 -  FUNCTION 2 pgl_gist_union(internal, internal),
  5.1528 -  FUNCTION 3 pgl_gist_compress_ecluster(internal),
  5.1529 -  FUNCTION 4 pgl_gist_decompress(internal),
  5.1530 -  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  5.1531 -  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  5.1532 -  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  5.1533 -  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  5.1534 -  STORAGE ekey_area;
  5.1535 -
  5.1536 -
  5.1537 ----------------------
  5.1538 --- alias functions --
  5.1539 ----------------------
  5.1540 -
  5.1541 -CREATE FUNCTION distance(epoint, epoint)
  5.1542 -  RETURNS float8
  5.1543 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2';
  5.1544 -
  5.1545 -CREATE FUNCTION distance(ecluster, epoint)
  5.1546 -  RETURNS float8
  5.1547 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2';
  5.1548 -
  5.1549 -CREATE FUNCTION distance_within(epoint, epoint, float8)
  5.1550 -  RETURNS boolean
  5.1551 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && ecircle($2, $3)';
  5.1552 -
  5.1553 -CREATE FUNCTION distance_within(ecluster, epoint, float8)
  5.1554 -  RETURNS boolean
  5.1555 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && ecircle($2, $3)';
  5.1556 -
  5.1557 -CREATE FUNCTION fair_distance(ecluster, epoint, int4 = 10000)
  5.1558 -  RETURNS float8
  5.1559 -  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <=> epoint_with_sample_count($2, $3)';
  5.1560 -
  5.1561 -
  5.1562 ---------------------------------
  5.1563 --- other data storage formats --
  5.1564 ---------------------------------
  5.1565 -
  5.1566 -CREATE FUNCTION coords_to_epoint(float8, float8, text = 'epoint')
  5.1567 -  RETURNS epoint
  5.1568 -  LANGUAGE plpgsql IMMUTABLE STRICT AS $$
  5.1569 -    DECLARE
  5.1570 -      "result" epoint;
  5.1571 -    BEGIN
  5.1572 -      IF $3 = 'epoint_lonlat' THEN
  5.1573 -        -- avoid dynamic command execution for better performance
  5.1574 -        RETURN epoint($2, $1);
  5.1575 -      END IF;
  5.1576 -      IF $3 = 'epoint' OR $3 = 'epoint_latlon' THEN
  5.1577 -        -- avoid dynamic command execution for better performance
  5.1578 -        RETURN epoint($1, $2);
  5.1579 -      END IF;
  5.1580 -      EXECUTE 'SELECT ' || $3 || '($1, $2)' INTO STRICT "result" USING $1, $2;
  5.1581 -      RETURN "result";
  5.1582 -    END;
  5.1583 -  $$;
  5.1584 -
  5.1585 -CREATE FUNCTION GeoJSON_LinearRing_vertices(jsonb, text = 'epoint_lonlat')
  5.1586 -  RETURNS SETOF jsonb
  5.1587 -  LANGUAGE sql IMMUTABLE STRICT AS $$
  5.1588 -    SELECT "result" FROM
  5.1589 -      ( SELECT jsonb_array_length($1) - 1 ) AS "lastindex_row" ("lastindex")
  5.1590 -      CROSS JOIN LATERAL jsonb_array_elements(
  5.1591 -        CASE WHEN
  5.1592 -          coords_to_epoint(
  5.1593 -            ($1->0->>0)::float8,
  5.1594 -            ($1->0->>1)::float8,
  5.1595 -            $2
  5.1596 -          ) = coords_to_epoint(
  5.1597 -            ($1->"lastindex"->>0)::float8,
  5.1598 -            ($1->"lastindex"->>1)::float8,
  5.1599 -            $2
  5.1600 -          )
  5.1601 -        THEN
  5.1602 -          $1 - "lastindex"
  5.1603 -        ELSE
  5.1604 -          $1
  5.1605 -        END
  5.1606 -      ) AS "result_row" ("result")
  5.1607 -  $$;
  5.1608 -
  5.1609 -CREATE FUNCTION GeoJSON_to_epoint(jsonb, text = 'epoint_lonlat')
  5.1610 -  RETURNS epoint
  5.1611 -  LANGUAGE sql IMMUTABLE STRICT AS $$
  5.1612 -    SELECT CASE
  5.1613 -    WHEN $1->>'type' = 'Point' THEN
  5.1614 -      coords_to_epoint(
  5.1615 -        ($1->'coordinates'->>0)::float8,
  5.1616 -        ($1->'coordinates'->>1)::float8,
  5.1617 -        $2
  5.1618 -      )
  5.1619 -    WHEN $1->>'type' = 'Feature' THEN
  5.1620 -      GeoJSON_to_epoint($1->'geometry', $2)
  5.1621 -    ELSE
  5.1622 -      NULL
  5.1623 -    END
  5.1624 -  $$;
  5.1625 -
  5.1626 -CREATE FUNCTION GeoJSON_to_ecluster(jsonb, text = 'epoint_lonlat')
  5.1627 -  RETURNS ecluster
  5.1628 -  LANGUAGE sql IMMUTABLE STRICT AS $$
  5.1629 -    SELECT CASE $1->>'type'
  5.1630 -    WHEN 'Point' THEN
  5.1631 -      coords_to_epoint(
  5.1632 -        ($1->'coordinates'->>0)::float8,
  5.1633 -        ($1->'coordinates'->>1)::float8,
  5.1634 -        $2
  5.1635 -      )::ecluster
  5.1636 -    WHEN 'MultiPoint' THEN
  5.1637 -      ( SELECT ecluster_create_multipoint(array_agg(
  5.1638 -          coords_to_epoint(
  5.1639 -            ("coord"->>0)::float8,
  5.1640 -            ("coord"->>1)::float8,
  5.1641 -            $2
  5.1642 -          )
  5.1643 -        ))
  5.1644 -        FROM jsonb_array_elements($1->'coordinates') AS "coord"
  5.1645 -      )
  5.1646 -    WHEN 'LineString' THEN
  5.1647 -      ( SELECT ecluster_create_path(array_agg(
  5.1648 -          coords_to_epoint(
  5.1649 -            ("coord"->>0)::float8,
  5.1650 -            ("coord"->>1)::float8,
  5.1651 -            $2
  5.1652 -          )
  5.1653 -        ))
  5.1654 -        FROM jsonb_array_elements($1->'coordinates') AS "coord"
  5.1655 -      )
  5.1656 -    WHEN 'MultiLineString' THEN
  5.1657 -      ( SELECT ecluster_concat(array_agg(
  5.1658 -          ( SELECT ecluster_create_path(array_agg(
  5.1659 -              coords_to_epoint(
  5.1660 -                ("coord"->>0)::float8,
  5.1661 -                ("coord"->>1)::float8,
  5.1662 -                $2
  5.1663 -              )
  5.1664 -            ))
  5.1665 -            FROM jsonb_array_elements("coord_array") AS "coord"
  5.1666 -          )
  5.1667 -        ))
  5.1668 -        FROM jsonb_array_elements($1->'coordinates') AS "coord_array"
  5.1669 -      )
  5.1670 -    WHEN 'Polygon' THEN
  5.1671 -      ( SELECT ecluster_concat(array_agg(
  5.1672 -          ( SELECT ecluster_create_polygon(array_agg(
  5.1673 -              coords_to_epoint(
  5.1674 -                ("coord"->>0)::float8,
  5.1675 -                ("coord"->>1)::float8,
  5.1676 -                $2
  5.1677 -              )
  5.1678 -            ))
  5.1679 -            FROM GeoJSON_LinearRing_vertices("coord_array", $2) AS "coord"
  5.1680 -          )
  5.1681 -        ))
  5.1682 -        FROM jsonb_array_elements($1->'coordinates') AS "coord_array"
  5.1683 -      )
  5.1684 -    WHEN 'MultiPolygon' THEN
  5.1685 -      ( SELECT ecluster_concat(array_agg(
  5.1686 -          ( SELECT ecluster_concat(array_agg(
  5.1687 -              ( SELECT ecluster_create_polygon(array_agg(
  5.1688 -                  coords_to_epoint(
  5.1689 -                    ("coord"->>0)::float8,
  5.1690 -                    ("coord"->>1)::float8,
  5.1691 -                    $2
  5.1692 -                  )
  5.1693 -                ))
  5.1694 -                FROM GeoJSON_LinearRing_vertices("coord_array", $2) AS "coord"
  5.1695 -              )
  5.1696 -            ))
  5.1697 -            FROM jsonb_array_elements("coord_array_array") AS "coord_array"
  5.1698 -          )
  5.1699 -        ))
  5.1700 -        FROM jsonb_array_elements($1->'coordinates') AS "coord_array_array"
  5.1701 -      )
  5.1702 -    WHEN 'GeometryCollection' THEN
  5.1703 -      ( SELECT ecluster_concat(array_agg(
  5.1704 -          GeoJSON_to_ecluster("geometry", $2)
  5.1705 -        ))
  5.1706 -        FROM jsonb_array_elements($1->'geometries') AS "geometry"
  5.1707 -      )
  5.1708 -    WHEN 'Feature' THEN
  5.1709 -      GeoJSON_to_ecluster($1->'geometry', $2)
  5.1710 -    WHEN 'FeatureCollection' THEN
  5.1711 -      ( SELECT ecluster_concat(array_agg(
  5.1712 -          GeoJSON_to_ecluster("feature", $2)
  5.1713 -        ))
  5.1714 -        FROM jsonb_array_elements($1->'features') AS "feature"
  5.1715 -      )
  5.1716 -    ELSE
  5.1717 -      NULL
  5.1718 -    END
  5.1719 -  $$;
  5.1720 -
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/latlon--0.14.sql	Tue Feb 11 01:59:04 2020 +0100
     6.3 @@ -0,0 +1,1717 @@
     6.4 +
     6.5 +----------------------------------------
     6.6 +-- forward declarations (shell types) --
     6.7 +----------------------------------------
     6.8 +
     6.9 +CREATE TYPE ekey_point;
    6.10 +CREATE TYPE ekey_area;
    6.11 +CREATE TYPE epoint;
    6.12 +CREATE TYPE epoint_with_sample_count;
    6.13 +CREATE TYPE ebox;
    6.14 +CREATE TYPE ecircle;
    6.15 +CREATE TYPE ecluster;
    6.16 +
    6.17 +
    6.18 +------------------------------------------------------------
    6.19 +-- dummy input/output functions for dummy index key types --
    6.20 +------------------------------------------------------------
    6.21 +
    6.22 +CREATE FUNCTION ekey_point_in_dummy(cstring)
    6.23 +  RETURNS ekey_point
    6.24 +  LANGUAGE C IMMUTABLE STRICT
    6.25 +  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    6.26 +
    6.27 +CREATE FUNCTION ekey_point_out_dummy(ekey_point)
    6.28 +  RETURNS cstring
    6.29 +  LANGUAGE C IMMUTABLE STRICT
    6.30 +  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    6.31 +
    6.32 +CREATE FUNCTION ekey_area_in_dummy(cstring)
    6.33 +  RETURNS ekey_area
    6.34 +  LANGUAGE C IMMUTABLE STRICT
    6.35 +  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    6.36 +
    6.37 +CREATE FUNCTION ekey_area_out_dummy(ekey_area)
    6.38 +  RETURNS cstring
    6.39 +  LANGUAGE C IMMUTABLE STRICT
    6.40 +  AS '$libdir/latlon-v0009', 'pgl_notimpl';
    6.41 +
    6.42 +
    6.43 +--------------------------
    6.44 +-- text input functions --
    6.45 +--------------------------
    6.46 +
    6.47 +CREATE FUNCTION epoint_in(cstring)
    6.48 +  RETURNS epoint
    6.49 +  LANGUAGE C IMMUTABLE STRICT
    6.50 +  AS '$libdir/latlon-v0009', 'pgl_epoint_in';
    6.51 +
    6.52 +CREATE FUNCTION epoint_with_sample_count_in(cstring)
    6.53 +  RETURNS epoint_with_sample_count
    6.54 +  LANGUAGE C IMMUTABLE STRICT
    6.55 +  AS '$libdir/latlon-v0009', 'pgl_epoint_with_sample_count_in';
    6.56 +
    6.57 +CREATE FUNCTION ebox_in(cstring)
    6.58 +  RETURNS ebox
    6.59 +  LANGUAGE C IMMUTABLE STRICT
    6.60 +  AS '$libdir/latlon-v0009', 'pgl_ebox_in';
    6.61 +
    6.62 +CREATE FUNCTION ecircle_in(cstring)
    6.63 +  RETURNS ecircle
    6.64 +  LANGUAGE C IMMUTABLE STRICT
    6.65 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_in';
    6.66 +
    6.67 +CREATE FUNCTION ecluster_in(cstring)
    6.68 +  RETURNS ecluster
    6.69 +  LANGUAGE C IMMUTABLE STRICT
    6.70 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_in';
    6.71 +
    6.72 +
    6.73 +---------------------------
    6.74 +-- text output functions --
    6.75 +---------------------------
    6.76 +
    6.77 +CREATE FUNCTION epoint_out(epoint)
    6.78 +  RETURNS cstring
    6.79 +  LANGUAGE C IMMUTABLE STRICT
    6.80 +  AS '$libdir/latlon-v0009', 'pgl_epoint_out';
    6.81 +
    6.82 +CREATE FUNCTION epoint_with_sample_count_out(epoint_with_sample_count)
    6.83 +  RETURNS cstring
    6.84 +  LANGUAGE C IMMUTABLE STRICT
    6.85 +  AS '$libdir/latlon-v0009', 'pgl_epoint_with_sample_count_out';
    6.86 +
    6.87 +CREATE FUNCTION ebox_out(ebox)
    6.88 +  RETURNS cstring
    6.89 +  LANGUAGE C IMMUTABLE STRICT
    6.90 +  AS '$libdir/latlon-v0009', 'pgl_ebox_out';
    6.91 +
    6.92 +CREATE FUNCTION ecircle_out(ecircle)
    6.93 +  RETURNS cstring
    6.94 +  LANGUAGE C IMMUTABLE STRICT
    6.95 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_out';
    6.96 +
    6.97 +CREATE FUNCTION ecluster_out(ecluster)
    6.98 +  RETURNS cstring
    6.99 +  LANGUAGE C IMMUTABLE STRICT
   6.100 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_out';
   6.101 +
   6.102 +
   6.103 +--------------------------
   6.104 +-- binary I/O functions --
   6.105 +--------------------------
   6.106 +
   6.107 +CREATE FUNCTION epoint_recv(internal)
   6.108 +  RETURNS epoint
   6.109 +  LANGUAGE C IMMUTABLE STRICT
   6.110 +  AS '$libdir/latlon-v0009', 'pgl_epoint_recv';
   6.111 +
   6.112 +CREATE FUNCTION ebox_recv(internal)
   6.113 +  RETURNS ebox
   6.114 +  LANGUAGE C IMMUTABLE STRICT
   6.115 +  AS '$libdir/latlon-v0009', 'pgl_ebox_recv';
   6.116 +
   6.117 +CREATE FUNCTION ecircle_recv(internal)
   6.118 +  RETURNS ecircle
   6.119 +  LANGUAGE C IMMUTABLE STRICT
   6.120 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_recv';
   6.121 +
   6.122 +CREATE FUNCTION epoint_send(epoint)
   6.123 +  RETURNS bytea
   6.124 +  LANGUAGE C IMMUTABLE STRICT
   6.125 +  AS '$libdir/latlon-v0009', 'pgl_epoint_send';
   6.126 +
   6.127 +CREATE FUNCTION ebox_send(ebox)
   6.128 +  RETURNS bytea
   6.129 +  LANGUAGE C IMMUTABLE STRICT
   6.130 +  AS '$libdir/latlon-v0009', 'pgl_ebox_send';
   6.131 +
   6.132 +CREATE FUNCTION ecircle_send(ecircle)
   6.133 +  RETURNS bytea
   6.134 +  LANGUAGE C IMMUTABLE STRICT
   6.135 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_send';
   6.136 +
   6.137 +
   6.138 +-----------------------------------------------
   6.139 +-- type definitions of dummy index key types --
   6.140 +-----------------------------------------------
   6.141 +
   6.142 +CREATE TYPE ekey_point (
   6.143 +  internallength = 8,
   6.144 +  input = ekey_point_in_dummy,
   6.145 +  output = ekey_point_out_dummy,
   6.146 +  alignment = char );
   6.147 +
   6.148 +CREATE TYPE ekey_area (
   6.149 +  internallength = 9,
   6.150 +  input = ekey_area_in_dummy,
   6.151 +  output = ekey_area_out_dummy,
   6.152 +  alignment = char );
   6.153 +
   6.154 +
   6.155 +------------------------------------------
   6.156 +-- definitions of geographic data types --
   6.157 +------------------------------------------
   6.158 +
   6.159 +CREATE TYPE epoint (
   6.160 +  internallength = 16,
   6.161 +  input = epoint_in,
   6.162 +  output = epoint_out,
   6.163 +  receive = epoint_recv,
   6.164 +  send = epoint_send,
   6.165 +  alignment = double );
   6.166 +
   6.167 +CREATE TYPE epoint_with_sample_count (
   6.168 +  internallength = 20,
   6.169 +  input = epoint_with_sample_count_in,
   6.170 +  output = epoint_with_sample_count_out,
   6.171 +  alignment = double );
   6.172 +
   6.173 +CREATE TYPE ebox (
   6.174 +  internallength = 32,
   6.175 +  input = ebox_in,
   6.176 +  output = ebox_out,
   6.177 +  receive = ebox_recv,
   6.178 +  send = ebox_send,
   6.179 +  alignment = double );
   6.180 +
   6.181 +CREATE TYPE ecircle (
   6.182 +  internallength = 24,
   6.183 +  input = ecircle_in,
   6.184 +  output = ecircle_out,
   6.185 +  receive = ecircle_recv,
   6.186 +  send = ecircle_send,
   6.187 +  alignment = double );
   6.188 +
   6.189 +CREATE TYPE ecluster (
   6.190 +  internallength = VARIABLE,
   6.191 +  input = ecluster_in,
   6.192 +  output = ecluster_out,
   6.193 +  alignment = double,
   6.194 +  storage = external );
   6.195 +
   6.196 +
   6.197 +--------------------
   6.198 +-- B-tree support --
   6.199 +--------------------
   6.200 +
   6.201 +-- begin of B-tree support for epoint
   6.202 +
   6.203 +CREATE FUNCTION epoint_btree_lt(epoint, epoint)
   6.204 +  RETURNS boolean
   6.205 +  LANGUAGE C IMMUTABLE STRICT
   6.206 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_lt';
   6.207 +
   6.208 +CREATE FUNCTION epoint_btree_le(epoint, epoint)
   6.209 +  RETURNS boolean
   6.210 +  LANGUAGE C IMMUTABLE STRICT
   6.211 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_le';
   6.212 +
   6.213 +CREATE FUNCTION epoint_btree_eq(epoint, epoint)
   6.214 +  RETURNS boolean
   6.215 +  LANGUAGE C IMMUTABLE STRICT
   6.216 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_eq';
   6.217 +
   6.218 +CREATE FUNCTION epoint_btree_ne(epoint, epoint)
   6.219 +  RETURNS boolean
   6.220 +  LANGUAGE C IMMUTABLE STRICT
   6.221 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_ne';
   6.222 +
   6.223 +CREATE FUNCTION epoint_btree_ge(epoint, epoint)
   6.224 +  RETURNS boolean
   6.225 +  LANGUAGE C IMMUTABLE STRICT
   6.226 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_ge';
   6.227 +
   6.228 +CREATE FUNCTION epoint_btree_gt(epoint, epoint)
   6.229 +  RETURNS boolean
   6.230 +  LANGUAGE C IMMUTABLE STRICT
   6.231 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_gt';
   6.232 +
   6.233 +CREATE OPERATOR <<< (
   6.234 +  leftarg = epoint,
   6.235 +  rightarg = epoint,
   6.236 +  procedure = epoint_btree_lt,
   6.237 +  commutator = >>>,
   6.238 +  negator = >>>=,
   6.239 +  restrict = scalarltsel,
   6.240 +  join = scalarltjoinsel
   6.241 +);
   6.242 +
   6.243 +CREATE OPERATOR <<<= (
   6.244 +  leftarg = epoint,
   6.245 +  rightarg = epoint,
   6.246 +  procedure = epoint_btree_le,
   6.247 +  commutator = >>>=,
   6.248 +  negator = >>>,
   6.249 +  restrict = scalarltsel,
   6.250 +  join = scalarltjoinsel
   6.251 +);
   6.252 +
   6.253 +CREATE OPERATOR = (
   6.254 +  leftarg = epoint,
   6.255 +  rightarg = epoint,
   6.256 +  procedure = epoint_btree_eq,
   6.257 +  commutator = =,
   6.258 +  negator = <>,
   6.259 +  restrict = eqsel,
   6.260 +  join = eqjoinsel,
   6.261 +  merges
   6.262 +);
   6.263 +
   6.264 +CREATE OPERATOR <> (
   6.265 +  leftarg = epoint,
   6.266 +  rightarg = epoint,
   6.267 +  procedure = epoint_btree_ne,
   6.268 +  commutator = <>,
   6.269 +  negator = =,
   6.270 +  restrict = neqsel,
   6.271 +  join = neqjoinsel
   6.272 +);
   6.273 +
   6.274 +CREATE OPERATOR >>>= (
   6.275 +  leftarg = epoint,
   6.276 +  rightarg = epoint,
   6.277 +  procedure = epoint_btree_ge,
   6.278 +  commutator = <<<=,
   6.279 +  negator = <<<,
   6.280 +  restrict = scalargtsel,
   6.281 +  join = scalargtjoinsel
   6.282 +);
   6.283 +
   6.284 +CREATE OPERATOR >>> (
   6.285 +  leftarg = epoint,
   6.286 +  rightarg = epoint,
   6.287 +  procedure = epoint_btree_gt,
   6.288 +  commutator = <<<,
   6.289 +  negator = <<<=,
   6.290 +  restrict = scalargtsel,
   6.291 +  join = scalargtjoinsel
   6.292 +);
   6.293 +
   6.294 +CREATE FUNCTION epoint_btree_cmp(epoint, epoint)
   6.295 +  RETURNS int4
   6.296 +  LANGUAGE C IMMUTABLE STRICT
   6.297 +  AS '$libdir/latlon-v0009', 'pgl_btree_epoint_cmp';
   6.298 +
   6.299 +CREATE OPERATOR CLASS epoint_btree_ops
   6.300 +  DEFAULT FOR TYPE epoint USING btree AS
   6.301 +  OPERATOR 1 <<< ,
   6.302 +  OPERATOR 2 <<<= ,
   6.303 +  OPERATOR 3 = ,
   6.304 +  OPERATOR 4 >>>= ,
   6.305 +  OPERATOR 5 >>> ,
   6.306 +  FUNCTION 1 epoint_btree_cmp(epoint, epoint);
   6.307 +
   6.308 +-- end of B-tree support for epoint
   6.309 +
   6.310 +-- begin of B-tree support for ebox
   6.311 +
   6.312 +CREATE FUNCTION ebox_btree_lt(ebox, ebox)
   6.313 +  RETURNS boolean
   6.314 +  LANGUAGE C IMMUTABLE STRICT
   6.315 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_lt';
   6.316 +
   6.317 +CREATE FUNCTION ebox_btree_le(ebox, ebox)
   6.318 +  RETURNS boolean
   6.319 +  LANGUAGE C IMMUTABLE STRICT
   6.320 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_le';
   6.321 +
   6.322 +CREATE FUNCTION ebox_btree_eq(ebox, ebox)
   6.323 +  RETURNS boolean
   6.324 +  LANGUAGE C IMMUTABLE STRICT
   6.325 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_eq';
   6.326 +
   6.327 +CREATE FUNCTION ebox_btree_ne(ebox, ebox)
   6.328 +  RETURNS boolean
   6.329 +  LANGUAGE C IMMUTABLE STRICT
   6.330 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_ne';
   6.331 +
   6.332 +CREATE FUNCTION ebox_btree_ge(ebox, ebox)
   6.333 +  RETURNS boolean
   6.334 +  LANGUAGE C IMMUTABLE STRICT
   6.335 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_ge';
   6.336 +
   6.337 +CREATE FUNCTION ebox_btree_gt(ebox, ebox)
   6.338 +  RETURNS boolean
   6.339 +  LANGUAGE C IMMUTABLE STRICT
   6.340 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_gt';
   6.341 +
   6.342 +CREATE OPERATOR <<< (
   6.343 +  leftarg = ebox,
   6.344 +  rightarg = ebox,
   6.345 +  procedure = ebox_btree_lt,
   6.346 +  commutator = >>>,
   6.347 +  negator = >>>=,
   6.348 +  restrict = scalarltsel,
   6.349 +  join = scalarltjoinsel
   6.350 +);
   6.351 +
   6.352 +CREATE OPERATOR <<<= (
   6.353 +  leftarg = ebox,
   6.354 +  rightarg = ebox,
   6.355 +  procedure = ebox_btree_le,
   6.356 +  commutator = >>>=,
   6.357 +  negator = >>>,
   6.358 +  restrict = scalarltsel,
   6.359 +  join = scalarltjoinsel
   6.360 +);
   6.361 +
   6.362 +CREATE OPERATOR = (
   6.363 +  leftarg = ebox,
   6.364 +  rightarg = ebox,
   6.365 +  procedure = ebox_btree_eq,
   6.366 +  commutator = =,
   6.367 +  negator = <>,
   6.368 +  restrict = eqsel,
   6.369 +  join = eqjoinsel,
   6.370 +  merges
   6.371 +);
   6.372 +
   6.373 +CREATE OPERATOR <> (
   6.374 +  leftarg = ebox,
   6.375 +  rightarg = ebox,
   6.376 +  procedure = ebox_btree_ne,
   6.377 +  commutator = <>,
   6.378 +  negator = =,
   6.379 +  restrict = neqsel,
   6.380 +  join = neqjoinsel
   6.381 +);
   6.382 +
   6.383 +CREATE OPERATOR >>>= (
   6.384 +  leftarg = ebox,
   6.385 +  rightarg = ebox,
   6.386 +  procedure = ebox_btree_ge,
   6.387 +  commutator = <<<=,
   6.388 +  negator = <<<,
   6.389 +  restrict = scalargtsel,
   6.390 +  join = scalargtjoinsel
   6.391 +);
   6.392 +
   6.393 +CREATE OPERATOR >>> (
   6.394 +  leftarg = ebox,
   6.395 +  rightarg = ebox,
   6.396 +  procedure = ebox_btree_gt,
   6.397 +  commutator = <<<,
   6.398 +  negator = <<<=,
   6.399 +  restrict = scalargtsel,
   6.400 +  join = scalargtjoinsel
   6.401 +);
   6.402 +
   6.403 +CREATE FUNCTION ebox_btree_cmp(ebox, ebox)
   6.404 +  RETURNS int4
   6.405 +  LANGUAGE C IMMUTABLE STRICT
   6.406 +  AS '$libdir/latlon-v0009', 'pgl_btree_ebox_cmp';
   6.407 +
   6.408 +CREATE OPERATOR CLASS ebox_btree_ops
   6.409 +  DEFAULT FOR TYPE ebox USING btree AS
   6.410 +  OPERATOR 1 <<< ,
   6.411 +  OPERATOR 2 <<<= ,
   6.412 +  OPERATOR 3 = ,
   6.413 +  OPERATOR 4 >>>= ,
   6.414 +  OPERATOR 5 >>> ,
   6.415 +  FUNCTION 1 ebox_btree_cmp(ebox, ebox);
   6.416 +
   6.417 +-- end of B-tree support for ebox
   6.418 +
   6.419 +-- begin of B-tree support for ecircle
   6.420 +
   6.421 +CREATE FUNCTION ecircle_btree_lt(ecircle, ecircle)
   6.422 +  RETURNS boolean
   6.423 +  LANGUAGE C IMMUTABLE STRICT
   6.424 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_lt';
   6.425 +
   6.426 +CREATE FUNCTION ecircle_btree_le(ecircle, ecircle)
   6.427 +  RETURNS boolean
   6.428 +  LANGUAGE C IMMUTABLE STRICT
   6.429 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_le';
   6.430 +
   6.431 +CREATE FUNCTION ecircle_btree_eq(ecircle, ecircle)
   6.432 +  RETURNS boolean
   6.433 +  LANGUAGE C IMMUTABLE STRICT
   6.434 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_eq';
   6.435 +
   6.436 +CREATE FUNCTION ecircle_btree_ne(ecircle, ecircle)
   6.437 +  RETURNS boolean
   6.438 +  LANGUAGE C IMMUTABLE STRICT
   6.439 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_ne';
   6.440 +
   6.441 +CREATE FUNCTION ecircle_btree_ge(ecircle, ecircle)
   6.442 +  RETURNS boolean
   6.443 +  LANGUAGE C IMMUTABLE STRICT
   6.444 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_ge';
   6.445 +
   6.446 +CREATE FUNCTION ecircle_btree_gt(ecircle, ecircle)
   6.447 +  RETURNS boolean
   6.448 +  LANGUAGE C IMMUTABLE STRICT
   6.449 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_gt';
   6.450 +
   6.451 +CREATE OPERATOR <<< (
   6.452 +  leftarg = ecircle,
   6.453 +  rightarg = ecircle,
   6.454 +  procedure = ecircle_btree_lt,
   6.455 +  commutator = >>>,
   6.456 +  negator = >>>=,
   6.457 +  restrict = scalarltsel,
   6.458 +  join = scalarltjoinsel
   6.459 +);
   6.460 +
   6.461 +CREATE OPERATOR <<<= (
   6.462 +  leftarg = ecircle,
   6.463 +  rightarg = ecircle,
   6.464 +  procedure = ecircle_btree_le,
   6.465 +  commutator = >>>=,
   6.466 +  negator = >>>,
   6.467 +  restrict = scalarltsel,
   6.468 +  join = scalarltjoinsel
   6.469 +);
   6.470 +
   6.471 +CREATE OPERATOR = (
   6.472 +  leftarg = ecircle,
   6.473 +  rightarg = ecircle,
   6.474 +  procedure = ecircle_btree_eq,
   6.475 +  commutator = =,
   6.476 +  negator = <>,
   6.477 +  restrict = eqsel,
   6.478 +  join = eqjoinsel,
   6.479 +  merges
   6.480 +);
   6.481 +
   6.482 +CREATE OPERATOR <> (
   6.483 +  leftarg = ecircle,
   6.484 +  rightarg = ecircle,
   6.485 +  procedure = ecircle_btree_ne,
   6.486 +  commutator = <>,
   6.487 +  negator = =,
   6.488 +  restrict = neqsel,
   6.489 +  join = neqjoinsel
   6.490 +);
   6.491 +
   6.492 +CREATE OPERATOR >>>= (
   6.493 +  leftarg = ecircle,
   6.494 +  rightarg = ecircle,
   6.495 +  procedure = ecircle_btree_ge,
   6.496 +  commutator = <<<=,
   6.497 +  negator = <<<,
   6.498 +  restrict = scalargtsel,
   6.499 +  join = scalargtjoinsel
   6.500 +);
   6.501 +
   6.502 +CREATE OPERATOR >>> (
   6.503 +  leftarg = ecircle,
   6.504 +  rightarg = ecircle,
   6.505 +  procedure = ecircle_btree_gt,
   6.506 +  commutator = <<<,
   6.507 +  negator = <<<=,
   6.508 +  restrict = scalargtsel,
   6.509 +  join = scalargtjoinsel
   6.510 +);
   6.511 +
   6.512 +CREATE FUNCTION ecircle_btree_cmp(ecircle, ecircle)
   6.513 +  RETURNS int4
   6.514 +  LANGUAGE C IMMUTABLE STRICT
   6.515 +  AS '$libdir/latlon-v0009', 'pgl_btree_ecircle_cmp';
   6.516 +
   6.517 +CREATE OPERATOR CLASS ecircle_btree_ops
   6.518 +  DEFAULT FOR TYPE ecircle USING btree AS
   6.519 +  OPERATOR 1 <<< ,
   6.520 +  OPERATOR 2 <<<= ,
   6.521 +  OPERATOR 3 = ,
   6.522 +  OPERATOR 4 >>>= ,
   6.523 +  OPERATOR 5 >>> ,
   6.524 +  FUNCTION 1 ecircle_btree_cmp(ecircle, ecircle);
   6.525 +
   6.526 +-- end of B-tree support for ecircle
   6.527 +
   6.528 +
   6.529 +----------------
   6.530 +-- type casts --
   6.531 +----------------
   6.532 +
   6.533 +CREATE FUNCTION cast_epoint_to_ebox(epoint)
   6.534 +  RETURNS ebox
   6.535 +  LANGUAGE C IMMUTABLE STRICT
   6.536 +  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ebox';
   6.537 +
   6.538 +CREATE CAST (epoint AS ebox) WITH FUNCTION cast_epoint_to_ebox(epoint);
   6.539 +
   6.540 +CREATE FUNCTION cast_epoint_to_ecircle(epoint)
   6.541 +  RETURNS ecircle
   6.542 +  LANGUAGE C IMMUTABLE STRICT
   6.543 +  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ecircle';
   6.544 +
   6.545 +CREATE CAST (epoint AS ecircle) WITH FUNCTION cast_epoint_to_ecircle(epoint);
   6.546 +
   6.547 +CREATE FUNCTION cast_epoint_to_ecluster(epoint)
   6.548 +  RETURNS ecluster
   6.549 +  LANGUAGE C IMMUTABLE STRICT
   6.550 +  AS '$libdir/latlon-v0009', 'pgl_epoint_to_ecluster';
   6.551 +
   6.552 +CREATE CAST (epoint AS ecluster) WITH FUNCTION cast_epoint_to_ecluster(epoint);
   6.553 +
   6.554 +CREATE FUNCTION cast_ebox_to_ecluster(ebox)
   6.555 +  RETURNS ecluster
   6.556 +  LANGUAGE C IMMUTABLE STRICT
   6.557 +  AS '$libdir/latlon-v0009', 'pgl_ebox_to_ecluster';
   6.558 +
   6.559 +CREATE CAST (ebox AS ecluster) WITH FUNCTION cast_ebox_to_ecluster(ebox);
   6.560 +
   6.561 +
   6.562 +---------------------------
   6.563 +-- constructor functions --
   6.564 +---------------------------
   6.565 +
   6.566 +CREATE FUNCTION epoint(float8, float8)
   6.567 +  RETURNS epoint
   6.568 +  LANGUAGE C IMMUTABLE STRICT
   6.569 +  AS '$libdir/latlon-v0009', 'pgl_create_epoint';
   6.570 +
   6.571 +CREATE FUNCTION epoint_latlon(float8, float8)
   6.572 +  RETURNS epoint
   6.573 +  LANGUAGE SQL IMMUTABLE STRICT AS $$
   6.574 +    SELECT epoint($1, $2)
   6.575 +  $$;
   6.576 +
   6.577 +CREATE FUNCTION epoint_lonlat(float8, float8)
   6.578 +  RETURNS epoint
   6.579 +  LANGUAGE SQL IMMUTABLE STRICT AS $$
   6.580 +    SELECT epoint($2, $1)
   6.581 +  $$;
   6.582 +
   6.583 +CREATE FUNCTION epoint_with_sample_count(epoint, int4)
   6.584 +  RETURNS epoint_with_sample_count
   6.585 +  LANGUAGE C IMMUTABLE STRICT
   6.586 +  AS '$libdir/latlon-v0009', 'pgl_create_epoint_with_sample_count';
   6.587 +
   6.588 +CREATE FUNCTION empty_ebox()
   6.589 +  RETURNS ebox
   6.590 +  LANGUAGE C IMMUTABLE STRICT
   6.591 +  AS '$libdir/latlon-v0009', 'pgl_create_empty_ebox';
   6.592 +
   6.593 +CREATE FUNCTION ebox(float8, float8, float8, float8)
   6.594 +  RETURNS ebox
   6.595 +  LANGUAGE C IMMUTABLE STRICT
   6.596 +  AS '$libdir/latlon-v0009', 'pgl_create_ebox';
   6.597 +
   6.598 +CREATE FUNCTION ebox(epoint, epoint)
   6.599 +  RETURNS ebox
   6.600 +  LANGUAGE C IMMUTABLE STRICT
   6.601 +  AS '$libdir/latlon-v0009', 'pgl_create_ebox_from_epoints';
   6.602 +
   6.603 +CREATE FUNCTION ecircle(float8, float8, float8)
   6.604 +  RETURNS ecircle
   6.605 +  LANGUAGE C IMMUTABLE STRICT
   6.606 +  AS '$libdir/latlon-v0009', 'pgl_create_ecircle';
   6.607 +
   6.608 +CREATE FUNCTION ecircle(epoint, float8)
   6.609 +  RETURNS ecircle
   6.610 +  LANGUAGE C IMMUTABLE STRICT
   6.611 +  AS '$libdir/latlon-v0009', 'pgl_create_ecircle_from_epoint';
   6.612 +
   6.613 +CREATE FUNCTION ecluster_concat(ecluster[])
   6.614 +  RETURNS ecluster
   6.615 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.616 +    SELECT array_to_string($1, ' ')::ecluster
   6.617 +  $$;
   6.618 +
   6.619 +CREATE FUNCTION ecluster_concat(ecluster, ecluster)
   6.620 +  RETURNS ecluster
   6.621 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.622 +    SELECT ($1::text || ' ' || $2::text)::ecluster
   6.623 +  $$;
   6.624 +
   6.625 +CREATE FUNCTION ecluster_create_multipoint(epoint[])
   6.626 +  RETURNS ecluster
   6.627 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.628 +    SELECT
   6.629 +      array_to_string(array_agg('point (' || unnest || ')'), ' ')::ecluster
   6.630 +    FROM unnest($1)
   6.631 +  $$;
   6.632 +
   6.633 +CREATE FUNCTION ecluster_create_path(epoint[])
   6.634 +  RETURNS ecluster
   6.635 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.636 +    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   6.637 +      ('path (' || array_to_string($1, ' ') || ')')::ecluster
   6.638 +    END
   6.639 +    FROM array_to_string($1, ' ') AS "str"
   6.640 +  $$;
   6.641 +
   6.642 +CREATE FUNCTION ecluster_create_outline(epoint[])
   6.643 +  RETURNS ecluster
   6.644 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.645 +    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   6.646 +      ('outline (' || array_to_string($1, ' ') || ')')::ecluster
   6.647 +    END
   6.648 +    FROM array_to_string($1, ' ') AS "str"
   6.649 +  $$;
   6.650 +
   6.651 +CREATE FUNCTION ecluster_create_polygon(epoint[])
   6.652 +  RETURNS ecluster
   6.653 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.654 +    SELECT CASE WHEN "str" = '' THEN 'empty'::ecluster ELSE
   6.655 +      ('polygon (' || array_to_string($1, ' ') || ')')::ecluster
   6.656 +    END
   6.657 +    FROM array_to_string($1, ' ') AS "str"
   6.658 +  $$;
   6.659 +
   6.660 +
   6.661 +----------------------
   6.662 +-- getter functions --
   6.663 +----------------------
   6.664 +
   6.665 +CREATE FUNCTION latitude(epoint)
   6.666 +  RETURNS float8
   6.667 +  LANGUAGE C IMMUTABLE STRICT
   6.668 +  AS '$libdir/latlon-v0009', 'pgl_epoint_lat';
   6.669 +
   6.670 +CREATE FUNCTION longitude(epoint)
   6.671 +  RETURNS float8
   6.672 +  LANGUAGE C IMMUTABLE STRICT
   6.673 +  AS '$libdir/latlon-v0009', 'pgl_epoint_lon';
   6.674 +
   6.675 +CREATE FUNCTION min_latitude(ebox)
   6.676 +  RETURNS float8
   6.677 +  LANGUAGE C IMMUTABLE STRICT
   6.678 +  AS '$libdir/latlon-v0009', 'pgl_ebox_lat_min';
   6.679 +
   6.680 +CREATE FUNCTION max_latitude(ebox)
   6.681 +  RETURNS float8
   6.682 +  LANGUAGE C IMMUTABLE STRICT
   6.683 +  AS '$libdir/latlon-v0009', 'pgl_ebox_lat_max';
   6.684 +
   6.685 +CREATE FUNCTION min_longitude(ebox)
   6.686 +  RETURNS float8
   6.687 +  LANGUAGE C IMMUTABLE STRICT
   6.688 +  AS '$libdir/latlon-v0009', 'pgl_ebox_lon_min';
   6.689 +
   6.690 +CREATE FUNCTION max_longitude(ebox)
   6.691 +  RETURNS float8
   6.692 +  LANGUAGE C IMMUTABLE STRICT
   6.693 +  AS '$libdir/latlon-v0009', 'pgl_ebox_lon_max';
   6.694 +
   6.695 +CREATE FUNCTION center(ecircle)
   6.696 +  RETURNS epoint
   6.697 +  LANGUAGE C IMMUTABLE STRICT
   6.698 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_center';
   6.699 +
   6.700 +CREATE FUNCTION radius(ecircle)
   6.701 +  RETURNS float8
   6.702 +  LANGUAGE C IMMUTABLE STRICT
   6.703 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_radius';
   6.704 +
   6.705 +CREATE FUNCTION ecluster_extract_points(ecluster)
   6.706 +  RETURNS SETOF epoint
   6.707 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.708 +    SELECT "match"[2]::epoint
   6.709 +    FROM regexp_matches($1::text, e'(^| )point \\(([^)]+)\\)', 'g') AS "match"
   6.710 +  $$;
   6.711 +
   6.712 +CREATE FUNCTION ecluster_extract_paths(ecluster)
   6.713 +  RETURNS SETOF epoint[]
   6.714 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.715 +    SELECT (
   6.716 +      SELECT array_agg("m2"[1]::epoint)
   6.717 +      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   6.718 +    )
   6.719 +    FROM regexp_matches($1::text, e'(^| )path \\(([^)]+)\\)', 'g') AS "m1"
   6.720 +  $$;
   6.721 +
   6.722 +CREATE FUNCTION ecluster_extract_outlines(ecluster)
   6.723 +  RETURNS SETOF epoint[]
   6.724 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.725 +    SELECT (
   6.726 +      SELECT array_agg("m2"[1]::epoint)
   6.727 +      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   6.728 +    )
   6.729 +    FROM regexp_matches($1::text, e'(^| )outline \\(([^)]+)\\)', 'g') AS "m1"
   6.730 +  $$;
   6.731 +
   6.732 +CREATE FUNCTION ecluster_extract_polygons(ecluster)
   6.733 +  RETURNS SETOF epoint[]
   6.734 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   6.735 +    SELECT (
   6.736 +      SELECT array_agg("m2"[1]::epoint)
   6.737 +      FROM regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   6.738 +    )
   6.739 +    FROM regexp_matches($1::text, e'(^| )polygon \\(([^)]+)\\)', 'g') AS "m1"
   6.740 +  $$;
   6.741 +
   6.742 +
   6.743 +---------------
   6.744 +-- operators --
   6.745 +---------------
   6.746 +
   6.747 +CREATE FUNCTION epoint_ebox_overlap_proc(epoint, ebox)
   6.748 +  RETURNS boolean
   6.749 +  LANGUAGE C IMMUTABLE STRICT
   6.750 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ebox_overlap';
   6.751 +
   6.752 +CREATE FUNCTION epoint_ecircle_overlap_proc(epoint, ecircle)
   6.753 +  RETURNS boolean
   6.754 +  LANGUAGE C IMMUTABLE STRICT
   6.755 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ecircle_overlap';
   6.756 +
   6.757 +CREATE FUNCTION epoint_ecluster_overlap_proc(epoint, ecluster)
   6.758 +  RETURNS boolean
   6.759 +  LANGUAGE C IMMUTABLE STRICT
   6.760 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_overlap';
   6.761 +
   6.762 +CREATE FUNCTION epoint_ecluster_may_overlap_proc(epoint, ecluster)
   6.763 +  RETURNS boolean
   6.764 +  LANGUAGE C IMMUTABLE STRICT
   6.765 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_may_overlap';
   6.766 +
   6.767 +CREATE FUNCTION ebox_overlap_proc(ebox, ebox)
   6.768 +  RETURNS boolean
   6.769 +  LANGUAGE C IMMUTABLE STRICT
   6.770 +  AS '$libdir/latlon-v0009', 'pgl_ebox_overlap';
   6.771 +
   6.772 +CREATE FUNCTION ebox_ecircle_may_overlap_proc(ebox, ecircle)
   6.773 +  RETURNS boolean
   6.774 +  LANGUAGE C IMMUTABLE STRICT
   6.775 +  AS '$libdir/latlon-v0009', 'pgl_ebox_ecircle_may_overlap';
   6.776 +
   6.777 +CREATE FUNCTION ebox_ecluster_may_overlap_proc(ebox, ecluster)
   6.778 +  RETURNS boolean
   6.779 +  LANGUAGE C IMMUTABLE STRICT
   6.780 +  AS '$libdir/latlon-v0009', 'pgl_ebox_ecluster_may_overlap';
   6.781 +
   6.782 +CREATE FUNCTION ecircle_overlap_proc(ecircle, ecircle)
   6.783 +  RETURNS boolean
   6.784 +  LANGUAGE C IMMUTABLE STRICT
   6.785 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_overlap';
   6.786 +
   6.787 +CREATE FUNCTION ecircle_ecluster_overlap_proc(ecircle, ecluster)
   6.788 +  RETURNS boolean
   6.789 +  LANGUAGE C IMMUTABLE STRICT
   6.790 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_overlap';
   6.791 +
   6.792 +CREATE FUNCTION ecircle_ecluster_may_overlap_proc(ecircle, ecluster)
   6.793 +  RETURNS boolean
   6.794 +  LANGUAGE C IMMUTABLE STRICT
   6.795 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_may_overlap';
   6.796 +
   6.797 +CREATE FUNCTION ecluster_overlap_proc(ecluster, ecluster)
   6.798 +  RETURNS boolean
   6.799 +  LANGUAGE C IMMUTABLE STRICT
   6.800 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_overlap';
   6.801 +
   6.802 +CREATE FUNCTION ecluster_may_overlap_proc(ecluster, ecluster)
   6.803 +  RETURNS boolean
   6.804 +  LANGUAGE C IMMUTABLE STRICT
   6.805 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_may_overlap';
   6.806 +
   6.807 +CREATE FUNCTION ecluster_contains_proc(ecluster, ecluster)
   6.808 +  RETURNS boolean
   6.809 +  LANGUAGE C IMMUTABLE STRICT
   6.810 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_contains';
   6.811 +
   6.812 +CREATE FUNCTION epoint_distance_proc(epoint, epoint)
   6.813 +  RETURNS float8
   6.814 +  LANGUAGE C IMMUTABLE STRICT
   6.815 +  AS '$libdir/latlon-v0009', 'pgl_epoint_distance';
   6.816 +
   6.817 +CREATE FUNCTION epoint_ecircle_distance_proc(epoint, ecircle)
   6.818 +  RETURNS float8
   6.819 +  LANGUAGE C IMMUTABLE STRICT
   6.820 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ecircle_distance';
   6.821 +
   6.822 +CREATE FUNCTION epoint_ecluster_distance_proc(epoint, ecluster)
   6.823 +  RETURNS float8
   6.824 +  LANGUAGE C IMMUTABLE STRICT
   6.825 +  AS '$libdir/latlon-v0009', 'pgl_epoint_ecluster_distance';
   6.826 +
   6.827 +CREATE FUNCTION ecircle_distance_proc(ecircle, ecircle)
   6.828 +  RETURNS float8
   6.829 +  LANGUAGE C IMMUTABLE STRICT
   6.830 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_distance';
   6.831 +
   6.832 +CREATE FUNCTION ecircle_ecluster_distance_proc(ecircle, ecluster)
   6.833 +  RETURNS float8
   6.834 +  LANGUAGE C IMMUTABLE STRICT
   6.835 +  AS '$libdir/latlon-v0009', 'pgl_ecircle_ecluster_distance';
   6.836 +
   6.837 +CREATE FUNCTION ecluster_distance_proc(ecluster, ecluster)
   6.838 +  RETURNS float8
   6.839 +  LANGUAGE C IMMUTABLE STRICT
   6.840 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_distance';
   6.841 +
   6.842 +CREATE FUNCTION fair_distance_operator_proc(ecluster, epoint_with_sample_count)
   6.843 +  RETURNS float8
   6.844 +  LANGUAGE C IMMUTABLE STRICT
   6.845 +  AS '$libdir/latlon-v0009', 'pgl_ecluster_epoint_sc_fair_distance';
   6.846 +
   6.847 +CREATE OPERATOR && (
   6.848 +  leftarg = epoint,
   6.849 +  rightarg = ebox,
   6.850 +  procedure = epoint_ebox_overlap_proc,
   6.851 +  commutator = &&,
   6.852 +  restrict = areasel,
   6.853 +  join = areajoinsel
   6.854 +);
   6.855 +
   6.856 +CREATE FUNCTION epoint_ebox_overlap_commutator(ebox, epoint)
   6.857 +  RETURNS boolean
   6.858 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   6.859 +
   6.860 +CREATE OPERATOR && (
   6.861 +  leftarg = ebox,
   6.862 +  rightarg = epoint,
   6.863 +  procedure = epoint_ebox_overlap_commutator,
   6.864 +  commutator = &&,
   6.865 +  restrict = areasel,
   6.866 +  join = areajoinsel
   6.867 +);
   6.868 +
   6.869 +CREATE OPERATOR && (
   6.870 +  leftarg = epoint,
   6.871 +  rightarg = ecircle,
   6.872 +  procedure = epoint_ecircle_overlap_proc,
   6.873 +  commutator = &&,
   6.874 +  restrict = areasel,
   6.875 +  join = areajoinsel
   6.876 +);
   6.877 +
   6.878 +CREATE FUNCTION epoint_ecircle_overlap_commutator(ecircle, epoint)
   6.879 +  RETURNS boolean
   6.880 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   6.881 +
   6.882 +CREATE OPERATOR && (
   6.883 +  leftarg = ecircle,
   6.884 +  rightarg = epoint,
   6.885 +  procedure = epoint_ecircle_overlap_commutator,
   6.886 +  commutator = &&,
   6.887 +  restrict = areasel,
   6.888 +  join = areajoinsel
   6.889 +);
   6.890 +
   6.891 +CREATE OPERATOR && (
   6.892 +  leftarg = epoint,
   6.893 +  rightarg = ecluster,
   6.894 +  procedure = epoint_ecluster_overlap_proc,
   6.895 +  commutator = &&,
   6.896 +  restrict = areasel,
   6.897 +  join = areajoinsel
   6.898 +);
   6.899 +
   6.900 +CREATE FUNCTION epoint_ecluster_overlap_commutator(ecluster, epoint)
   6.901 +  RETURNS boolean
   6.902 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   6.903 +
   6.904 +CREATE OPERATOR && (
   6.905 +  leftarg = ecluster,
   6.906 +  rightarg = epoint,
   6.907 +  procedure = epoint_ecluster_overlap_commutator,
   6.908 +  commutator = &&,
   6.909 +  restrict = areasel,
   6.910 +  join = areajoinsel
   6.911 +);
   6.912 +
   6.913 +CREATE OPERATOR && (
   6.914 +  leftarg = ebox,
   6.915 +  rightarg = ebox,
   6.916 +  procedure = ebox_overlap_proc,
   6.917 +  commutator = &&,
   6.918 +  restrict = areasel,
   6.919 +  join = areajoinsel
   6.920 +);
   6.921 +
   6.922 +CREATE OPERATOR && (
   6.923 +  leftarg = ecircle,
   6.924 +  rightarg = ecircle,
   6.925 +  procedure = ecircle_overlap_proc,
   6.926 +  commutator = &&,
   6.927 +  restrict = areasel,
   6.928 +  join = areajoinsel
   6.929 +);
   6.930 +
   6.931 +CREATE OPERATOR && (
   6.932 +  leftarg = ecircle,
   6.933 +  rightarg = ecluster,
   6.934 +  procedure = ecircle_ecluster_overlap_proc,
   6.935 +  commutator = &&,
   6.936 +  restrict = areasel,
   6.937 +  join = areajoinsel
   6.938 +);
   6.939 +
   6.940 +CREATE FUNCTION ecircle_ecluster_overlap_commutator(ecluster, ecircle)
   6.941 +  RETURNS boolean
   6.942 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 && $1';
   6.943 +
   6.944 +CREATE OPERATOR && (
   6.945 +  leftarg = ecluster,
   6.946 +  rightarg = ecircle,
   6.947 +  procedure = ecircle_ecluster_overlap_commutator,
   6.948 +  commutator = &&,
   6.949 +  restrict = areasel,
   6.950 +  join = areajoinsel
   6.951 +);
   6.952 +
   6.953 +CREATE OPERATOR && (
   6.954 +  leftarg = ecluster,
   6.955 +  rightarg = ecluster,
   6.956 +  procedure = ecluster_overlap_proc,
   6.957 +  commutator = &&,
   6.958 +  restrict = areasel,
   6.959 +  join = areajoinsel
   6.960 +);
   6.961 +
   6.962 +CREATE FUNCTION ebox_ecircle_overlap_castwrap(ebox, ecircle)
   6.963 +  RETURNS boolean
   6.964 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster && $2';
   6.965 +
   6.966 +CREATE OPERATOR && (
   6.967 +  leftarg = ebox,
   6.968 +  rightarg = ecircle,
   6.969 +  procedure = ebox_ecircle_overlap_castwrap,
   6.970 +  commutator = &&,
   6.971 +  restrict = areasel,
   6.972 +  join = areajoinsel
   6.973 +);
   6.974 +
   6.975 +CREATE FUNCTION ebox_ecircle_overlap_castwrap(ecircle, ebox)
   6.976 +  RETURNS boolean
   6.977 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && $2::ecluster';
   6.978 +
   6.979 +CREATE OPERATOR && (
   6.980 +  leftarg = ecircle,
   6.981 +  rightarg = ebox,
   6.982 +  procedure = ebox_ecircle_overlap_castwrap,
   6.983 +  commutator = &&,
   6.984 +  restrict = areasel,
   6.985 +  join = areajoinsel
   6.986 +);
   6.987 +
   6.988 +CREATE FUNCTION ebox_ecluster_overlap_castwrap(ebox, ecluster)
   6.989 +  RETURNS boolean
   6.990 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster && $2';
   6.991 +
   6.992 +CREATE OPERATOR && (
   6.993 +  leftarg = ebox,
   6.994 +  rightarg = ecluster,
   6.995 +  procedure = ebox_ecluster_overlap_castwrap,
   6.996 +  commutator = &&,
   6.997 +  restrict = areasel,
   6.998 +  join = areajoinsel
   6.999 +);
  6.1000 +
  6.1001 +CREATE FUNCTION ebox_ecluster_overlap_castwrap(ecluster, ebox)
  6.1002 +  RETURNS boolean
  6.1003 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && $2::ecluster';
  6.1004 +
  6.1005 +CREATE OPERATOR && (
  6.1006 +  leftarg = ecluster,
  6.1007 +  rightarg = ebox,
  6.1008 +  procedure = ebox_ecluster_overlap_castwrap,
  6.1009 +  commutator = &&,
  6.1010 +  restrict = areasel,
  6.1011 +  join = areajoinsel
  6.1012 +);
  6.1013 +
  6.1014 +CREATE OPERATOR &&+ (
  6.1015 +  leftarg = epoint,
  6.1016 +  rightarg = ecluster,
  6.1017 +  procedure = epoint_ecluster_may_overlap_proc,
  6.1018 +  commutator = &&+,
  6.1019 +  restrict = areasel,
  6.1020 +  join = areajoinsel
  6.1021 +);
  6.1022 +
  6.1023 +CREATE FUNCTION epoint_ecluster_may_overlap_commutator(ecluster, epoint)
  6.1024 +  RETURNS boolean
  6.1025 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  6.1026 +
  6.1027 +CREATE OPERATOR &&+ (
  6.1028 +  leftarg = ecluster,
  6.1029 +  rightarg = epoint,
  6.1030 +  procedure = epoint_ecluster_may_overlap_commutator,
  6.1031 +  commutator = &&+,
  6.1032 +  restrict = areasel,
  6.1033 +  join = areajoinsel
  6.1034 +);
  6.1035 +
  6.1036 +CREATE OPERATOR &&+ (
  6.1037 +  leftarg = ebox,
  6.1038 +  rightarg = ecircle,
  6.1039 +  procedure = ebox_ecircle_may_overlap_proc,
  6.1040 +  commutator = &&+,
  6.1041 +  restrict = areasel,
  6.1042 +  join = areajoinsel
  6.1043 +);
  6.1044 +
  6.1045 +CREATE FUNCTION ebox_ecircle_may_overlap_commutator(ecircle, ebox)
  6.1046 +  RETURNS boolean
  6.1047 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  6.1048 +
  6.1049 +CREATE OPERATOR &&+ (
  6.1050 +  leftarg = ecircle,
  6.1051 +  rightarg = ebox,
  6.1052 +  procedure = ebox_ecircle_may_overlap_commutator,
  6.1053 +  commutator = &&+,
  6.1054 +  restrict = areasel,
  6.1055 +  join = areajoinsel
  6.1056 +);
  6.1057 +
  6.1058 +CREATE OPERATOR &&+ (
  6.1059 +  leftarg = ebox,
  6.1060 +  rightarg = ecluster,
  6.1061 +  procedure = ebox_ecluster_may_overlap_proc,
  6.1062 +  commutator = &&+,
  6.1063 +  restrict = areasel,
  6.1064 +  join = areajoinsel
  6.1065 +);
  6.1066 +
  6.1067 +CREATE FUNCTION ebox_ecluster_may_overlap_commutator(ecluster, ebox)
  6.1068 +  RETURNS boolean
  6.1069 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  6.1070 +
  6.1071 +CREATE OPERATOR &&+ (
  6.1072 +  leftarg = ecluster,
  6.1073 +  rightarg = ebox,
  6.1074 +  procedure = ebox_ecluster_may_overlap_commutator,
  6.1075 +  commutator = &&+,
  6.1076 +  restrict = areasel,
  6.1077 +  join = areajoinsel
  6.1078 +);
  6.1079 +
  6.1080 +CREATE OPERATOR &&+ (
  6.1081 +  leftarg = ecircle,
  6.1082 +  rightarg = ecluster,
  6.1083 +  procedure = ecircle_ecluster_may_overlap_proc,
  6.1084 +  commutator = &&+,
  6.1085 +  restrict = areasel,
  6.1086 +  join = areajoinsel
  6.1087 +);
  6.1088 +
  6.1089 +CREATE FUNCTION ecircle_ecluster_may_overlap_commutator(ecluster, ecircle)
  6.1090 +  RETURNS boolean
  6.1091 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 &&+ $1';
  6.1092 +
  6.1093 +CREATE OPERATOR &&+ (
  6.1094 +  leftarg = ecluster,
  6.1095 +  rightarg = ecircle,
  6.1096 +  procedure = ecircle_ecluster_may_overlap_commutator,
  6.1097 +  commutator = &&+,
  6.1098 +  restrict = areasel,
  6.1099 +  join = areajoinsel
  6.1100 +);
  6.1101 +
  6.1102 +CREATE OPERATOR &&+ (
  6.1103 +  leftarg = ecluster,
  6.1104 +  rightarg = ecluster,
  6.1105 +  procedure = ecluster_may_overlap_proc,
  6.1106 +  commutator = &&+,
  6.1107 +  restrict = areasel,
  6.1108 +  join = areajoinsel
  6.1109 +);
  6.1110 +
  6.1111 +CREATE OPERATOR @> (
  6.1112 +  leftarg = ebox,
  6.1113 +  rightarg = epoint,
  6.1114 +  procedure = epoint_ebox_overlap_commutator,
  6.1115 +  commutator = <@,
  6.1116 +  restrict = areasel,
  6.1117 +  join = areajoinsel
  6.1118 +);
  6.1119 +
  6.1120 +CREATE OPERATOR <@ (
  6.1121 +  leftarg = epoint,
  6.1122 +  rightarg = ebox,
  6.1123 +  procedure = epoint_ebox_overlap_proc,
  6.1124 +  commutator = @>,
  6.1125 +  restrict = areasel,
  6.1126 +  join = areajoinsel
  6.1127 +);
  6.1128 +
  6.1129 +CREATE OPERATOR @> (
  6.1130 +  leftarg = ecluster,
  6.1131 +  rightarg = epoint,
  6.1132 +  procedure = epoint_ecluster_overlap_commutator,
  6.1133 +  commutator = <@,
  6.1134 +  restrict = areasel,
  6.1135 +  join = areajoinsel
  6.1136 +);
  6.1137 +
  6.1138 +CREATE OPERATOR <@ (
  6.1139 +  leftarg = epoint,
  6.1140 +  rightarg = ecluster,
  6.1141 +  procedure = epoint_ecluster_overlap_proc,
  6.1142 +  commutator = <@,
  6.1143 +  restrict = areasel,
  6.1144 +  join = areajoinsel
  6.1145 +);
  6.1146 +
  6.1147 +CREATE OPERATOR @> (
  6.1148 +  leftarg = ecluster,
  6.1149 +  rightarg = ecluster,
  6.1150 +  procedure = ecluster_contains_proc,
  6.1151 +  commutator = <@,
  6.1152 +  restrict = areasel,
  6.1153 +  join = areajoinsel
  6.1154 +);
  6.1155 +
  6.1156 +CREATE FUNCTION ecluster_contains_commutator(ecluster, ecluster)
  6.1157 +  RETURNS boolean
  6.1158 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 @> $1';
  6.1159 +
  6.1160 +CREATE OPERATOR <@ (
  6.1161 +  leftarg = ecluster,
  6.1162 +  rightarg = ecluster,
  6.1163 +  procedure = ecluster_contains_commutator,
  6.1164 +  commutator = @>,
  6.1165 +  restrict = areasel,
  6.1166 +  join = areajoinsel
  6.1167 +);
  6.1168 +
  6.1169 +CREATE FUNCTION ebox_contains_castwrap(ebox, ebox)
  6.1170 +  RETURNS boolean
  6.1171 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster @> $2::ecluster';
  6.1172 +
  6.1173 +CREATE OPERATOR @> (
  6.1174 +  leftarg = ebox,
  6.1175 +  rightarg = ebox,
  6.1176 +  procedure = ebox_contains_castwrap,
  6.1177 +  commutator = <@,
  6.1178 +  restrict = areasel,
  6.1179 +  join = areajoinsel
  6.1180 +);
  6.1181 +
  6.1182 +CREATE FUNCTION ebox_contains_swapped_castwrap(ebox, ebox)
  6.1183 +  RETURNS boolean
  6.1184 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2::ecluster @> $1::ecluster';
  6.1185 +
  6.1186 +CREATE OPERATOR <@ (
  6.1187 +  leftarg = ebox,
  6.1188 +  rightarg = ebox,
  6.1189 +  procedure = ebox_contains_swapped_castwrap,
  6.1190 +  commutator = @>,
  6.1191 +  restrict = areasel,
  6.1192 +  join = areajoinsel
  6.1193 +);
  6.1194 +
  6.1195 +CREATE FUNCTION ebox_ecluster_contains_castwrap(ebox, ecluster)
  6.1196 +  RETURNS boolean
  6.1197 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster @> $2';
  6.1198 +
  6.1199 +CREATE OPERATOR @> (
  6.1200 +  leftarg = ebox,
  6.1201 +  rightarg = ecluster,
  6.1202 +  procedure = ebox_ecluster_contains_castwrap,
  6.1203 +  commutator = <@,
  6.1204 +  restrict = areasel,
  6.1205 +  join = areajoinsel
  6.1206 +);
  6.1207 +
  6.1208 +CREATE FUNCTION ebox_ecluster_contains_castwrap(ecluster, ebox)
  6.1209 +  RETURNS boolean
  6.1210 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2::ecluster @> $1';
  6.1211 +
  6.1212 +CREATE OPERATOR <@ (
  6.1213 +  leftarg = ecluster,
  6.1214 +  rightarg = ebox,
  6.1215 +  procedure = ebox_ecluster_contains_castwrap,
  6.1216 +  commutator = @>,
  6.1217 +  restrict = areasel,
  6.1218 +  join = areajoinsel
  6.1219 +);
  6.1220 +
  6.1221 +CREATE FUNCTION ecluster_ebox_contains_castwrap(ecluster, ebox)
  6.1222 +  RETURNS boolean
  6.1223 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 @> $2::ecluster';
  6.1224 +
  6.1225 +CREATE OPERATOR @> (
  6.1226 +  leftarg = ecluster,
  6.1227 +  rightarg = ebox,
  6.1228 +  procedure = ecluster_ebox_contains_castwrap,
  6.1229 +  commutator = <@,
  6.1230 +  restrict = areasel,
  6.1231 +  join = areajoinsel
  6.1232 +);
  6.1233 +
  6.1234 +CREATE FUNCTION ecluster_ebox_contains_castwrap(ebox, ecluster)
  6.1235 +  RETURNS boolean
  6.1236 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 @> $1::ecluster';
  6.1237 +
  6.1238 +CREATE OPERATOR <@ (
  6.1239 +  leftarg = ebox,
  6.1240 +  rightarg = ecluster,
  6.1241 +  procedure = ecluster_ebox_contains_castwrap,
  6.1242 +  commutator = @>,
  6.1243 +  restrict = areasel,
  6.1244 +  join = areajoinsel
  6.1245 +);
  6.1246 +
  6.1247 +CREATE OPERATOR <-> (
  6.1248 +  leftarg = epoint,
  6.1249 +  rightarg = epoint,
  6.1250 +  procedure = epoint_distance_proc,
  6.1251 +  commutator = <->
  6.1252 +);
  6.1253 +
  6.1254 +CREATE OPERATOR <-> (
  6.1255 +  leftarg = epoint,
  6.1256 +  rightarg = ecircle,
  6.1257 +  procedure = epoint_ecircle_distance_proc,
  6.1258 +  commutator = <->
  6.1259 +);
  6.1260 +
  6.1261 +CREATE FUNCTION epoint_ecircle_distance_commutator(ecircle, epoint)
  6.1262 +  RETURNS float8
  6.1263 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  6.1264 +
  6.1265 +CREATE OPERATOR <-> (
  6.1266 +  leftarg = ecircle,
  6.1267 +  rightarg = epoint,
  6.1268 +  procedure = epoint_ecircle_distance_commutator,
  6.1269 +  commutator = <->
  6.1270 +);
  6.1271 +
  6.1272 +CREATE OPERATOR <-> (
  6.1273 +  leftarg = epoint,
  6.1274 +  rightarg = ecluster,
  6.1275 +  procedure = epoint_ecluster_distance_proc,
  6.1276 +  commutator = <->
  6.1277 +);
  6.1278 +
  6.1279 +CREATE FUNCTION epoint_ecluster_distance_commutator(ecluster, epoint)
  6.1280 +  RETURNS float8
  6.1281 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  6.1282 +
  6.1283 +CREATE OPERATOR <-> (
  6.1284 +  leftarg = ecluster,
  6.1285 +  rightarg = epoint,
  6.1286 +  procedure = epoint_ecluster_distance_commutator,
  6.1287 +  commutator = <->
  6.1288 +);
  6.1289 +
  6.1290 +CREATE OPERATOR <-> (
  6.1291 +  leftarg = ecircle,
  6.1292 +  rightarg = ecircle,
  6.1293 +  procedure = ecircle_distance_proc,
  6.1294 +  commutator = <->
  6.1295 +);
  6.1296 +
  6.1297 +CREATE OPERATOR <-> (
  6.1298 +  leftarg = ecircle,
  6.1299 +  rightarg = ecluster,
  6.1300 +  procedure = ecircle_ecluster_distance_proc,
  6.1301 +  commutator = <->
  6.1302 +);
  6.1303 +
  6.1304 +CREATE FUNCTION ecircle_ecluster_distance_commutator(ecluster, ecircle)
  6.1305 +  RETURNS float8
  6.1306 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 <-> $1';
  6.1307 +
  6.1308 +CREATE OPERATOR <-> (
  6.1309 +  leftarg = ecluster,
  6.1310 +  rightarg = ecircle,
  6.1311 +  procedure = ecircle_ecluster_distance_commutator,
  6.1312 +  commutator = <->
  6.1313 +);
  6.1314 +
  6.1315 +CREATE OPERATOR <-> (
  6.1316 +  leftarg = ecluster,
  6.1317 +  rightarg = ecluster,
  6.1318 +  procedure = ecluster_distance_proc,
  6.1319 +  commutator = <->
  6.1320 +);
  6.1321 +
  6.1322 +CREATE FUNCTION epoint_ebox_distance_castwrap(epoint, ebox)
  6.1323 +  RETURNS float8
  6.1324 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  6.1325 +
  6.1326 +CREATE OPERATOR <-> (
  6.1327 +  leftarg = epoint,
  6.1328 +  rightarg = ebox,
  6.1329 +  procedure = epoint_ebox_distance_castwrap,
  6.1330 +  commutator = <->
  6.1331 +);
  6.1332 +
  6.1333 +CREATE FUNCTION epoint_ebox_distance_castwrap(ebox, epoint)
  6.1334 +  RETURNS float8
  6.1335 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  6.1336 +
  6.1337 +CREATE OPERATOR <-> (
  6.1338 +  leftarg = ebox,
  6.1339 +  rightarg = epoint,
  6.1340 +  procedure = epoint_ebox_distance_castwrap,
  6.1341 +  commutator = <->
  6.1342 +);
  6.1343 +
  6.1344 +CREATE FUNCTION ebox_distance_castwrap(ebox, ebox)
  6.1345 +  RETURNS float8
  6.1346 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2::ecluster';
  6.1347 +
  6.1348 +CREATE OPERATOR <-> (
  6.1349 +  leftarg = ebox,
  6.1350 +  rightarg = ebox,
  6.1351 +  procedure = ebox_distance_castwrap,
  6.1352 +  commutator = <->
  6.1353 +);
  6.1354 +
  6.1355 +CREATE FUNCTION ebox_ecircle_distance_castwrap(ebox, ecircle)
  6.1356 +  RETURNS float8
  6.1357 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  6.1358 +
  6.1359 +CREATE OPERATOR <-> (
  6.1360 +  leftarg = ebox,
  6.1361 +  rightarg = ecircle,
  6.1362 +  procedure = ebox_ecircle_distance_castwrap,
  6.1363 +  commutator = <->
  6.1364 +);
  6.1365 +
  6.1366 +CREATE FUNCTION ebox_ecircle_distance_castwrap(ecircle, ebox)
  6.1367 +  RETURNS float8
  6.1368 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  6.1369 +
  6.1370 +CREATE OPERATOR <-> (
  6.1371 +  leftarg = ecircle,
  6.1372 +  rightarg = ebox,
  6.1373 +  procedure = ebox_ecircle_distance_castwrap,
  6.1374 +  commutator = <->
  6.1375 +);
  6.1376 +
  6.1377 +CREATE FUNCTION ebox_ecluster_distance_castwrap(ebox, ecluster)
  6.1378 +  RETURNS float8
  6.1379 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1::ecluster <-> $2';
  6.1380 +
  6.1381 +CREATE OPERATOR <-> (
  6.1382 +  leftarg = ebox,
  6.1383 +  rightarg = ecluster,
  6.1384 +  procedure = ebox_ecluster_distance_castwrap,
  6.1385 +  commutator = <->
  6.1386 +);
  6.1387 +
  6.1388 +CREATE FUNCTION ebox_ecluster_distance_castwrap(ecluster, ebox)
  6.1389 +  RETURNS float8
  6.1390 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2::ecluster';
  6.1391 +
  6.1392 +CREATE OPERATOR <-> (
  6.1393 +  leftarg = ecluster,
  6.1394 +  rightarg = ebox,
  6.1395 +  procedure = ebox_ecluster_distance_castwrap,
  6.1396 +  commutator = <->
  6.1397 +);
  6.1398 +
  6.1399 +CREATE OPERATOR <=> (
  6.1400 +  leftarg = ecluster,
  6.1401 +  rightarg = epoint_with_sample_count,
  6.1402 +  procedure = fair_distance_operator_proc
  6.1403 +);
  6.1404 +
  6.1405 +
  6.1406 +----------------
  6.1407 +-- GiST index --
  6.1408 +----------------
  6.1409 +
  6.1410 +CREATE FUNCTION pgl_gist_consistent(internal, internal, smallint, oid, internal)
  6.1411 +  RETURNS boolean
  6.1412 +  LANGUAGE C STRICT
  6.1413 +  AS '$libdir/latlon-v0009', 'pgl_gist_consistent';
  6.1414 +
  6.1415 +CREATE FUNCTION pgl_gist_union(internal, internal)
  6.1416 +  RETURNS internal
  6.1417 +  LANGUAGE C STRICT
  6.1418 +  AS '$libdir/latlon-v0009', 'pgl_gist_union';
  6.1419 +
  6.1420 +CREATE FUNCTION pgl_gist_compress_epoint(internal)
  6.1421 +  RETURNS internal
  6.1422 +  LANGUAGE C STRICT
  6.1423 +  AS '$libdir/latlon-v0009', 'pgl_gist_compress_epoint';
  6.1424 +
  6.1425 +CREATE FUNCTION pgl_gist_compress_ecircle(internal)
  6.1426 +  RETURNS internal
  6.1427 +  LANGUAGE C STRICT
  6.1428 +  AS '$libdir/latlon-v0009', 'pgl_gist_compress_ecircle';
  6.1429 +
  6.1430 +CREATE FUNCTION pgl_gist_compress_ecluster(internal)
  6.1431 +  RETURNS internal
  6.1432 +  LANGUAGE C STRICT
  6.1433 +  AS '$libdir/latlon-v0009', 'pgl_gist_compress_ecluster';
  6.1434 +
  6.1435 +CREATE FUNCTION pgl_gist_decompress(internal)
  6.1436 +  RETURNS internal
  6.1437 +  LANGUAGE C STRICT
  6.1438 +  AS '$libdir/latlon-v0009', 'pgl_gist_decompress';
  6.1439 +
  6.1440 +CREATE FUNCTION pgl_gist_penalty(internal, internal, internal)
  6.1441 +  RETURNS internal
  6.1442 +  LANGUAGE C STRICT
  6.1443 +  AS '$libdir/latlon-v0009', 'pgl_gist_penalty';
  6.1444 +
  6.1445 +CREATE FUNCTION pgl_gist_picksplit(internal, internal)
  6.1446 +  RETURNS internal
  6.1447 +  LANGUAGE C STRICT
  6.1448 +  AS '$libdir/latlon-v0009', 'pgl_gist_picksplit';
  6.1449 +
  6.1450 +CREATE FUNCTION pgl_gist_same(internal, internal, internal)
  6.1451 +  RETURNS internal
  6.1452 +  LANGUAGE C STRICT
  6.1453 +  AS '$libdir/latlon-v0009', 'pgl_gist_same';
  6.1454 +
  6.1455 +CREATE FUNCTION pgl_gist_distance(internal, internal, smallint, oid)
  6.1456 +  RETURNS internal
  6.1457 +  LANGUAGE C STRICT
  6.1458 +  AS '$libdir/latlon-v0009', 'pgl_gist_distance';
  6.1459 +
  6.1460 +CREATE OPERATOR CLASS epoint_ops
  6.1461 +  DEFAULT FOR TYPE epoint USING gist AS
  6.1462 +  OPERATOR  11 = ,
  6.1463 +  OPERATOR  22 &&  (epoint, ebox),
  6.1464 +  OPERATOR 222 <@  (epoint, ebox),
  6.1465 +  OPERATOR  23 &&  (epoint, ecircle),
  6.1466 +  OPERATOR  24 &&  (epoint, ecluster),
  6.1467 +  OPERATOR 124 &&+ (epoint, ecluster),
  6.1468 +  OPERATOR 224 <@  (epoint, ecluster),
  6.1469 +  OPERATOR  31 <-> (epoint, epoint) FOR ORDER BY float_ops,
  6.1470 +  OPERATOR  32 <-> (epoint, ebox) FOR ORDER BY float_ops,
  6.1471 +  OPERATOR  33 <-> (epoint, ecircle) FOR ORDER BY float_ops,
  6.1472 +  OPERATOR  34 <-> (epoint, ecluster) FOR ORDER BY float_ops,
  6.1473 +  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  6.1474 +  FUNCTION 2 pgl_gist_union(internal, internal),
  6.1475 +  FUNCTION 3 pgl_gist_compress_epoint(internal),
  6.1476 +  FUNCTION 4 pgl_gist_decompress(internal),
  6.1477 +  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  6.1478 +  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  6.1479 +  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  6.1480 +  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  6.1481 +  STORAGE ekey_point;
  6.1482 +
  6.1483 +CREATE OPERATOR CLASS ecircle_ops
  6.1484 +  DEFAULT FOR TYPE ecircle USING gist AS
  6.1485 +  OPERATOR  13 = ,
  6.1486 +  OPERATOR  21 &&  (ecircle, epoint),
  6.1487 +  OPERATOR  22 &&  (ecircle, ebox),
  6.1488 +  OPERATOR 122 &&+ (ecircle, ebox),
  6.1489 +  OPERATOR  23 &&  (ecircle, ecircle),
  6.1490 +  OPERATOR  24 &&  (ecircle, ecluster),
  6.1491 +  OPERATOR 124 &&+ (ecircle, ecluster),
  6.1492 +  OPERATOR  31 <-> (ecircle, epoint) FOR ORDER BY float_ops,
  6.1493 +  OPERATOR  32 <-> (ecircle, ebox) FOR ORDER BY float_ops,
  6.1494 +  OPERATOR  33 <-> (ecircle, ecircle) FOR ORDER BY float_ops,
  6.1495 +  OPERATOR  34 <-> (ecircle, ecluster) FOR ORDER BY float_ops,
  6.1496 +  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  6.1497 +  FUNCTION 2 pgl_gist_union(internal, internal),
  6.1498 +  FUNCTION 3 pgl_gist_compress_ecircle(internal),
  6.1499 +  FUNCTION 4 pgl_gist_decompress(internal),
  6.1500 +  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  6.1501 +  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  6.1502 +  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  6.1503 +  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  6.1504 +  STORAGE ekey_area;
  6.1505 +
  6.1506 +CREATE OPERATOR CLASS ecluster_ops
  6.1507 +  DEFAULT FOR TYPE ecluster USING gist AS
  6.1508 +  OPERATOR  21 &&  (ecluster, epoint),
  6.1509 +  OPERATOR 121 &&+ (ecluster, epoint),
  6.1510 +  OPERATOR 221 @>  (ecluster, epoint),
  6.1511 +  OPERATOR  22 &&  (ecluster, ebox),
  6.1512 +  OPERATOR 122 &&+ (ecluster, ebox),
  6.1513 +  OPERATOR 222 @>  (ecluster, ebox),
  6.1514 +  OPERATOR 322 <@  (ecluster, ebox),
  6.1515 +  OPERATOR  23 &&  (ecluster, ecircle),
  6.1516 +  OPERATOR 123 &&+ (ecluster, ecircle),
  6.1517 +  OPERATOR  24 &&  (ecluster, ecluster),
  6.1518 +  OPERATOR 124 &&+ (ecluster, ecluster),
  6.1519 +  OPERATOR 224 @>  (ecluster, ecluster),
  6.1520 +  OPERATOR 324 <@  (ecluster, ecluster),
  6.1521 +  OPERATOR  31 <-> (ecluster, epoint) FOR ORDER BY float_ops,
  6.1522 +  OPERATOR  32 <-> (ecluster, ebox) FOR ORDER BY float_ops,
  6.1523 +  OPERATOR  33 <-> (ecluster, ecircle) FOR ORDER BY float_ops,
  6.1524 +  OPERATOR  34 <-> (ecluster, ecluster) FOR ORDER BY float_ops,
  6.1525 +  OPERATOR 131 <=> (ecluster, epoint_with_sample_count) FOR ORDER BY float_ops,
  6.1526 +  FUNCTION 1 pgl_gist_consistent(internal, internal, smallint, oid, internal),
  6.1527 +  FUNCTION 2 pgl_gist_union(internal, internal),
  6.1528 +  FUNCTION 3 pgl_gist_compress_ecluster(internal),
  6.1529 +  FUNCTION 4 pgl_gist_decompress(internal),
  6.1530 +  FUNCTION 5 pgl_gist_penalty(internal, internal, internal),
  6.1531 +  FUNCTION 6 pgl_gist_picksplit(internal, internal),
  6.1532 +  FUNCTION 7 pgl_gist_same(internal, internal, internal),
  6.1533 +  FUNCTION 8 pgl_gist_distance(internal, internal, smallint, oid),
  6.1534 +  STORAGE ekey_area;
  6.1535 +
  6.1536 +
  6.1537 +---------------------
  6.1538 +-- alias functions --
  6.1539 +---------------------
  6.1540 +
  6.1541 +CREATE FUNCTION distance(epoint, epoint)
  6.1542 +  RETURNS float8
  6.1543 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2';
  6.1544 +
  6.1545 +CREATE FUNCTION distance(ecluster, epoint)
  6.1546 +  RETURNS float8
  6.1547 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <-> $2';
  6.1548 +
  6.1549 +CREATE FUNCTION distance_within(epoint, epoint, float8)
  6.1550 +  RETURNS boolean
  6.1551 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && ecircle($2, $3)';
  6.1552 +
  6.1553 +CREATE FUNCTION distance_within(ecluster, epoint, float8)
  6.1554 +  RETURNS boolean
  6.1555 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 && ecircle($2, $3)';
  6.1556 +
  6.1557 +CREATE FUNCTION fair_distance(ecluster, epoint, int4 = 10000)
  6.1558 +  RETURNS float8
  6.1559 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 <=> epoint_with_sample_count($2, $3)';
  6.1560 +
  6.1561 +
  6.1562 +--------------------------------
  6.1563 +-- other data storage formats --
  6.1564 +--------------------------------
  6.1565 +
  6.1566 +CREATE FUNCTION coords_to_epoint(float8, float8, text = 'epoint')
  6.1567 +  RETURNS epoint
  6.1568 +  LANGUAGE plpgsql IMMUTABLE STRICT AS $$
  6.1569 +    DECLARE
  6.1570 +      "result" epoint;
  6.1571 +    BEGIN
  6.1572 +      IF $3 = 'epoint_lonlat' THEN
  6.1573 +        -- avoid dynamic command execution for better performance
  6.1574 +        RETURN epoint($2, $1);
  6.1575 +      END IF;
  6.1576 +      IF $3 = 'epoint' OR $3 = 'epoint_latlon' THEN
  6.1577 +        -- avoid dynamic command execution for better performance
  6.1578 +        RETURN epoint($1, $2);
  6.1579 +      END IF;
  6.1580 +      EXECUTE 'SELECT ' || $3 || '($1, $2)' INTO STRICT "result" USING $1, $2;
  6.1581 +      RETURN "result";
  6.1582 +    END;
  6.1583 +  $$;
  6.1584 +
  6.1585 +CREATE FUNCTION GeoJSON_LinearRing_vertices(jsonb, text = 'epoint_lonlat')
  6.1586 +  RETURNS SETOF jsonb
  6.1587 +  LANGUAGE sql IMMUTABLE STRICT AS $$
  6.1588 +    SELECT "result" FROM
  6.1589 +      ( SELECT jsonb_array_length($1) - 1 ) AS "lastindex_row" ("lastindex")
  6.1590 +      CROSS JOIN LATERAL jsonb_array_elements(
  6.1591 +        CASE WHEN
  6.1592 +          coords_to_epoint(
  6.1593 +            ($1->0->>0)::float8,
  6.1594 +            ($1->0->>1)::float8,
  6.1595 +            $2
  6.1596 +          ) = coords_to_epoint(
  6.1597 +            ($1->"lastindex"->>0)::float8,
  6.1598 +            ($1->"lastindex"->>1)::float8,
  6.1599 +            $2
  6.1600 +          )
  6.1601 +        THEN
  6.1602 +          $1 - "lastindex"
  6.1603 +        ELSE
  6.1604 +          $1
  6.1605 +        END
  6.1606 +      ) AS "result_row" ("result")
  6.1607 +  $$;
  6.1608 +
  6.1609 +CREATE FUNCTION GeoJSON_to_epoint(jsonb, text = 'epoint_lonlat')
  6.1610 +  RETURNS epoint
  6.1611 +  LANGUAGE sql IMMUTABLE STRICT AS $$
  6.1612 +    SELECT CASE
  6.1613 +    WHEN $1->>'type' = 'Point' THEN
  6.1614 +      coords_to_epoint(
  6.1615 +        ($1->'coordinates'->>0)::float8,
  6.1616 +        ($1->'coordinates'->>1)::float8,
  6.1617 +        $2
  6.1618 +      )
  6.1619 +    WHEN $1->>'type' = 'Feature' THEN
  6.1620 +      GeoJSON_to_epoint($1->'geometry', $2)
  6.1621 +    ELSE
  6.1622 +      NULL
  6.1623 +    END
  6.1624 +  $$;
  6.1625 +
  6.1626 +CREATE FUNCTION GeoJSON_to_ecluster(jsonb, text = 'epoint_lonlat')
  6.1627 +  RETURNS ecluster
  6.1628 +  LANGUAGE sql IMMUTABLE STRICT AS $$
  6.1629 +    SELECT CASE $1->>'type'
  6.1630 +    WHEN 'Point' THEN
  6.1631 +      coords_to_epoint(
  6.1632 +        ($1->'coordinates'->>0)::float8,
  6.1633 +        ($1->'coordinates'->>1)::float8,
  6.1634 +        $2
  6.1635 +      )::ecluster
  6.1636 +    WHEN 'MultiPoint' THEN
  6.1637 +      ( SELECT ecluster_create_multipoint(array_agg(
  6.1638 +          coords_to_epoint(
  6.1639 +            ("coord"->>0)::float8,
  6.1640 +            ("coord"->>1)::float8,
  6.1641 +            $2
  6.1642 +          )
  6.1643 +        ))
  6.1644 +        FROM jsonb_array_elements($1->'coordinates') AS "coord"
  6.1645 +      )
  6.1646 +    WHEN 'LineString' THEN
  6.1647 +      ( SELECT ecluster_create_path(array_agg(
  6.1648 +          coords_to_epoint(
  6.1649 +            ("coord"->>0)::float8,
  6.1650 +            ("coord"->>1)::float8,
  6.1651 +            $2
  6.1652 +          )
  6.1653 +        ))
  6.1654 +        FROM jsonb_array_elements($1->'coordinates') AS "coord"
  6.1655 +      )
  6.1656 +    WHEN 'MultiLineString' THEN
  6.1657 +      ( SELECT ecluster_concat(array_agg(
  6.1658 +          ( SELECT ecluster_create_path(array_agg(
  6.1659 +              coords_to_epoint(
  6.1660 +                ("coord"->>0)::float8,
  6.1661 +                ("coord"->>1)::float8,
  6.1662 +                $2
  6.1663 +              )
  6.1664 +            ))
  6.1665 +            FROM jsonb_array_elements("coord_array") AS "coord"
  6.1666 +          )
  6.1667 +        ))
  6.1668 +        FROM jsonb_array_elements($1->'coordinates') AS "coord_array"
  6.1669 +      )
  6.1670 +    WHEN 'Polygon' THEN
  6.1671 +      ( SELECT ecluster_concat(array_agg(
  6.1672 +          ( SELECT ecluster_create_polygon(array_agg(
  6.1673 +              coords_to_epoint(
  6.1674 +                ("coord"->>0)::float8,
  6.1675 +                ("coord"->>1)::float8,
  6.1676 +                $2
  6.1677 +              )
  6.1678 +            ))
  6.1679 +            FROM GeoJSON_LinearRing_vertices("coord_array", $2) AS "coord"
  6.1680 +          )
  6.1681 +        ))
  6.1682 +        FROM jsonb_array_elements($1->'coordinates') AS "coord_array"
  6.1683 +      )
  6.1684 +    WHEN 'MultiPolygon' THEN
  6.1685 +      ( SELECT ecluster_concat(array_agg(
  6.1686 +          ( SELECT ecluster_concat(array_agg(
  6.1687 +              ( SELECT ecluster_create_polygon(array_agg(
  6.1688 +                  coords_to_epoint(
  6.1689 +                    ("coord"->>0)::float8,
  6.1690 +                    ("coord"->>1)::float8,
  6.1691 +                    $2
  6.1692 +                  )
  6.1693 +                ))
  6.1694 +                FROM GeoJSON_LinearRing_vertices("coord_array", $2) AS "coord"
  6.1695 +              )
  6.1696 +            ))
  6.1697 +            FROM jsonb_array_elements("coord_array_array") AS "coord_array"
  6.1698 +          )
  6.1699 +        ))
  6.1700 +        FROM jsonb_array_elements($1->'coordinates') AS "coord_array_array"
  6.1701 +      )
  6.1702 +    WHEN 'GeometryCollection' THEN
  6.1703 +      ( SELECT ecluster_concat(array_agg(
  6.1704 +          GeoJSON_to_ecluster("geometry", $2)
  6.1705 +        ))
  6.1706 +        FROM jsonb_array_elements($1->'geometries') AS "geometry"
  6.1707 +      )
  6.1708 +    WHEN 'Feature' THEN
  6.1709 +      GeoJSON_to_ecluster($1->'geometry', $2)
  6.1710 +    WHEN 'FeatureCollection' THEN
  6.1711 +      ( SELECT ecluster_concat(array_agg(
  6.1712 +          GeoJSON_to_ecluster("feature", $2)
  6.1713 +        ))
  6.1714 +        FROM jsonb_array_elements($1->'features') AS "feature"
  6.1715 +      )
  6.1716 +    ELSE
  6.1717 +      NULL
  6.1718 +    END
  6.1719 +  $$;
  6.1720 +
     7.1 --- a/latlon.control	Mon Feb 10 21:44:32 2020 +0100
     7.2 +++ b/latlon.control	Tue Feb 11 01:59:04 2020 +0100
     7.3 @@ -1,3 +1,3 @@
     7.4  comment = 'Geographic data types and spatial indexing for the WGS-84 spheroid'
     7.5 -default_version = '0.12'
     7.6 +default_version = '0.14'
     7.7  relocatable = true

Impressum / About Us