Convert some simple functions from plpgsql to sql
SQL is a faster language to call, and these are very simple functions.
This commit is contained in:
parent
a9f6e26fed
commit
ea7c16fbaf
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
-- }
|
||||
|
||||
-- {
|
||||
|
Loading…
Reference in New Issue
Block a user