From 098e73479b466902cf48a07627f050dadd2fd73e Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Fri, 4 Oct 2019 13:40:27 +0100 Subject: [PATCH] Remove shared lib PG functions from committed DB structure. --- db/structure.sql | 67 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 47f3cf7a0..908b97c1f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5,6 +5,7 @@ SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; +SET xmloption = content; SET client_min_messages = warning; SET row_security = off; @@ -132,27 +133,57 @@ CREATE TYPE public.user_status_enum AS ENUM ( -- Name: maptile_for_point(bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: - -- -CREATE FUNCTION public.maptile_for_point(bigint, bigint, integer) RETURNS integer - LANGUAGE c STRICT - AS '$libdir/libpgosm.so', 'maptile_for_point'; +CREATE FUNCTION public.maptile_for_point(scaled_lat bigint, scaled_lon bigint, zoom integer) RETURNS integer + LANGUAGE plpgsql IMMUTABLE + AS $$ +DECLARE + lat CONSTANT DOUBLE PRECISION := scaled_lat / 10000000.0; + lon CONSTANT DOUBLE PRECISION := scaled_lon / 10000000.0; + zscale CONSTANT DOUBLE PRECISION := 2.0 ^ zoom; + pi CONSTANT DOUBLE PRECISION := 3.141592653589793; + r_per_d CONSTANT DOUBLE PRECISION := pi / 180.0; + x int4; + y int4; +BEGIN + -- straight port of the C code. see db/functions/maptile.c + x := floor((lon + 180.0) * zscale / 360.0); + y := floor((1.0 - ln(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / pi) * zscale / 2.0); + + RETURN (x << zoom) | y; +END; +$$; -- -- Name: tile_for_point(integer, integer); Type: FUNCTION; Schema: public; Owner: - -- -CREATE FUNCTION public.tile_for_point(integer, integer) RETURNS bigint - LANGUAGE c STRICT - AS '$libdir/libpgosm.so', 'tile_for_point'; +CREATE FUNCTION public.tile_for_point(scaled_lat integer, scaled_lon integer) RETURNS bigint + LANGUAGE plpgsql IMMUTABLE + AS $$ +DECLARE + x int8; -- quantized x from lon, + y int8; -- quantized y from lat, +BEGIN + x := round(((scaled_lon / 10000000.0) + 180.0) * 65535.0 / 360.0); + y := round(((scaled_lat / 10000000.0) + 90.0) * 65535.0 / 180.0); + -- these bit-masks are special numbers used in the bit interleaving algorithm. + -- see https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN + -- for the original algorithm and more details. + x := (x | (x << 8)) & 16711935; -- 0x00FF00FF + x := (x | (x << 4)) & 252645135; -- 0x0F0F0F0F + x := (x | (x << 2)) & 858993459; -- 0x33333333 + x := (x | (x << 1)) & 1431655765; -- 0x55555555 --- --- Name: xid_to_int4(xid); Type: FUNCTION; Schema: public; Owner: - --- + y := (y | (y << 8)) & 16711935; -- 0x00FF00FF + y := (y | (y << 4)) & 252645135; -- 0x0F0F0F0F + y := (y | (y << 2)) & 858993459; -- 0x33333333 + y := (y | (y << 1)) & 1431655765; -- 0x55555555 -CREATE FUNCTION public.xid_to_int4(xid) RETURNS integer - LANGUAGE c IMMUTABLE STRICT - AS '$libdir/libpgosm.so', 'xid_to_int4'; + RETURN (x << 1) | y; +END; +$$; SET default_tablespace = ''; @@ -291,6 +322,7 @@ CREATE TABLE public.changeset_comments ( -- CREATE SEQUENCE public.changeset_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -392,6 +424,7 @@ CREATE TABLE public.client_applications ( -- CREATE SEQUENCE public.client_applications_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -816,6 +849,7 @@ CREATE TABLE public.issue_comments ( -- CREATE SEQUENCE public.issue_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -855,6 +889,7 @@ CREATE TABLE public.issues ( -- CREATE SEQUENCE public.issues_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -967,6 +1002,7 @@ CREATE TABLE public.note_comments ( -- CREATE SEQUENCE public.note_comments_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1002,6 +1038,7 @@ CREATE TABLE public.notes ( -- CREATE SEQUENCE public.notes_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1034,6 +1071,7 @@ CREATE TABLE public.oauth_nonces ( -- CREATE SEQUENCE public.oauth_nonces_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1082,6 +1120,7 @@ CREATE TABLE public.oauth_tokens ( -- CREATE SEQUENCE public.oauth_tokens_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1116,6 +1155,7 @@ CREATE TABLE public.redactions ( -- CREATE SEQUENCE public.redactions_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1190,6 +1230,7 @@ CREATE TABLE public.reports ( -- CREATE SEQUENCE public.reports_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1236,6 +1277,7 @@ CREATE TABLE public.user_blocks ( -- CREATE SEQUENCE public.user_blocks_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1280,6 +1322,7 @@ CREATE TABLE public.user_roles ( -- CREATE SEQUENCE public.user_roles_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE -- 2.43.2