diff --git a/scripts-available/CDB_LatLng.sql b/scripts-available/CDB_LatLng.sql index d1304c3..7f08f61 100644 --- a/scripts-available/CDB_LatLng.sql +++ b/scripts-available/CDB_LatLng.sql @@ -8,16 +8,12 @@ -- CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$ -BEGIN -- this function is silly - RETURN ST_SetSRID(ST_MakePoint(lng,lat),4326); -END; -$$ language plpgsql IMMUTABLE; + SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326); +$$ language SQL IMMUTABLE; CREATE OR REPLACE FUNCTION CDB_LatLng (lat FLOAT8, lng FLOAT8) RETURNS geometry as $$ -BEGIN -- this function is silly - RETURN ST_SetSRID(ST_MakePoint(lng,lat),4326); -END; -$$ language plpgsql IMMUTABLE; + SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326); +$$ language SQL IMMUTABLE; diff --git a/scripts-available/CDB_XYZ.sql b/scripts-available/CDB_XYZ.sql index 92e7dae..fa38171 100644 --- a/scripts-available/CDB_XYZ.sql +++ b/scripts-available/CDB_XYZ.sql @@ -5,24 +5,9 @@ CREATE OR REPLACE FUNCTION CDB_XYZ_Resolution(z INTEGER) RETURNS FLOAT8 AS $$ -DECLARE - earth_circumference FLOAT8; - tile_size INTEGER; - full_resolution FLOAT8; -BEGIN - - -- Earth equatorial circumference in meters (according to wikipedia) - earth_circumference := 40075017; - - -- Size of each tile in pixels (1:1 aspect ratio) - tile_size := 256; - - full_resolution := earth_circumference/tile_size; - - RETURN full_resolution / (power(2,z)); - -END -$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; + -- circumference divided by 256 is z0 resolution, then divide by 2^z + SELECT 40075017 / 256 / power(2, z); +$$ LANGUAGE SQL IMMUTABLE STRICT; -- } -- {