Compare commits
1 Commits
master
...
cdb_latlng
Author | SHA1 | Date | |
---|---|---|---|
|
8e0ffcb98d |
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user