pgLatLon

diff latlon--0.14--0.15.sql @ 73:b5bc6b35b716

Allow non-superusers to install extension; Properly support loading extension into schema; Do not allow schema relocation
author jbe
date Sun Nov 29 19:55:33 2020 +0100 (2020-11-29)
parents 882b77aee653
children 1cdb3da50176
line diff
     1.1 --- a/latlon--0.14--0.15.sql	Wed Feb 12 13:11:04 2020 +0100
     1.2 +++ b/latlon--0.14--0.15.sql	Sun Nov 29 19:55:33 2020 +0100
     1.3 @@ -1,3 +1,5 @@
     1.4 +SET LOCAL search_path TO @extschema@;
     1.5 +
     1.6  
     1.7  ------------------------------------------------------------
     1.8  -- dummy input/output functions for dummy index key types --
     1.9 @@ -275,6 +277,18 @@
    1.10    LANGUAGE C IMMUTABLE STRICT
    1.11    AS '$libdir/latlon-v0010', 'pgl_create_epoint';
    1.12  
    1.13 +CREATE OR REPLACE FUNCTION epoint_latlon(float8, float8)
    1.14 +  RETURNS epoint
    1.15 +  LANGUAGE SQL IMMUTABLE STRICT AS $$
    1.16 +    SELECT @extschema@.epoint($1, $2)
    1.17 +  $$;
    1.18 +
    1.19 +CREATE OR REPLACE FUNCTION epoint_lonlat(float8, float8)
    1.20 +  RETURNS epoint
    1.21 +  LANGUAGE SQL IMMUTABLE STRICT AS $$
    1.22 +    SELECT @extschema@.epoint($2, $1)
    1.23 +  $$;
    1.24 +
    1.25  CREATE OR REPLACE FUNCTION epoint_with_sample_count(epoint, int4)
    1.26    RETURNS epoint_with_sample_count
    1.27    LANGUAGE C IMMUTABLE STRICT
    1.28 @@ -305,6 +319,74 @@
    1.29    LANGUAGE C IMMUTABLE STRICT
    1.30    AS '$libdir/latlon-v0010', 'pgl_create_ecircle_from_epoint';
    1.31  
    1.32 +CREATE OR REPLACE FUNCTION ecluster_concat(ecluster[])
    1.33 +  RETURNS ecluster
    1.34 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.35 +    SELECT pg_catalog.array_to_string($1, ' ')::@extschema@.ecluster
    1.36 +  $$;
    1.37 +
    1.38 +CREATE OR REPLACE FUNCTION ecluster_concat(ecluster, ecluster)
    1.39 +  RETURNS ecluster
    1.40 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.41 +    SELECT (
    1.42 +      $1::pg_catalog.text OPERATOR(pg_catalog.||) ' ' OPERATOR(pg_catalog.||)
    1.43 +      $2::pg_catalog.text
    1.44 +    )::@extschema@.ecluster
    1.45 +  $$;
    1.46 +
    1.47 +CREATE OR REPLACE FUNCTION ecluster_create_multipoint(epoint[])
    1.48 +  RETURNS ecluster
    1.49 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.50 +    SELECT
    1.51 +      pg_catalog.array_to_string(
    1.52 +        pg_catalog.array_agg(
    1.53 +          'point (' OPERATOR(pg_catalog.||) unnest OPERATOR(pg_catalog.||) ')'
    1.54 +        ),
    1.55 +        ' '
    1.56 +      )::@extschema@.ecluster
    1.57 +    FROM pg_catalog.unnest($1)
    1.58 +  $$;
    1.59 +
    1.60 +CREATE OR REPLACE FUNCTION ecluster_create_path(epoint[])
    1.61 +  RETURNS ecluster
    1.62 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.63 +    SELECT CASE WHEN "str" OPERATOR(pg_catalog.=) '' THEN
    1.64 +      'empty'::@extschema@.ecluster
    1.65 +    ELSE
    1.66 +      (
    1.67 +        'path (' OPERATOR(pg_catalog.||) "str" OPERATOR(pg_catalog.||) ')'
    1.68 +      )::@extschema@.ecluster
    1.69 +    END
    1.70 +    FROM pg_catalog.array_to_string($1, ' ') AS "str"
    1.71 +  $$;
    1.72 +
    1.73 +CREATE OR REPLACE FUNCTION ecluster_create_outline(epoint[])
    1.74 +  RETURNS ecluster
    1.75 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.76 +    SELECT CASE WHEN "str" OPERATOR(pg_catalog.=) '' THEN
    1.77 +      'empty'::@extschema@.ecluster
    1.78 +    ELSE
    1.79 +      (
    1.80 +        'outline (' OPERATOR(pg_catalog.||) "str" OPERATOR(pg_catalog.||) ')'
    1.81 +      )::@extschema@.ecluster
    1.82 +    END
    1.83 +    FROM pg_catalog.array_to_string($1, ' ') AS "str"
    1.84 +  $$;
    1.85 +
    1.86 +CREATE OR REPLACE FUNCTION ecluster_create_polygon(epoint[])
    1.87 +  RETURNS ecluster
    1.88 +  LANGUAGE sql IMMUTABLE STRICT AS $$
    1.89 +    SELECT CASE WHEN "str" OPERATOR(pg_catalog.=) '' THEN
    1.90 +      'empty'::@extschema@.ecluster
    1.91 +    ELSE
    1.92 +      (
    1.93 +        'polygon (' OPERATOR(pg_catalog.||) pg_catalog.array_to_string($1, ' ')
    1.94 +        OPERATOR(pg_catalog.||) ')'
    1.95 +      )::@extschema@.ecluster
    1.96 +    END
    1.97 +    FROM pg_catalog.array_to_string($1, ' ') AS "str"
    1.98 +  $$;
    1.99 +
   1.100  
   1.101  ----------------------
   1.102  -- getter functions --
   1.103 @@ -350,6 +432,51 @@
   1.104    LANGUAGE C IMMUTABLE STRICT
   1.105    AS '$libdir/latlon-v0010', 'pgl_ecircle_radius';
   1.106  
   1.107 +CREATE OR REPLACE FUNCTION ecluster_extract_points(ecluster)
   1.108 +  RETURNS SETOF epoint
   1.109 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.110 +    SELECT "match"[2]::@extschema@.epoint
   1.111 +    FROM pg_catalog.regexp_matches(
   1.112 +      $1::pg_catalog.text, e'(^| )point \\(([^)]+)\\)', 'g'
   1.113 +    ) AS "match"
   1.114 +  $$;
   1.115 +
   1.116 +CREATE OR REPLACE FUNCTION ecluster_extract_paths(ecluster)
   1.117 +  RETURNS SETOF epoint[]
   1.118 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.119 +    SELECT (
   1.120 +      SELECT pg_catalog.array_agg("m2"[1]::@extschema@.epoint)
   1.121 +      FROM pg_catalog.regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   1.122 +    )
   1.123 +    FROM pg_catalog.regexp_matches(
   1.124 +      $1::pg_catalog.text, e'(^| )path \\(([^)]+)\\)', 'g'
   1.125 +    ) AS "m1"
   1.126 +  $$;
   1.127 +
   1.128 +CREATE OR REPLACE FUNCTION ecluster_extract_outlines(ecluster)
   1.129 +  RETURNS SETOF epoint[]
   1.130 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.131 +    SELECT (
   1.132 +      SELECT pg_catalog.array_agg("m2"[1]::@extschema@.epoint)
   1.133 +      FROM pg_catalog.regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   1.134 +    )
   1.135 +    FROM pg_catalog.regexp_matches(
   1.136 +      $1::pg_catalog.text, e'(^| )outline \\(([^)]+)\\)', 'g'
   1.137 +    ) AS "m1"
   1.138 +  $$;
   1.139 +
   1.140 +CREATE OR REPLACE FUNCTION ecluster_extract_polygons(ecluster)
   1.141 +  RETURNS SETOF epoint[]
   1.142 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.143 +    SELECT (
   1.144 +      SELECT pg_catalog.array_agg("m2"[1]::@extschema@.epoint)
   1.145 +      FROM pg_catalog.regexp_matches("m1"[2], e'[^ ]+ [^ ]+', 'g') AS "m2"
   1.146 +    )
   1.147 +    FROM pg_catalog.regexp_matches(
   1.148 +      $1::pg_catalog.text, e'(^| )polygon \\(([^)]+)\\)', 'g'
   1.149 +    ) AS "m1"
   1.150 +  $$;
   1.151 +
   1.152  
   1.153  ---------------
   1.154  -- operators --
   1.155 @@ -455,6 +582,145 @@
   1.156    LANGUAGE C IMMUTABLE STRICT
   1.157    AS '$libdir/latlon-v0010', 'pgl_ecluster_epoint_sc_fair_distance';
   1.158  
   1.159 +CREATE OR REPLACE FUNCTION epoint_ebox_overlap_commutator(ebox, epoint)
   1.160 +  RETURNS boolean
   1.161 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&) $1';
   1.162 +
   1.163 +CREATE OR REPLACE FUNCTION epoint_ecircle_overlap_commutator(ecircle, epoint)
   1.164 +  RETURNS boolean
   1.165 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&) $1';
   1.166 +
   1.167 +CREATE OR REPLACE FUNCTION epoint_ecluster_overlap_commutator(ecluster, epoint)
   1.168 +  RETURNS boolean
   1.169 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&) $1';
   1.170 +
   1.171 +CREATE OR REPLACE FUNCTION ecircle_ecluster_overlap_commutator(ecluster, ecircle)
   1.172 +  RETURNS boolean
   1.173 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&) $1';
   1.174 +
   1.175 +CREATE OR REPLACE FUNCTION ebox_ecircle_overlap_castwrap(ebox, ecircle)
   1.176 +  RETURNS boolean
   1.177 +  LANGUAGE sql IMMUTABLE
   1.178 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.&&) $2';
   1.179 +
   1.180 +CREATE OR REPLACE FUNCTION ebox_ecircle_overlap_castwrap(ecircle, ebox)
   1.181 +  RETURNS boolean
   1.182 +  LANGUAGE sql IMMUTABLE
   1.183 +  AS 'SELECT $1 OPERATOR(@extschema@.&&) $2::@extschema@.ecluster';
   1.184 +
   1.185 +CREATE OR REPLACE FUNCTION ebox_ecluster_overlap_castwrap(ebox, ecluster)
   1.186 +  RETURNS boolean
   1.187 +  LANGUAGE sql IMMUTABLE
   1.188 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.&&) $2';
   1.189 +
   1.190 +CREATE OR REPLACE FUNCTION ebox_ecluster_overlap_castwrap(ecluster, ebox)
   1.191 +  RETURNS boolean
   1.192 +  LANGUAGE sql IMMUTABLE
   1.193 +  AS 'SELECT $1 OPERATOR(@extschema@.&&) $2::@extschema@.ecluster';
   1.194 +
   1.195 +CREATE OR REPLACE FUNCTION epoint_ecluster_may_overlap_commutator(ecluster, epoint)
   1.196 +  RETURNS boolean
   1.197 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&+) $1';
   1.198 +
   1.199 +CREATE OR REPLACE FUNCTION ebox_ecircle_may_overlap_commutator(ecircle, ebox)
   1.200 +  RETURNS boolean
   1.201 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&+) $1';
   1.202 +
   1.203 +CREATE OR REPLACE FUNCTION ebox_ecluster_may_overlap_commutator(ecluster, ebox)
   1.204 +  RETURNS boolean
   1.205 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&+) $1';
   1.206 +
   1.207 +CREATE OR REPLACE FUNCTION ecircle_ecluster_may_overlap_commutator(ecluster, ecircle)
   1.208 +  RETURNS boolean
   1.209 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.&&+) $1';
   1.210 +
   1.211 +CREATE OR REPLACE FUNCTION ecluster_contains_commutator(ecluster, ecluster)
   1.212 +  RETURNS boolean
   1.213 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.@>) $1';
   1.214 +
   1.215 +CREATE OR REPLACE FUNCTION ebox_contains_castwrap(ebox, ebox)
   1.216 +  RETURNS boolean
   1.217 +  LANGUAGE sql IMMUTABLE AS $$
   1.218 +    SELECT
   1.219 +    $1::@extschema@.ecluster OPERATOR(@extschema@.@>) $2::@extschema@.ecluster
   1.220 +  $$;
   1.221 +
   1.222 +CREATE OR REPLACE FUNCTION ebox_contains_swapped_castwrap(ebox, ebox)
   1.223 +  RETURNS boolean
   1.224 +  LANGUAGE sql IMMUTABLE AS $$
   1.225 +    SELECT
   1.226 +    $2::@extschema@.ecluster OPERATOR(@extschema@.@>) $1::@extschema@.ecluster
   1.227 +  $$;
   1.228 +
   1.229 +CREATE OR REPLACE FUNCTION ebox_ecluster_contains_castwrap(ebox, ecluster)
   1.230 +  RETURNS boolean
   1.231 +  LANGUAGE sql IMMUTABLE
   1.232 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.@>) $2';
   1.233 +
   1.234 +CREATE OR REPLACE FUNCTION ebox_ecluster_contains_castwrap(ecluster, ebox)
   1.235 +  RETURNS boolean
   1.236 +  LANGUAGE sql IMMUTABLE
   1.237 +  AS 'SELECT $2::@extschema@.ecluster OPERATOR(@extschema@.@>) $1';
   1.238 +
   1.239 +CREATE OR REPLACE FUNCTION ecluster_ebox_contains_castwrap(ecluster, ebox)
   1.240 +  RETURNS boolean
   1.241 +  LANGUAGE sql IMMUTABLE
   1.242 +  AS 'SELECT $1 OPERATOR(@extschema@.@>) $2::@extschema@.ecluster';
   1.243 +
   1.244 +CREATE OR REPLACE FUNCTION ecluster_ebox_contains_castwrap(ebox, ecluster)
   1.245 +  RETURNS boolean
   1.246 +  LANGUAGE sql IMMUTABLE
   1.247 +  AS 'SELECT $2 OPERATOR(@extschema@.@>) $1::@extschema@.ecluster';
   1.248 +
   1.249 +CREATE OR REPLACE FUNCTION epoint_ecircle_distance_commutator(ecircle, epoint)
   1.250 +  RETURNS float8
   1.251 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.<->) $1';
   1.252 +
   1.253 +CREATE OR REPLACE FUNCTION epoint_ecluster_distance_commutator(ecluster, epoint)
   1.254 +  RETURNS float8
   1.255 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.<->) $1';
   1.256 +
   1.257 +CREATE OR REPLACE FUNCTION ecircle_ecluster_distance_commutator(ecluster, ecircle)
   1.258 +  RETURNS float8
   1.259 +  LANGUAGE sql IMMUTABLE AS 'SELECT $2 OPERATOR(@extschema@.<->) $1';
   1.260 +
   1.261 +CREATE OR REPLACE FUNCTION epoint_ebox_distance_castwrap(epoint, ebox)
   1.262 +  RETURNS float8
   1.263 +  LANGUAGE sql IMMUTABLE
   1.264 +  AS 'SELECT $1 OPERATOR(@extschema@.<->) $2::@extschema@.ecluster';
   1.265 +
   1.266 +CREATE OR REPLACE FUNCTION epoint_ebox_distance_castwrap(ebox, epoint)
   1.267 +  RETURNS float8
   1.268 +  LANGUAGE sql IMMUTABLE
   1.269 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.<->) $2';
   1.270 +
   1.271 +CREATE OR REPLACE FUNCTION ebox_distance_castwrap(ebox, ebox)
   1.272 +  RETURNS float8
   1.273 +  LANGUAGE sql IMMUTABLE AS $$
   1.274 +    SELECT
   1.275 +    $1::@extschema@.ecluster OPERATOR(@extschema@.<->) $2::@extschema@.ecluster
   1.276 +  $$;
   1.277 +
   1.278 +CREATE OR REPLACE FUNCTION ebox_ecircle_distance_castwrap(ebox, ecircle)
   1.279 +  RETURNS float8
   1.280 +  LANGUAGE sql IMMUTABLE
   1.281 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.<->) $2';
   1.282 +
   1.283 +CREATE OR REPLACE FUNCTION ebox_ecircle_distance_castwrap(ecircle, ebox)
   1.284 +  RETURNS float8
   1.285 +  LANGUAGE sql IMMUTABLE
   1.286 +  AS 'SELECT $1 OPERATOR(@extschema@.<->) $2::@extschema@.ecluster';
   1.287 +
   1.288 +CREATE OR REPLACE FUNCTION ebox_ecluster_distance_castwrap(ebox, ecluster)
   1.289 +  RETURNS float8
   1.290 +  LANGUAGE sql IMMUTABLE
   1.291 +  AS 'SELECT $1::@extschema@.ecluster OPERATOR(@extschema@.<->) $2';
   1.292 +
   1.293 +CREATE OR REPLACE FUNCTION ebox_ecluster_distance_castwrap(ecluster, ebox)
   1.294 +  RETURNS float8
   1.295 +  LANGUAGE sql IMMUTABLE
   1.296 +  AS 'SELECT $1 OPERATOR(@extschema@.<->) $2::@extschema@.ecluster';
   1.297 +
   1.298  
   1.299  ----------------
   1.300  -- GiST index --
   1.301 @@ -510,3 +776,225 @@
   1.302    LANGUAGE C STRICT
   1.303    AS '$libdir/latlon-v0010', 'pgl_gist_distance';
   1.304  
   1.305 +
   1.306 +---------------------
   1.307 +-- alias functions --
   1.308 +---------------------
   1.309 +
   1.310 +CREATE OR REPLACE FUNCTION distance(epoint, epoint)
   1.311 +  RETURNS float8
   1.312 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 OPERATOR(@extschema@.<->) $2';
   1.313 +
   1.314 +CREATE OR REPLACE FUNCTION distance(ecluster, epoint)
   1.315 +  RETURNS float8
   1.316 +  LANGUAGE sql IMMUTABLE AS 'SELECT $1 OPERATOR(@extschema@.<->) $2';
   1.317 +
   1.318 +CREATE OR REPLACE FUNCTION distance_within(epoint, epoint, float8)
   1.319 +  RETURNS boolean
   1.320 +  LANGUAGE sql IMMUTABLE
   1.321 +  AS 'SELECT $1 OPERATOR(@extschema@.&&) @extschema@.ecircle($2, $3)';
   1.322 +
   1.323 +CREATE OR REPLACE FUNCTION distance_within(ecluster, epoint, float8)
   1.324 +  RETURNS boolean
   1.325 +  LANGUAGE sql IMMUTABLE
   1.326 +  AS 'SELECT $1 OPERATOR(@extschema@.&&) @extschema@.ecircle($2, $3)';
   1.327 +
   1.328 +CREATE OR REPLACE FUNCTION fair_distance(ecluster, epoint, int4 = 10000)
   1.329 +  RETURNS float8
   1.330 +  LANGUAGE sql IMMUTABLE AS $$
   1.331 +    SELECT
   1.332 +    $1 OPERATOR(@extschema@.<=>) @extschema@.epoint_with_sample_count($2, $3)
   1.333 +  $$;
   1.334 +
   1.335 +
   1.336 +--------------------------------
   1.337 +-- other data storage formats --
   1.338 +--------------------------------
   1.339 +
   1.340 +CREATE OR REPLACE FUNCTION coords_to_epoint(float8, float8, text = 'epoint')
   1.341 +  RETURNS epoint
   1.342 +  LANGUAGE plpgsql IMMUTABLE STRICT AS $$
   1.343 +    DECLARE
   1.344 +      "result" @extschema@.epoint;
   1.345 +    BEGIN
   1.346 +      IF $3 OPERATOR(pg_catalog.=) 'epoint_lonlat' THEN
   1.347 +        -- avoid dynamic command execution for better performance
   1.348 +        RETURN @extschema@.epoint($2, $1);
   1.349 +      END IF;
   1.350 +      IF
   1.351 +        $3 OPERATOR(pg_catalog.=) 'epoint' OR
   1.352 +        $3 OPERATOR(pg_catalog.=) 'epoint_latlon'
   1.353 +      THEN
   1.354 +        -- avoid dynamic command execution for better performance
   1.355 +        RETURN @extschema@.epoint($1, $2);
   1.356 +      END IF;
   1.357 +      EXECUTE
   1.358 +        'SELECT ' OPERATOR(pg_catalog.||) $3 OPERATOR(pg_catalog.||) '($1, $2)'         INTO STRICT "result" USING $1, $2;
   1.359 +      RETURN "result";
   1.360 +    END;
   1.361 +  $$;
   1.362 +
   1.363 +CREATE OR REPLACE FUNCTION GeoJSON_LinearRing_vertices(jsonb, text = 'epoint_lonlat')
   1.364 +  RETURNS SETOF jsonb
   1.365 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.366 +    SELECT "result" FROM
   1.367 +      ( SELECT pg_catalog.jsonb_array_length($1) - 1 )
   1.368 +      AS "lastindex_row" ("lastindex")
   1.369 +      CROSS JOIN LATERAL pg_catalog.jsonb_array_elements(
   1.370 +        CASE WHEN
   1.371 +          @extschema@.coords_to_epoint(
   1.372 +            ($1 OPERATOR(pg_catalog.->) 0 OPERATOR(pg_catalog.->>) 0)
   1.373 +            ::pg_catalog.float8,
   1.374 +            ($1 OPERATOR(pg_catalog.->) 0 OPERATOR(pg_catalog.->>) 1)
   1.375 +            ::pg_catalog.float8,
   1.376 +            $2
   1.377 +          ) OPERATOR(pg_catalog.=) @extschema@.coords_to_epoint(
   1.378 +            ($1 OPERATOR(pg_catalog.->) "lastindex" OPERATOR(pg_catalog.->>) 0)
   1.379 +            ::pg_catalog.float8,
   1.380 +            ($1 OPERATOR(pg_catalog.->) "lastindex" OPERATOR(pg_catalog.->>) 1)
   1.381 +            ::pg_catalog.float8,
   1.382 +            $2
   1.383 +          )
   1.384 +        THEN
   1.385 +          $1 - "lastindex"
   1.386 +        ELSE
   1.387 +          $1
   1.388 +        END
   1.389 +      ) AS "result_row" ("result")
   1.390 +  $$;
   1.391 +
   1.392 +CREATE OR REPLACE FUNCTION GeoJSON_to_epoint(jsonb, text = 'epoint_lonlat')
   1.393 +  RETURNS epoint
   1.394 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.395 +    SELECT CASE
   1.396 +    WHEN $1 OPERATOR(pg_catalog.->>) 'type' OPERATOR(pg_catalog.=) 'Point' THEN
   1.397 +      @extschema@.coords_to_epoint(
   1.398 +        ($1 OPERATOR(pg_catalog.->) 'coordinates' OPERATOR(pg_catalog.->>) 0)
   1.399 +        ::pg_catalog.float8,
   1.400 +        ($1 OPERATOR(pg_catalog.->) 'coordinates' OPERATOR(pg_catalog.->>) 1)
   1.401 +        ::pg_catalog.float8,
   1.402 +        $2
   1.403 +      )
   1.404 +    WHEN $1->>'type' = 'Feature' THEN
   1.405 +      @extschema@.GeoJSON_to_epoint($1 OPERATOR(pg_catalog.->) 'geometry', $2)
   1.406 +    ELSE
   1.407 +      NULL
   1.408 +    END
   1.409 +  $$;
   1.410 +
   1.411 +CREATE OR REPLACE FUNCTION GeoJSON_to_ecluster(jsonb, text = 'epoint_lonlat')
   1.412 +  RETURNS ecluster
   1.413 +  LANGUAGE sql IMMUTABLE STRICT AS $$
   1.414 +    SELECT CASE $1 OPERATOR(pg_catalog.->>) 'type'
   1.415 +    WHEN 'Point' THEN
   1.416 +      @extschema@.coords_to_epoint(
   1.417 +        ($1 OPERATOR(pg_catalog.->) 'coordinates' OPERATOR(pg_catalog.->>) 0)
   1.418 +        ::pg_catalog.float8,
   1.419 +        ($1 OPERATOR(pg_catalog.->) 'coordinates' OPERATOR(pg_catalog.->>) 1)
   1.420 +        ::pg_catalog.float8,
   1.421 +        $2
   1.422 +      )::@extschema@.ecluster
   1.423 +    WHEN 'MultiPoint' THEN
   1.424 +      ( SELECT @extschema@.ecluster_create_multipoint(pg_catalog.array_agg(
   1.425 +          @extschema@.coords_to_epoint(
   1.426 +            ("coord" OPERATOR(pg_catalog.->>) 0)::pg_catalog.float8,
   1.427 +            ("coord" OPERATOR(pg_catalog.->>) 1)::pg_catalog.float8,
   1.428 +            $2
   1.429 +          )
   1.430 +        ))
   1.431 +        FROM pg_catalog.jsonb_array_elements(
   1.432 +          $1 OPERATOR(pg_catalog.->) 'coordinates'
   1.433 +        ) AS "coord"
   1.434 +      )
   1.435 +    WHEN 'LineString' THEN
   1.436 +      ( SELECT @extschema@.ecluster_create_path(pg_catalog.array_agg(
   1.437 +          @extschema@.coords_to_epoint(
   1.438 +            ("coord" OPERATOR(pg_catalog.->>) 0)::pg_catalog.float8,
   1.439 +            ("coord" OPERATOR(pg_catalog.->>) 1)::pg_catalog.float8,
   1.440 +            $2
   1.441 +          )
   1.442 +        ))
   1.443 +        FROM pg_catalog.jsonb_array_elements(
   1.444 +          $1 OPERATOR(pg_catalog.->) 'coordinates'
   1.445 +        ) AS "coord"
   1.446 +      )
   1.447 +    WHEN 'MultiLineString' THEN
   1.448 +      ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.449 +          ( SELECT @extschema@.ecluster_create_path(pg_catalog.array_agg(
   1.450 +              coords_to_epoint(
   1.451 +                ("coord" OPERATOR(pg_catalog.->>) 0)::pg_catalog.float8,
   1.452 +                ("coord" OPERATOR(pg_catalog.->>) 1)::pg_catalog.float8,
   1.453 +                $2
   1.454 +              )
   1.455 +            ))
   1.456 +            FROM pg_catalog.jsonb_array_elements("coord_array") AS "coord"
   1.457 +          )
   1.458 +        ))
   1.459 +        FROM pg_catalog.jsonb_array_elements(
   1.460 +          $1 OPERATOR(pg_catalog.->) 'coordinates'
   1.461 +        ) AS "coord_array"
   1.462 +      )
   1.463 +    WHEN 'Polygon' THEN
   1.464 +      ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.465 +          ( SELECT @extschema@.ecluster_create_polygon(pg_catalog.array_agg(
   1.466 +              @extschema@.coords_to_epoint(
   1.467 +                ("coord" OPERATOR(pg_catalog.->>) 0)::pg_catalog.float8,
   1.468 +                ("coord" OPERATOR(pg_catalog.->>) 1)::pg_catalog.float8,
   1.469 +                $2
   1.470 +              )
   1.471 +            ))
   1.472 +            FROM @extschema@.GeoJSON_LinearRing_vertices("coord_array", $2)
   1.473 +            AS "coord"
   1.474 +          )
   1.475 +        ))
   1.476 +        FROM pg_catalog.jsonb_array_elements(
   1.477 +          $1 OPERATOR(pg_catalog.->) 'coordinates'
   1.478 +        ) AS "coord_array"
   1.479 +      )
   1.480 +    WHEN 'MultiPolygon' THEN
   1.481 +      ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.482 +          ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.483 +              ( SELECT pg_catalog.ecluster_create_polygon(pg_catalog.array_agg(
   1.484 +                  @extschema@.coords_to_epoint(
   1.485 +                    ("coord" OPERATOR(pg_catalog.->>) 0)::pg_catalog.float8,
   1.486 +                    ("coord" OPERATOR(pg_catalog.->>) 1)::pg_catalog.float8,
   1.487 +                    $2
   1.488 +                  )
   1.489 +                ))
   1.490 +                FROM @extschema@.GeoJSON_LinearRing_vertices("coord_array", $2)
   1.491 +                AS "coord"
   1.492 +              )
   1.493 +            ))
   1.494 +            FROM pg_catalog.jsonb_array_elements("coord_array_array")
   1.495 +            AS "coord_array"
   1.496 +          )
   1.497 +        ))
   1.498 +        FROM jsonb_array_elements(
   1.499 +          $1 OPERATOR(pg_catalog.->) 'coordinates'
   1.500 +        ) AS "coord_array_array"
   1.501 +      )
   1.502 +    WHEN 'GeometryCollection' THEN
   1.503 +      ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.504 +          @extschema@.GeoJSON_to_ecluster("geometry", $2)
   1.505 +        ))
   1.506 +        FROM pg_catalog.jsonb_array_elements(
   1.507 +          $1 OPERATOR(pg_catalog.->) 'geometries'
   1.508 +        ) AS "geometry"
   1.509 +      )
   1.510 +    WHEN 'Feature' THEN
   1.511 +      @extschema@.GeoJSON_to_ecluster(
   1.512 +        $1 OPERATOR(pg_catalog.->) 'geometry', $2
   1.513 +      )
   1.514 +    WHEN 'FeatureCollection' THEN
   1.515 +      ( SELECT @extschema@.ecluster_concat(pg_catalog.array_agg(
   1.516 +          @extschema@.GeoJSON_to_ecluster("feature", $2)
   1.517 +        ))
   1.518 +        FROM pg_catalog.jsonb_array_elements(
   1.519 +          $1 OPERATOR(pg_catalog.->) 'features'
   1.520 +        ) AS "feature"
   1.521 +      )
   1.522 +    ELSE
   1.523 +      NULL
   1.524 +    END
   1.525 +  $$;
   1.526 +

Impressum / About Us