SpatialDB Advisor
Yesterday, I posted a short article on Converting Google Earth Formatted Longitude/Latitude points to decimal degrees. The Google Earth longitude/latitude values are expressed as a string containing degree, minute and seconds values with text separators as follows:
| Latitude | Longitude |
|---|---|
| 43° 0’50.60“S | 147°12’18.20“E |
The function described was written in PL/SQL for Oracle.
Regina Obe emailed me today as she had read the article and had converted it to PostGIS (supplying me a copy).
You will notice, in the code that follows, that PL/SQL and PL/PgSQL are very similar, making conversion much easier than you might expect.
CREATE OR REPLACE FUNCTION DMS2DD(strDegMinSec varchar)
RETURNS numeric
AS
$$
DECLARE
i numeric;
intDmsLen numeric; -- Length of original string
strCompassPoint Char(1);
strNorm varchar(16) = ''; -- Will contain normalized string
strDegMinSecB varchar(100);
blnGotSeparator integer; -- Keeps track of separator sequences
arrDegMinSec varchar[]; -- TYPE stringarray is table of varchar(2048) ;
dDeg numeric := 0;
dMin numeric := 0;
dSec numeric := 0;
strChr Char(1);
BEGIN
-- Remove leading and trailing spaces
strDegMinSecB := REPLACE(strDegMinSec,' ','');
-- assume no leading and trailing spaces?
intDmsLen := Length(strDegMinSecB);
SELECT round(dms2dd('43° 0''50.60"S'),9) as latitude,
round(dms2dd('147°12''18.20"E'),9) as longitude;
| latitude | longitude |
|---|---|
| -43.014055556 | 147.205055556 |
Thanks Regina.


















<<Implementing Oracle's GetVertices function in PostGIS - ST_DumpPoints >>Loading Point Data from a CSV File in PostGIS