Compare commits

...

1 Commits

Author SHA1 Message Date
Raul Ochoa
8e0ffcb98d accept (text) and (text, text) inputs (#54) 2014-08-25 16:32:55 +02:00

View File

@ -21,3 +21,36 @@ BEGIN
END;
$$ language plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION CDB_DecimalDegreeLiteral(deg TEXT) RETURNS numeric as $$
BEGIN
-- Check if comma decimal place
-- e.g. '141,00' = 141.00
IF array_length(string_to_array(deg, ','), 1) > 1 THEN
RETURN replace(deg, ',', '.')::numeric;
-- Just try the good old convert to numeric
ELSE
RETURN deg::numeric;
END IF;
END;
$$ language plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION CDB_LatLng(lat TEXT, lng TEXT) RETURNS geometry as $$
BEGIN
-- TODO: Check if other text type. E.g. DDMMSS
RETURN CDB_LatLng(
CDB_DecimalDegreeLiteral(lat),
CDB_DecimalDegreeLiteral(lng)
);
END;
$$ language plpgsql IMMUTABLE;
CREATE OR REPLACE FUNCTION CDB_LatLng(coords TEXT) RETURNS geometry as $$
DECLARE
BEGIN
-- TODO: Check if other spaces. E.g. DD MM SS
RETURN CDB_LatLng(
CDB_DecimalDegreeLiteral(split_part(coords, ' ', 1)),
CDB_DecimalDegreeLiteral(split_part(coords, ' ', 2))
);
END;
$$ language plpgsql IMMUTABLE;